Subversion Repositories vnag

Compare Revisions

No changes between revisions

Regard whitespace Rev 1 → Rev 2

/trunk/plugins/file_timestamp/FileTimestampCheck.class.php
0,0 → 1,136
<?php /* <ViaThinkSoftSignature>zGZPz4tVkmDMjrF+v+xuP5dMnqRI4kbdU8ojps0jpGMRwVFzfd6cmeRy1+67gqLA94NEGq7tz9T+gVN8HmmxkW4BiD6dWzrcLrZwtiiVx/C8LS7SB71SKfpVaISx0v2RjHek77YzcQQaC6v1D/p1iPFjNJe1W/XITfCdGQjUxODY84f5iyMRFgeCl4/TK1xqeaCaiBvMbyr/ypo+Zq90TtXDQdYezgF8xQv/yDgP/qYGKTDq7ya3wUjGmCR+DViT6DFQ6doi/kAGWTsa9KflYYcuYY9L/MJnDsSXZqFjc30BBqxsAjZaQZcQnZHYLmlmyEIBtYZn/UOG9Z67E6/tq1OBW8styEyw59z4DFNB+uIqLtx5Ip/JLoNcEfG4jxQVISZ1QCxzYHQ+LaaTk3yDM5hIQ4Cm5z+L6w9YfQ+JGho0CUGDgo0QL+0f4fKW+YETrcEzwYOVqX7Ry6DujKgTWIVKkU1yT/7bg3KdPAJKHaHuBWqqHIMCuTE+muhJd/t6jyOXcuayGKlI3jey33fdrW7CaVpMsUDeFmM7QRMPrvWv+HiY0fu406F6dlQxPSqmMZHTxZ4UH1LkREzFBEyJet7vlazVrLKBmWk83l37lwWrlL5Ehw0RtZGanLLLxNqyDfh6iGjRI9yJDOI+68oMoeF5rnchLJYJ2bMJ2lqJ+0cGy9foFdbCPqd+iPDK/KwmNHXwkZQvuDeKLuJycCKUt2x2CMoIX6GkF4jHAC860AZ2f0A9n6OFXPHfDgZAwWhdKYK8M6ob0QVSTICsBiFAMKkQM8t/BM2FnUPgB1a/m9wPaao/4Xx7TFwvvAqZaJe4iQNhwDvji92V/uRELz831J5lNi84PmY8WAqQLzWf8Uo5L2noZ/+EQiv6xydKig0hGq0WOaxSalbd6E9JYqKXRny2gAhEEIjWzhKyd4yUa4z3WOWe2r8wGTF06y6nbtTaOvVtUKWSC/0ZS9v6fxdmv37TLxZczJ1XNQpRpCPkOngz11ZYuBV0jR23VZfW//CKyV89YVufp/w6lQ74V1RCjIYb8tcIS8L8QTQB1JCqFFyUMhgOmFEYHZSF0BZYicXO78i7wK3wbZqjo0WMmySw6Yy1v1yYPB2xCFiXRCLSsiQTAPwxAghOWMdCWhx5qXTPmNbvZXOuyKQCbFPxJzjYpmPGIfI2Zhiu5Fdmx58NjcJBHNFQJ9Km0FpVb1TOpPdTaWvi6Ms6ecivzOPV9WzFtSkA5R0Hr5pBcRgGRMVkJqSEyeebJfWKhBcjNSHmTcuwCE3s/WcOAhZRzq9dnYY6cTBcMfodXMOiICU5nq9Zt5NsLFSNI+5q8bghPmfy5mQ7cobhNge1lJme6hUXV4CRTw==</ViaThinkSoftSignature> */ ?>
<?php
 
/*
* VNag - Nagios Framework for PHP
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
* Licensed under the terms of the Apache 2.0 license
*
* Revision 2018-07-15
*/
 
// TODO: New parameter: alternatively check for the creation timestamp instead of the modification timestamp.
// TODO: vnag soll der timestamp monitor auch warnen, wenn gewisse dateien nicht gefunden werden? im moment macht er nur einen glob() und ignoriert damit leere ergebnisse
 
declare(ticks=1);
 
