Rev 6 | 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> |
31 | daniel-mar | 2 | c9r/fj8IW6Nf5LoeSJPY8SFXmPThJNj45cxTdW+9Iot0ccSLSP0kE5U7z3fKByUCa |
3 | 9bBmWXRQ38Pv6Ztfmw2mGneTXNwcWAud4NRRlRGSJ5mX3Kn6Db043oqYjl5EAV7CO |
||
4 | NTXCI1NK1go/2tIh6Cl3OMRS4dyV11F+krGrg6T1+teNJr2zpniNyWDyVImOAMJXt |
||
5 | VGL6HcXQjApsQ8/x2pzXwFJ6jFZPLZVNLbB5/mhLqiAgemgQAVIGSyJlBmYlhcoZB |
||
6 | /lCaC4RuSrVqr87d4VxREWMtaRSh0dKShXlmG85gaMnVF3eRGo+yUsw1OutIM1OPv |
||
7 | EEYRbmbZvnbGjGVnf1uP6gpeTzPQHIp+kFFLDdFus5AflovPYEDi1UHT/Ez4B6lZ4 |
||
8 | HphJOzB5kK4x1/Wurwlzfx7exGsmFElRmFxMD0wXahOpWcOYQ39RcrIrcg1RlEAfM |
||
9 | nLZRG8BUyRcaefS72jgmOTV/VgB+Ls28AkVdgWOS8eCb4egM7krg7kHHwCDHzuKcV |
||
10 | S7v03mxZi5QeMEXABJqJUqPN+09xfnkuYkXIRcDBG29Nj8wp3cmt8ND8cCjLR19fa |
||
11 | KCqKVf6u4V7vw2asKRPyYnMc3FQitwmIxDGsPtREg22wJ/R8zV8WfArNXkcq2Y6tZ |
||
12 | ws36ogjZ466SI9EQyS+YYay8Tln/wZ9uY7wZf7/L9hAAC77kEhViJ1BfAKXA7O/Lt |
||
13 | +vshYbv8H0gpkhyzgqielK/Ke1xdAiE0NujgBUuOjAWT2/WFj60ln2WRJcwVytJuK |
||
14 | Dy/VhhrYWkKArp7MNB7YI8Gj/GIvCWCGuIF7+H6tG7aNRmJoC7Tzns+4VQOhIztXr |
||
15 | rdPcPjo9e3T0zxNbNYKAwxy4QV/cymhoWP8etvPOfycEMhR4BKei+xBAft0TWVKFT |
||
16 | gxPZQg5y4ZyvpLXRyfwdrU9nncj6Gt4ot6ia7F6ctHWqvOD4y4sZ7QMP8mYsVA4Pi |
||
17 | Bf388N0mTdmmlr8Zvyzq4TD+wtioX/LmynDYAVDRcoQJOhVsSUz6LY2StolcOlBzm |
||
18 | rqBsiXEsrgLveb0Vtg93PqGCBRshKWVwOa/bZEBc8zv+4Ia36hL0bS4yLUMvllYeG |
||
19 | +K4sJI2neWKBT4PWJSx7UTKZsMDO3g7MCimfC/2EvVQp3M2Uu49QNzPUTzlHVZvVr |
||
20 | i1kyEtYaCztE2LIDOFXeeLdvz39sbloz+4/o9TyAsUd+MEXTns0SjA965Vw8bMM35 |
||
21 | CLky/HVnfGoIEo5ekhyuWrdTEgoCc2bQ7XcdoyU28IuqshbRKvdKFqAHeW8en/et1 |
||
22 | Kchk0pi+oQa/68RMxZDpJH6WEMLESPA99Fn+OfoG+j4qex1lCtzjUgvGzIgK8QZ7q |
||
6 | daniel-mar | 23 | A== |
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 | * |
||
6 | daniel-mar | 32 | * Revision 2018-12-25 |
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)) { |
||
74 | throw new Exception("Please specify the disks you want to monitor."); |
||
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 { |
||
99 | $state = trim(file_get_contents($state_file)); |
||
100 | if ($state != 'running') { |
||
101 | $this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_SUMMARY); |
||
102 | $this->setStatus(VNag::STATUS_CRITICAL); |
||
103 | $count_offline++; |
||
104 | } else { |
||
31 | daniel-mar | 105 | #$ioerr_file = "/sys/block/$disk/device/ioerr_cnt"; |
106 | #if (file_exists($ioerr_file) && (($ioerr_cont = trim(file_get_contents($ioerr_file))) != '0x0')) { |
||
107 | # $this->addVerboseMessage("$disk : High IOERR count ($ioerr_cont), but state is reported as $state", VNag::VERBOSITY_SUMMARY); |
||
108 | # $this->setStatus(VNag::STATUS_WARNING); |
||
109 | # $count_warning++; |
||
110 | #} else { |
||
6 | daniel-mar | 111 | $this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_ADDITIONAL_INFORMATION); |
112 | $this->setStatus(VNag::STATUS_OK); // Note: This won't unset a previously set critical state |
||
113 | $count_running++; |
||
31 | daniel-mar | 114 | #} |
2 | daniel-mar | 115 | } |
116 | } |
||
117 | } |
||
118 | } |
||
119 | |||
6 | daniel-mar | 120 | $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 | 121 | } |
122 | } |