Subversion Repositories vnag

Compare Revisions

No changes between revisions

Regard whitespace Rev 1 → Rev 2

/trunk/plugins/disk_running/DiskRunningCheck.class.php
0,0 → 1,85
<?php /* <ViaThinkSoftSignature>F9z2AfT7nAZ8u/BI8TAx/BdR2s+t778tdYJG4+lJV7Oqve9Zovt7XxsagYPLn4q3acTV8dGL2yaMvIWdPqwpWhu9ssXL9NN81pvIItF5t7GR9NWGS71nHMrr9pjQoIn+R6exKklwpuSMMQgFYKiCh5tUKnaMtEgQm/uQYTRei2UhOeV1s59MJ5/b6TOOcy/NNkO/lYQuflZ+mk5L3VcBtdi6F8sLhoiw4gy+oDDyNpGNSNjiB0mi3CMuQDXpnuAOSv9JluhQMRhQlTfKKaiF+4J7EGKuW3D8lt5FKuF+rGca1Iixtbi4bemQ9RqY3pbgKPg/iNdpxY+j24FcRJ7P6QvHBcY+lb1YL0ss9LqxMOV6DeNg+UOu5Aa1AerA8vfIQ4k7iK8Wt1e+9FXsmGmm84SgJ0gukRNRSzCreb+9glJ52V/PMNZcAiH7Qe7O/bzSeaqHlGIsgghkwt+XEBfyAiemuwBRN5GzyJsMOK7VH1Z+YGcj+V9I3SKkfZVABP6zyq/GwN4EOA2sQ9OCo3PVOcreVsIR+mYTUPfWBB+pd/M9Pu73LnA2WweoeKk/owrrb//uDEfBpCa5TIiDahng2xKaBBZTBJ++mO1kSzBP8X+n5KQToQQCmTzSJvZBXB6h4dqOVm6DikflV62JzOPP2839u48PMIo/6NFheEJnSHLR88f1X0B1lDmAgyc41m1sVk55hiTV5QQ9OJthifgehh9p0kakzY5H1PmltTrwlzBbFFE7BypH1rwyzRCwlXMKlFl74DWAY69ZRs6UaOXC0gbuKJT+blD4dfuEuUut/fQyFYwsFsyPgPzhjAsqnVgHT5IbkBrw2tVZ9NZgraYZjZyW+OFBFMk6fhvuxKzPxJXCHT2JAZ6hTwUPoPfq1GogrDMMmLQ0rorUgVMGuCN/lYtB57ak7QiE6Eczyob8qM60r+m738RysL5Jxg6IPGoT1rtekQKqAFGXUT50jOeTCu6aOSFwLCbisGf+ospZ1POtgFofTPygQJgO2uEkfPDjgkd04oP/p4S9UgIpUDQwlxZkz+MV2ErOSegvpcirTwt7OT2nJNN/FZUE3SOpP6tsRbYH+61kEhmbRK70ebeX6kwF8C6LB+eBvxMgups32MsFQOMucsqmyxV/uz5SM2BLn1giTn13fjJZMhnmz5fqHequgbiJ7vIUjUOpE/ccB6EuRFtirMNlZrVq3J26VEy9s3T9Rd/nV1k+cWLda+lBoLszPI7pRHOIda37RGTbWNPhvxDkG5sIVERQH8/rgTmBK1V/1tabXwDSn6FvzddVKPyXgcXsGefz6TcUMB0c0JMhnRY+/+m/MCQ1mAppVbAQUX+Ha9CJR1xw0e5P+hePww==</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-11-04
*/
 
declare(ticks=1);
 
