Subversion Repositories vnag

Compare Revisions

No changes between revisions

Regard whitespace Rev 1 → Rev 2

/trunk/plugins/smart/SmartCheck.class.php
0,0 → 1,142
<?php /* <ViaThinkSoftSignature>JzjmNSphjJTRHMsIRHh892nocNxwZ2Es+ZcviS31H/rsieUvZmhp9cok7T2tEye/QwVbEbouz4zSVd9vP3Pvq37NJoqHC6s0zttRWeBrXKqkBpJnucsuT1M+OTkxdxu+CvXupKWifcXjUpQF+yxg+rPji/oaF5V8r4BZK7/GgZUyvovpuXSn2e0w91PtkrE7j9Weq8LS1SqcYeTh4AeozQC+GjWrrzzW6w90hDM1b4HSp+S5KcBQOTRY1h1umJp41XNeYb7/sPkmCsIbpf4YuzUFg4v7q9epYH/qwnfRI3Ll0jrFNYdGHFbgPGApmNkklNf7hSpWMAB1LaUh/4i/gkxceyHA8xt9i2pdHJIRiHoxzUFyIXevst0GOneUoeEUdLAyG3xCYxuai85ZvzeffkKQCVbEkQu/vitQUW6JiE3yeOMJFF9mEwPbHFC7uYEpnbV98FEsegNrxdM8vscinKmr/cGg/P2j+BjPVT+Uag+7ps5xxcmSHFIHZuD0VoKnyyDAyzOs8YhloJq0P8ovBTcJyvmj4Qzcs2UaM4WKmkFbFJhos2DxFxoPfh+DfiLVQJaO57npZOkbjX86+ann5OjkgJRgMDc4EFbfApfK1t4L57FTNJwEWIlmUl2X5k0LOXiLl0ShFGgpqfAIUvB+K7TQbEh3wRdqSuUhTigUqL/aEFygygueEPh2DhIPc//QENU22fSMcxT+Ud+uNJWgXqxCg6NxjyshWTNwvIFWX14LtqauL80TUhXnYZZVtq4tbCNqb3DAxIvqK+F1aTbgQnb/JIq+4ntHjR9t2Jp22zQ+EEzdgIabG9YRfJNYLggwgUFrlmmFht0sVJVCl4dLPo/CuK6VVTIj1PLSIKpa0mnt+cadUMrJVY1kogJHCmyzLpiwj4sff483YaH5gcOqAdJ1NlvnDJvhxZLV4JSIvuk8dGCdcuaa2HJfoVOxBFUguXB5wHsgTvOT7Ia8WpqbF6SJDfH2YqoUsAiifCUxi1C/NHffQ3mZc4ko7nzdTVHJgtfaPT1kkFscH2ZV6GZzUdJx0wcSr9e7d2zDCElP7R1rF01aiHCGlMOfdC4GnzxYH5MCgwBL/GNMN9qJmBK4sDFwJ6PiuJUlz20NlVlm/rwV0SfVaMHMtDZ7/L+ynva8W13SfsQeYhWoJxH8Um0dlvf5DG+Aq4mzMbCShHxG9zIrNSFfmYrKuh5ldot+/9FN6b4WTP7Ej1D0l55+1fcwBrXwxl8w9+awryEhXzuRtxuewnkNopqv+U3SEPlqK5nyZt8GwQZpqw1DzdGiA7jY7yAx/fTMeMs4ypVpxQJzt3Sct/BUkKHSkhSY0UrHyP2k4k29VGhwaAqZHBChglawvw==</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-17
*/
 
declare(ticks=1);
 
class SmartCheck extends VNag {
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_smart');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks the contents of the SMART data and warns when a harddisk has failed.');
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ (no additional arguments expected)');
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
}
 
