Rev 31 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
77 | daniel-mar | 2 | PWwDKp/NSf/rrEh35zHyCMaO4gcZlVT+EjMyvCDND7VbDr2OfniffusJQ/+G/mPHZ |
3 | v2dTvk6poY69nCYrUnsqeEdmeVhi5l++vvSAvpVUZiENZkyRUrTBkPVBhQcT8kviQ |
||
4 | pfuBHklcTOhQqiN6MMKD1fS9MkG5jqelOSvMt3L35tTlQk0Fdkbu8WTp2kqWJ/gaA |
||
5 | aZQzTXCserS7Y7SHpWoVvul7kfnpKWkspryM0l1Ih8fCFhYrB7/mMKTL9TqgKd9Ka |
||
6 | f1VGax1Xm3H6z8OkJ8HfgbvbuvC+zruB9J7uYFCnnrtS5JqL660UV61zkTVLE0KBE |
||
7 | Qd8T2cs8ROPsJpwO3StbG3ZU2rDChfpLVKV7VsEYnQpjyIACwIlu4E2kMTzOlIPaP |
||
8 | hl/9HDuL7vfM8DYkUVvvMtxqvVVHYpIx/AFigxakY2HteLmfekxhL9uRJqX2e4SJH |
||
9 | XWeu731yuH+0/c82rzLbEKadHYtV4XBXOxIlSxl4VYM17RCe0r2/R392aMQ4Ziy9j |
||
10 | dhQo22vBJrtmIutBpH7KaecQUwT+hM8sWas68xwfIMWzFuwofsanyA2iJvRx5tR+s |
||
11 | J0mhHQ08HszAqZ+G8byAuW6z8ncRieLhseu2g91OMHOiuDnxpDbGqqrluXDDGs7W+ |
||
12 | 0aHGPmIbPTYTP6LGyuqV/Q5gg0tgZh0ESFWLoRh1mzrJMBh6ZYMrsByfAruq9ewdB |
||
13 | FZ8rE3a91IhpbFa76wfcN81lk6QMrrc0crd0Fp359xUacXAz6DEO4mQ/f5g06p6rz |
||
14 | jPLfClhpm1Z5AhhaVZS8AhgHNrXSFchksoE+oruo+CO3QDhcZKygGXntMb0I0KIYR |
||
15 | 8hsl0CYfkDD9oaMSXPE4g22WO48k6jKxt3MyCSta4vtnTeH6Quon6PEvSXkRs4ZCa |
||
16 | aKYy8owaVxds+h0lGd4eNBgP/bZZb5nxeMuOlO9lhvEgxpXoksLB8Oh10BMj9EBQT |
||
17 | T2TaEtY1GyIr0shBb/mD5BQO0v+qW3PHKbtDtWccKPxNo5Cx4CPf0AiHoqzj6Sa6C |
||
18 | 7MdS57nQ9DQAnwhBPOJ5+tt1LF468AerjjdDjsWEYMmicZjOpPM/9APdJjUe312+9 |
||
19 | AkVN9Mz3mVQ8DGpI0wEfDdrHH9IWs1G/0RofVtQo23PxyFbX8S64Di7vwBrlrgrWg |
||
20 | esBRLltyn9hSdqv+C1XEJltlunWo2yM/HggjK9mbq2pNLqgW2r/Ddfhbhg+UnHPk+ |
||
21 | 3XlC2nyPLzLt9Mpf/3IrfbTl3siOB1F6eQT2cQCa9pKrrE1TJu49oMmpiwmD3xT6P |
||
22 | P1c6cVZn8g3N+MdZEJJknf492Zr1Y5oSx93ofxLFYrh5Mf3CDrHAPOTpPZ9J5Kh3s |
||
23 | Q== |
||
4 | daniel-mar | 24 | </ViaThinkSoftSignature> */ ?> |
2 | daniel-mar | 25 | <?php |
26 | |||
27 | /* |
||
28 | * VNag - Nagios Framework for PHP |
||
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
30 | * Licensed under the terms of the Apache 2.0 license |
||
31 | * |
||
77 | daniel-mar | 32 | * Revision 2023-10-13 |
2 | daniel-mar | 33 | */ |
34 | |||
6 | daniel-mar | 35 | // TODO: Anstelle "-d diskname[,diskname[,...]]" wäre es schöner ohne Komma, denn dann könnte man auch die Shell Erweiterung /dev/sd* nutzen |
36 | |||
2 | daniel-mar | 37 | declare(ticks=1); |
38 | |||
39 | class DiskRunningCheck extends VNag { |
||
40 | // 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. |
||
41 | // If that would happen, the disk might vanish from the device-folder and therefore would not be detected by the wildcard anymore. |
||
42 | protected $argDisks = null; |
||
43 | |||
44 | public function __construct() { |
||
45 | parent::__construct(); |
||
46 | |||
47 | if ($this->is_http_mode()) { |
||
48 | // Don't allow the standard arguments via $_REQUEST |
||
49 | $this->registerExpectedStandardArguments(''); |
||
50 | } else { |
||
51 | $this->registerExpectedStandardArguments('Vhtv'); |
||
52 | } |
||
53 | |||
54 | $this->getHelpManager()->setPluginName('vnag_disk_running'); |
||
55 | $this->getHelpManager()->setVersion('1.0'); |
||
56 | $this->getHelpManager()->setShortDescription('This plugin checks if a disk is running/online, even if no SMART functionality is available.'); |
||
57 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
58 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ -d diskname[,diskname[,...]]'); |
||
59 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
60 | |||
61 | // Individual (non-standard) arguments: |
||
62 | $this->addExpectedArgument($this->argDisks = new VNagArgument('d', 'disknames', VNagArgument::VALUE_REQUIRED, 'disks', 'Disks to be monitored, e.g. "sda,sdb"')); |
||
63 | } |
||
64 | |||
65 | protected function cbRun() { |
||
66 | $count_total = 0; |
||
67 | $count_running = 0; |
||
68 | $count_offline = 0; |
||
6 | daniel-mar | 69 | $count_warning = 0; |
2 | daniel-mar | 70 | $count_unknown = 0; |
71 | |||
72 | $disks = $this->argDisks->getValue(); |
||
73 | if (empty($disks)) { |
||
77 | daniel-mar | 74 | throw new VNagException("Please specify the disks you want to monitor."); |
2 | daniel-mar | 75 | } |
76 | $disks = explode(',',$disks); |
||
77 | |||
78 | foreach ($disks as $disk) { |
||
6 | daniel-mar | 79 | $disk = preg_replace('@^/dev/@', '', $disk); // accept '/dev/' too |
80 | |||
2 | daniel-mar | 81 | // 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/ |
82 | // But we check if everything is OK, and nothing nasty is done here |
||
83 | $disk = preg_replace('@[^a-zA-Z0-9]@', '', $disk); |
||
84 | |||
6 | daniel-mar | 85 | $disk = preg_replace('@^(...)\d+@', '\\1', $disk); // accept 'sdh1' too |
86 | |||
2 | daniel-mar | 87 | $count_total++; |
88 | if (!file_exists("/dev/$disk")) { |
||
89 | $this->addVerboseMessage("$disk : Drive does not exist", VNag::VERBOSITY_SUMMARY); |
||
90 | $this->setStatus(VNag::STATUS_CRITICAL); |
||
91 | $count_offline++; |
||
92 | } else { |
||
93 | $state_file = "/sys/block/$disk/device/state"; |
||
94 | if (!file_exists($state_file)) { |
||
95 | $this->addVerboseMessage("$disk : Cannot fetch state (Is this a valid block device?)", VNag::VERBOSITY_SUMMARY); |
||
96 | $this->setStatus(VNag::STATUS_CRITICAL); |
||
97 | $count_unknown++; |
||
98 | } else { |
||
77 | daniel-mar | 99 | $cont = @file_get_contents($state_file); |
100 | if ($cont === false) throw new VNagException("Cannot read $state_file"); |
||
101 | $state = trim($cont); |
||
2 | daniel-mar | 102 | if ($state != 'running') { |
103 | $this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_SUMMARY); |
||
104 | $this->setStatus(VNag::STATUS_CRITICAL); |
||
105 | $count_offline++; |
||
106 | } else { |
||
31 | daniel-mar | 107 | #$ioerr_file = "/sys/block/$disk/device/ioerr_cnt"; |
108 | #if (file_exists($ioerr_file) && (($ioerr_cont = trim(file_get_contents($ioerr_file))) != '0x0')) { |
||
109 | # $this->addVerboseMessage("$disk : High IOERR count ($ioerr_cont), but state is reported as $state", VNag::VERBOSITY_SUMMARY); |
||
110 | # $this->setStatus(VNag::STATUS_WARNING); |
||
111 | # $count_warning++; |
||
112 | #} else { |
||
6 | daniel-mar | 113 | $this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_ADDITIONAL_INFORMATION); |
114 | $this->setStatus(VNag::STATUS_OK); // Note: This won't unset a previously set critical state |
||
115 | $count_running++; |
||
31 | daniel-mar | 116 | #} |
2 | daniel-mar | 117 | } |
118 | } |
||
119 | } |
||
120 | } |
||
121 | |||
6 | daniel-mar | 122 | $this->setHeadline(sprintf('Checked %d disks (%d running, %d offline, %d warnings, %d unknown)', $count_total, $count_running, $count_offline, $count_warning, $count_unknown)); |
2 | daniel-mar | 123 | } |
124 | } |