class FileTimestampCheck extends VNag {
protected $argFiles = null;
 
public function __construct() {
parent::__construct();
 
$this->registerExpectedStandardArguments('Vhtwcv');
 
$this->getHelpManager()->setPluginName('check_file_timestamp');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks if local files are within a specific timestamp.');
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-v] -w <warnSeconds>s -c <critSeconds>s -f "[#]<mask>" [-f "[#]<mask>" [...]]');
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
 
// Individual (non-standard) arguments:
$this->addExpectedArgument($this->argFiles = new VNagArgument('f', 'file', VNagArgument::VALUE_REQUIRED, 'mask', 'The files to be checked. This argument can be used multiple times. Wilcards may be used but MUST be passed as string only (not resolved by the Shell). There are two possible checking modes: If you put a # in front of the file mask, only the youngest file of each group will be checked (use this mode e.g. if you want to check if a downloader is regularly downloading files into a download directory). Otherwise, all files of the file group are checked.'));
 
// In this context, when the user writes "-w 60s" then he actually means "-w @60s:~" or "-w 0s:60s", so these commands allow this notation:
$this->warningSingleValueRangeBehaviors[0] = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
$this->criticalSingleValueRangeBehaviors[0] = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
}
 
private static function humanFriendlyInterval($secs) {
$out = array();
 
$years = floor($secs / 60 / 60 / 24 / 365);
if ($years > 0) $out[] = $years == 1 ? "$years year" : "$years years";
 
$days = floor($secs / 60 / 60 / 24) % 365;
if ($days > 0) $out[] = $days == 1 ? "$days day" : "$days days";
 
$hours = floor($secs / 60 / 60) % 24;
if ($hours > 0) $out[] = $hours == 1 ? "$hours hour" : "$hours hours";
 
$minutes = floor($secs / 60) % 60;
if ($minutes > 0) $out[] = $minutes == 1 ? "$minutes minute" : "$minutes minutes";
 
$seconds = $secs % 60;
if ($seconds > 0) $out[] = $seconds == 1 ? "$seconds second" : "$seconds seconds";
 
return implode(", ", $out);
}
 