private function check_smart($dev) {
if (!`which which`) {
throw new VNagException("Program 'which' is not installed on your system");
}
 
if (!`which smartctl`) {
throw new VNagException("Program 'smartctl' (usually included in package smartmontools) is not installed on your system");
}
 
if (!`sudo cat /proc/cpuinfo`) {
// To make this work, please run "visudo" and add the following line:
// nagios ALL=NOPASSWD: /usr/sbin/smartctl
throw new VNagException("You don't have SUDO privileges. Please run 'visudo' and allow the command /usr/sbin/smartctl for user ".get_current_user().".");
}
 
unset($out);
exec('sudo smartctl --all '.escapeshellarg($dev), $out, $code);
$cont = implode("\n", $out);
 
$msg = array();
$status = -1;
 
if (stripos($cont, 'device lacks SMART capability') !== false) {
// At my system (Debian 9), I get exit code 4 (which is not fully accurate)
$msg[] = 'Device lacks SMART capability';
#$status = VNag::STATUS_UNKNOWN;
} else if ($code == 0) {
$status = VNag::STATUS_OK;
} else {
if ($code & 1) {
throw new Exception("smartctl reports 'command line did not parse' (code $code).");
}
if ($code & 2) {
$msg[] = "Device open failed. It is either completely defective, or in low-power mode.";
$status = max($status, VNag::STATUS_CRITICAL);
}
if ($code & 4) {
$msg[] = "SMART command failed or checksum is wrong.";
$status = max($status, VNag::STATUS_WARNING);
}
if ($code & 8) {
$msg[] = "SMART status returns 'DISK FAILING'";
$status = max($status, VNag::STATUS_CRITICAL);
}
if ($code & 16) {
$msg[] = "SMART found prefail attributes below threshold";
$status = max($status, VNag::STATUS_WARNING);
}
if ($code & 32) {
$msg[] = "SMART status is 'OK' but usage/prefail attributes have been below threshold in the past.";
$status = max($status, VNag::STATUS_WARNING);
}
if ($code & 64) {
$msg[] = "The device error log contains records of errors.";
$status = max($status, VNag::STATUS_WARNING);
}
if ($code & 128) {
$msg[] = "The self-test logs contains records of errors.";
$status = max($status, VNag::STATUS_WARNING);
}
}
 
$messages = implode(", ", $msg);
if ($messages != '') $messages = ": $messages";
 
if ($status == VNag::STATUS_CRITICAL) {
$this->addVerboseMessage("$dev (Critical)$messages", VNag::VERBOSITY_SUMMARY);
} else if ($status == VNag::STATUS_WARNING) {
$this->addVerboseMessage("$dev (Warning)$messages", VNag::VERBOSITY_SUMMARY);
} else if ($status == VNag::STATUS_OK) {
$this->addVerboseMessage("$dev (OK)$messages", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
} else {
$status = VNag::STATUS_UNKNOWN;
$this->addVerboseMessage("$dev (Unknown)$messages", VNag::VERBOSITY_SUMMARY);
}
$this->setStatus($status);
return $status;
}
 
protected function cbRun() {
$devices = array();
$devices = array_merge($devices, glob('/dev/sd?'));
$devices = array_merge($devices, glob('/dev/hd?'));
 
$count_total = 0;
$count_ok = 0;
$count_warning = 0;
$count_critical = 0;
$count_unknown = 0;
foreach ($devices as $dev) {
$count_total++;
switch ($this->check_smart($dev)) {
case VNag::STATUS_OK:
$count_ok++;
break;
case VNag::STATUS_WARNING:
$count_warning++;
break;
case VNag::STATUS_CRITICAL:
$count_critical++;
break;
case VNag::STATUS_UNKNOWN:
$count_unknown++;
break;
}
}
 
$this->setHeadline(sprintf('Checked %d drives (%d OK, %d warning, %d critical, %d unknown)', $count_total, $count_ok, $count_warning, $count_critical, $count_unknown));
}
}
/trunk/plugins/smart/check_smart
0,0 → 1,20
#!/usr/bin/php
<?php /* <ViaThinkSoftSignature>PlZYWxINdIanFYFeUVDsTLMMxMM/raUv6IV5svu+EWfGtNMge4jicM8OwhfxJ+9xJfrw4BanWArk7PzkBD0GsT/nFZLHpRgXuMsEk7YPBlk2YxUEDkTkJeGsSy6wd/FhoHPfHlPrGveBymybvsOWlcF/bbvDJOcKoj5oDtflE2kAIg14xlKvJcy6X01iOtceueNh9KP4/PdQ+2fUGxEssGiz1MjgDjcA1teXlWtBZDlthMe6MhLpp9YPiu+13JkF5BUfZWhZqjmMpr2hYl8sz7CS6DvZxJUJIRci64qUZEdKcIljDhgCFq2m0FE9oPCNJwdX5/9bLk/lqpxjXMc0rz37TT/+Zf8i370I5EIepgzjqx+Xrut7aNyQOZ5173sKIPJDponDQToTGK30W3ZOZHWo+101+GDANM3v/l1Xk/k3XBEYBRKjYZmryGNd+9jn/byd8NLhQOLol5l34fGL6fBF1AE3BozqtqGqitKMjbnEs4grFssYb4ZQ1ynnFKPeXsYrg/0G9/Uxiv85vpPDBDujhaSbo0mdEBfN+icfbwekeWNv4Ldu+0iUhsVt/YXQ+cJenNreAM61L1KuWvC+WAbr5wBRz7z1QB0UUZ7+CeeLpxf5+PKafmiXQGPVPfhN7oiYTq3OCBWPpb4iaWeFgkJgW23y7Ydx+u89g8NAoMu8QEdxNe5hLtlpoE5yQ57aAArynICQhpCLT0sVVvq+sIl3Z9u2aPVfazsl1CPHZRXR9o+csaSp+rOU+t4lo6DzODIJfYiZ7NzO5IDR2J/C+yPzIWzDiOUG/FWbuBAofpqYvJBYzIWFY+AYxEGWG2NclTgkzd9qKfOf/CChNQpGQdvV2eAhiAN2296MG1FYdtA0N+XaS7M/Irujgcur8mWowzrz8osytTpW0+4PsT+KccuMyWwAjMUBmC18ui2a92eYs5ocXs+AmyFiknf1LvgfLE5ffa9MqU0yJZsJyxotN4ehpyaOHPx7pbxBhmiavMUPfWqPNwkG+JsqhjQAAgfQtBDPLxyk4eamnjclq6XuL+LW6z8SUnUtfNzMIdSKk6e1XdKYC5ToBfxK6TKDPg4FjhboIflD9IFG1aPPW/f3KbT2WgczpD1trJ07LSFMPn6eN0gCht2nys5n8jE5/yGVDwyF+1sMuXCCEx/2gdBGBqyL52Ao76cCD9G9jxG+cFcJN54+hQS7UQX0SV8oJy1GoKOfIkH+8QOzSx97oySFw4LWAPcNQEUhkx4sYmXD1iAnDFqp7hM0BLvSxUdprt6EYxoNH6mj4272BvCulaqM/JEvObB3/YvpbiKVTBZEyPrwJE4CXfzV4lGgLS+qs2+Zvt4NOaihB5iNiGetY+2T0w==</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__.'/SmartCheck.class.php';
 
$job = new SmartCheck();
$job->run();
unset($job);
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/trunk/plugins/smart/icinga2.conf
0,0 → 1,29
// 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_smart" {
command = [ "/daten/vnag/plugins/smart/check_smart" ]
 
arguments = {
"-v" = {
set_if = "$vnag_smart_verbose$"
description = "Additionally list drives which are OK, not just the drives which have failed."
}
}
}
 
// Example usage:
//
// apply Service "example_smart" {
// import "generic-service"
// check_command = "vnag_smart"
// vars = {
// vnag_smart_verbose = false
// }
// assign where host.name == NodeName
// }