class DiskRunningCheck extends VNag {
// Currently, we do not accept wildcards ('sd*' and 'hd*') because this plugin should monitor if disks become offline, e.g. horribly fail or get disconnected.
// If that would happen, the disk might vanish from the device-folder and therefore would not be detected by the wildcard anymore.
protected $argDisks = null;
 
public function __construct() {
parent::__construct();
 
if ($this->is_http_mode()) {
// Don't allow the standard arguments via $_REQUEST
$this->registerExpectedStandardArguments('');
} else {
$this->registerExpectedStandardArguments('Vhtv');
}
 
$this->getHelpManager()->setPluginName('vnag_disk_running');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks if a disk is running/online, even if no SMART functionality is available.');
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ -d diskname[,diskname[,...]]');
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
 
// Individual (non-standard) arguments:
$this->addExpectedArgument($this->argDisks = new VNagArgument('d', 'disknames', VNagArgument::VALUE_REQUIRED, 'disks', 'Disks to be monitored, e.g. "sda,sdb"'));
}
 
protected function cbRun() {
$count_total = 0;
$count_running = 0;
$count_offline = 0;
$count_unknown = 0;
 
$disks = $this->argDisks->getValue();
if (empty($disks)) {
throw new Exception("Please specify the disks you want to monitor.");
}
$disks = explode(',',$disks);
 
foreach ($disks as $disk) {
// We do not check the size, in case the user has more than 26 disks; https://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-named-beyond-drive-26-devsdz/
// But we check if everything is OK, and nothing nasty is done here
$disk = preg_replace('@[^a-zA-Z0-9]@', '', $disk);
 
$count_total++;
if (!file_exists("/dev/$disk")) {
$this->addVerboseMessage("$disk : Drive does not exist", VNag::VERBOSITY_SUMMARY);
$this->setStatus(VNag::STATUS_CRITICAL);
$count_offline++;
} else {
$state_file = "/sys/block/$disk/device/state";
if (!file_exists($state_file)) {
$this->addVerboseMessage("$disk : Cannot fetch state (Is this a valid block device?)", VNag::VERBOSITY_SUMMARY);
$this->setStatus(VNag::STATUS_CRITICAL);
$count_unknown++;
} else {
$state = trim(file_get_contents($state_file));
if ($state != 'running') {
$this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_SUMMARY);
$this->setStatus(VNag::STATUS_CRITICAL);
$count_offline++;
} else {
$this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
$this->setStatus(VNag::STATUS_OK); // Note: This won't unset a previously set critical state
$count_running++;
}
}
}
}
 
$this->setHeadline(sprintf('Checked %d disks (%d running, %d offline, %d unknown)', $count_total, $count_running, $count_offline, $count_unknown));
}
}
/trunk/plugins/disk_running/check_disk_running
0,0 → 1,20
#!/usr/bin/php
<?php /* <ViaThinkSoftSignature>Jb7vImFaEfIbD/bEBosJ7WbTWaSLsZAjImdNMNjIFowln2hx8D8wTwOaMCEFr6nuCxZR0KTGn5d2WTVKVdyoZTkLthgsItVd7VfCMF9cq6XegGCMkEs3Akj9m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SXiN4Ia1O7V18/xJpEVwxzsSbiKMagYoFdKM9aK6XDrYQX0Dl3UcbI42i9OZb2IYSJ2Jmurg4x8+TTrU+ou5G8s+/VWn9Cx6E9gmLD7iIT1GVjp9eUg1K3saEHxAJs5zWi/tVBwu4diW6AEpV20XGWuwaLa5eTMx3qGA==</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-11-04
*/
 
declare(ticks=1);
 
require_once __DIR__ . '/../../framework/vnag_framework.inc.php';
require_once __DIR__.'/DiskRunningCheck.class.php';
 
$job = new DiskRunningCheck();
$job->run();
unset($job);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/trunk/plugins/disk_running/icinga2.conf
0,0 → 1,35
// 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-11-04
 
object CheckCommand "vnag_disk_running" {
command = [ "/daten/vnag/plugins/disk_running/check_disk_running" ]
 
arguments = {
"-d" = {
value = "$vnag_disk_running_disks$"
description = "Disks to be monitored; can be comma separated, e.g. 'sda,sdb'"
required = true
}
"-v" = {
set_if = "$vnag_disk_running_verbose$"
description = "Additionally list drives which are OK, not just the drives which are offline."
}
}
}
 
// Example usage:
//
// apply Service "example_disk_running" {
// import "generic-service"
// check_command = "vnag_disk_running"
// vars = {
// vnag_disk_running_disks = "sda,sdb"
// vnag_disk_running_verbose = false
// }
// assign where host.name == NodeName
// }