protected function cbRun($optional_args=array()) {
$this->argFiles->require();
 
$countFilesTotal = 0;
$countFilesCrit = 0;
$countFilesWarn = 0;
 
$fileGroupMasks = $this->argFiles->getValue();
if (!is_array($fileGroupMasks)) $fileGroupMasks = array($fileGroupMasks);
foreach ($fileGroupMasks as $fileGroupMask) {
if (substr($fileGroupMask, 0, 1) === '#') {
$fileGroupMask = substr($fileGroupMask, 1); // remove #
 
// Mode 1: Only the youngest file of each group is checked.
// You can use this mode e.g. if you have a folder with downloaded files
// and you want to check if a downloading-script is still downloading
// new files regularly.
 
$files = glob($fileGroupMask);
if (count($files) == 0) continue;
 
$youngestTS = null;
foreach ($files as $file) {
$youngestTS = is_null($youngestTS) ? filemtime($file) : max($youngestTS, filemtime($file));
}
 
$youngestAge = time() - $youngestTS;
$countFilesTotal++;
if ($this->checkAgainstCriticalRange($youngestAge.'s', false, true)) {
$countFilesCrit++;
$this->addVerboseMessage("File group '$fileGroupMask': Youngest file's age: ".self::humanFriendlyInterval($youngestAge)." (Critical)\n", VNag::VERBOSITY_SUMMARY);
} else if ($this->checkAgainstWarningRange($youngestAge.'s', false, true)) {
$countFilesWarn++;
$this->addVerboseMessage("File group '$fileGroupMask': Youngest file's age: ".self::humanFriendlyInterval($youngestAge)." (Warning)\n", VNag::VERBOSITY_SUMMARY);
} else {
if (($this->getArgumentHandler()->getArgumentObj('w')->available()) || ($this->getArgumentHandler()->getArgumentObj('c')->available())) {
$this->addVerboseMessage("File group '$fileGroupMask': Youngest file's age: ".self::humanFriendlyInterval($youngestAge)." (OK)\n", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
} else {
$this->addVerboseMessage("File group '$fileGroupMask': Youngest file's age: ".self::humanFriendlyInterval($youngestAge)."\n", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
}
}
} else {
// Mode 2: All files of each group are checked.
 
$files = glob($fileGroupMask);
if (count($files) == 0) continue;
 
foreach ($files as $file) {
$age = time() - filemtime($file);
$countFilesTotal++;
if ($this->checkAgainstCriticalRange($age.'s', false, true)) {
$countFilesCrit++;
$this->addVerboseMessage("File $file age ".self::humanFriendlyInterval($age)." (Critical)\n", VNag::VERBOSITY_SUMMARY);
} else if ($this->checkAgainstWarningRange($age.'s', false, true)) {
$countFilesWarn++;
$this->addVerboseMessage("File $file age ".self::humanFriendlyInterval($age)." (Warning)\n", VNag::VERBOSITY_SUMMARY);
} else {
if (($this->getArgumentHandler()->getArgumentObj('w')->available()) || ($this->getArgumentHandler()->getArgumentObj('c')->available())) {
$this->addVerboseMessage("File $file age ".self::humanFriendlyInterval($age)." (OK)\n", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
} else {
$this->addVerboseMessage("File $file age ".self::humanFriendlyInterval($age)."\n", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
}
}
}
}
}
 
$msg = array();
$msg[] = "Checked $countFilesTotal files";
if ($this->getArgumentHandler()->getArgumentObj('w')->available()) $msg[] = "$countFilesWarn are in warning time range";
if ($this->getArgumentHandler()->getArgumentObj('c')->available()) $msg[] = "$countFilesCrit are in critical time range";
$msg = implode(", ", $msg);
 
$this->setHeadLine($msg);
}
}
/trunk/plugins/file_timestamp/check_file_timestamp
0,0 → 1,20
#!/usr/bin/php
<?php /* <ViaThinkSoftSignature>JECmzbK89A3spE9vWc+t83TbtGIVkkOPxRZGky06jmfgaJWI1OHNTowDly/6e3hXqOXPC8GhdvgkGNOm4DiqDR94Q8bSZnnnjYJ8M0wU+RqOgGOZcxtHyxYh1cMt4+Nfqiq0uh12HT7DeC133UA53/bZ9qr2zeMg7FhJV7AB7zSNlxyt3IcwS82soT0sZNVCia48Jltyqrb4LthTOJJ+DFDtSfuVNZhi4zbY7Hu7rzw6nCSLx63ZJO0EytvtLysPDHU1NDC5VQGnehZeDH//Pp/n27bcU3bk5Y9rB/lsr/cy3Ee36JoztWcHO6pdU8BtB7Ym1aXlFO2KhXG4E0vaWauAdoujDbL2gCRxDpsJsQxCEpM86mbaYbo3Fm69aJhxX/G5dVNIkXfEqfRGF99bfiPjlSNwVPJAhViYnMgZcix/BoaKlqB5OTONoD0jrhySYI5WxBDapczNp4cZv6ZpXBTTzyVxGaGbNmpCICjLfzU5em9k5VK3Dn18lo14ctOMZVdcHhNOdtqxTskIURO3X1NePMCoOTI/oofXAxAaAEWMcATK6JbqKNpP4TDY0/QAigTVClowK9+EMJHvY1oVAbOV/3etCcY91tHLJJfQfpx2M7xGrgz4Shcf3Xp/NmdxV30yz37tUVtmRtte/D9cx9M6tmS4fptWHD+L53PKYT1ul7nBcHlcX9csxOKstECV95BjJ/0qJTKmVt71TRD9VsSsQQtvEHTydabemcTYE5oYnhKpaPEQdTLnMM3yk0H+qwRB1yheZCWGt85pqxPmGkZwxBta1j6uZTec/nvWbBxJRkzZ5Oyou9IM80eNaGGD96FsOhv6i09bxxpRN0bTa5IrZK4szxnpPgW5bmQOalGom32R1KKKriuYK4brEy1jMpUZAlmN9LrphCfJZFXuVbBdWe7cWZ0F+blbrlLbTMR1LxpF1r8hlKIqhuf1OMysbkcqEA303cMdlTaUSokJw2J/bgoa22GLRW5aSpUjqjm0L6MQqu58TZT4NhB5VRXo0ORZsswI38/U8HhojJ9tSq+x39ctn0uMwI5PBXOvXbkohI2BGkwo5YqLNTOV6I2uY1cEhMlIu1zg1OcribTlCPIhd9xT91EX45AOVlOYEy36k2P3AfrOcAjiFMDfcgVQlzxjHYv1IWUfe7FZUoq5SNVMdEWVqgwqHqVaZ15KgRNlgM7pQ4uDb6Uf3RkJMLZOgi8I4uLi5pG7zAyiPC+7wSFSgEvkH36/hBHWTnCp2zjdH7gOkPD2I6ICNt02XQ72xG5+J45c5vI2VY3WCLK7VeHjdoBvGDgzVCWU3jCmUFUzt8wiupkeCkpQzh23dCFLrQkLCGMbfv96tqIC8a+jBg==</ViaThinkSoftSignature> */ ?>
<?php
 
/*
* VNag - Nagios Framework for PHP
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
* Licensed under the terms of the Apache 2.0 license
*
* Revision 2018-07-15
*/
 
declare(ticks=1);
 
require_once __DIR__ . '/../../framework/vnag_framework.inc.php';
require_once __DIR__ . '/FileTimestampCheck.class.php';
 
$job = new FileTimestampCheck();
$job->run();
unset($job);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/trunk/plugins/file_timestamp/icinga2.conf
0,0 → 1,71
// Put this file in /etc/icinga2/conf.d/...
 
// VNag - Nagios Framework for PHP
// Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
// Licensed under the terms of the Apache 2.0 license
//
// Revision 2018-07-15
 
object CheckCommand "vnag_file_timestamp" {
command = [ "/daten/vnag/plugins/file_timestamp/check_file_timestamp" ]
 
arguments = {
"-f" = {
value = "$vnag_file_timestamp_file$"
description = "File or filemask to be checked. There are two possible checking modes: If you put a # in front of the file mask, only the youngest file of each group will be checked (use this mode e.g. if you want to check if a downloader is regularly downloading files into a download directory). Otherwise, all files of the file group are checked."
repeat_key = true
required = true
}
"-w" = {
value = "$vnag_file_timestamp_warn$"
description = "Max age of file (warning range). You must use a Nagios compatible unit of measure (i.e. seconds)."
}
"-c" = {
value = "$vnag_file_timestamp_crit$"
description = "Max age of file (critical range). You must use a Nagios compatible unit of measure (i.e. seconds)."
}
"-v" = {
set_if = "$vnag_file_timestamp_verbose$"
description = "Additionally list files which are OK, not just the files which are out of the time range."
}
}
}
 
// Example usage:
//
// apply Service "example_daily_backup_timestamp" {
// import "generic-service"
// check_command = "vnag_file_timestamp"
// vars = {
// vnag_file_timestamp_file = [ "/backup/automatic/timestamps/ts_daily_rsync", "/backup/automatic/timestamps/ts_daily_mysqldump" ]
// vnag_file_timestamp_warn = "86400s" // 24h
// vnag_file_timestamp_crit = "144000s" // 40h
// vnag_file_timestamp_verbose = false
// }
// assign where host.name == NodeName
// }
//
// apply Service "example_3month_backup_timestamp" {
// import "generic-service"
// check_command = "vnag_file_timestamp"
// vars = {
// vnag_file_timestamp_file = [ "/backup/automatic/timestamps/ts_raspberry_rsync" ]
// vnag_file_timestamp_warn = "7776000s" // 3 Months
// vnag_file_timestamp_crit = "15552000s" // 6 Months
// vnag_file_timestamp_verbose = false
// }
// assign where host.name == NodeName
// }
//
// apply Service "example_downloader_timestamp" {
// import "generic-service"
// check_command = "vnag_file_timestamp"
// // the prepending hashtag means 'check only the youngest file'
// vars = {
// vnag_file_timestamp_file = [ "#/home/test/my_downloader/downloaded_files/*.jpg" ]
// vnag_file_timestamp_warn = "86400s" // 24h
// vnag_file_timestamp_crit = "144000s" // 40h
// vnag_file_timestamp_verbose = false
// }
// assign where host.name == NodeName
// }