Rev 28 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 28 | Rev 49 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | R+VZLh3GAQ/vs4fO8eyTRn1IEqD7XS9dR7YFDqJM3h944GnPQKym1XAkDpiQkswyq |
2 | q7QvHyotKOTpEs9fbuwcPzqwjSw69WwJkY5ah30oJKbmru7P2dq3T8e5Xz2WZygTE |
3 | Dtmsg1r43c/tkzPexDMu8YLjKC2RzT0arj86HzJgeBSoQ4W1ncmmPZ7zsP/2TGJSS |
3 | JahCPsT59QVwK92IUQQDZwQ5QO1GBwhH9sQ2LoAy7W0X9iGLxwAQM1b0Lalfr22V0 |
4 | 5rLft8xT2/XcUAi02RaHstg+j3Q6f8+wgcWTj4hg/R/uQaPoR7re27Zwx1+xsH2er |
4 | cct1CBNw2Jyv/jQXDdMGgJ0lEv677xH+zizO86+WahYUW6WZ91dFGp6gw89pMK4QA |
5 | hq7qo6oEf4kHno2gcLDyoQmUJbL2N7M0xfvrFPLoSSPuIL3EwtF9Cp3LZ3HXkUUnV |
5 | bvk6QnKmIrrfX/m6fA0SENoche/dBwFzSTSScpFCs6Xpy+aQNQUcGWyBKBePosQD0 |
6 | Bqbfnyv59ZKzVcpn9spZZKobiQJFNHbtAc3z61cTilNSvO4/5LhSk17CXtM4kjfLU |
6 | YI2TAqf7rnOuN71xgNG0JzNJQf+aBonZeBkxA98Iui4r10ws4iapq7TklJaWoy423 |
7 | n1ZLgRqNmuiKNv+wPk/H4mM3VPc9DE67VRR6V+HZNr1PEdb9DbSiYgbmCONqs7lX9 |
7 | iHUWx9PU+u5RqnthE98Dmcu/pJmQME8l/M4eSNFssUmc3Oxx3lcSMjyBmlTyOx9eA |
8 | y09sojvRztAemua0M44er/STKnmKpIGigmmMQ4ZBYh4XD34IfLYwVeX2ErK2mnBhg |
8 | 24Fg5xaLH29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UdtDDEm77OvunTI04aFqZST |
16 | gkhxB05CMxaORs5f1dFmKBKKNvZ7pQw4g/GbRxhVX+uAdVf5e4oVFEYBNviCc4tGt |
17 | XO00CNcCCByM8Q7m8qb06Od/4bjo79qhNPjHx4wYBTgLhYYKoQRTv3MyZY9BDgIE3 |
17 | MEHiPhTEa5PJbfRgxiEfyKkSjDXJeHou5O8mQjD/01cw3VMhuaStcM99DaAVunBWi |
18 | /UPyHa0h2UPhS6IjqLoIuU3WZRh+kKJMExeTNWJ+F9yVvmpDlK2pPNo279g8H7jD6 |
18 | 24uD1lLhHXybvwIiJ3OwA/oOmwL47UZ1fsKFHwMfEb4bQ9SiwosESz2V6TZHlQjbi |
19 | Dp5aSDwdwSqGE9mrMgwdDL2qjun8kWg0s69snfXSaI5qSTyoIjVmGIiSlNtdw8VsX |
19 | 1tIfhmrsxG88jtYpBPagTD09afluSRJAmEiMzl4k2+JAts3mvfGFTl5KsGGard3gq |
20 | gW/wO07WOUv+r5qsHkVZgSFKZxeGCETPKyGmGjgy9yibFyDWwoeK2NMijgJlO0QPR |
20 | zR5XlY52le3Oi0MFNQzXi+jeOJdWlIGbTb7z10rwrLemyGzFH4BPhwjV7gOlxpmE5 |
21 | d02HfMGFQ30TyAnuVDkmZf1a02czFQ/YVQbu1Hq3siQ+gqkCC8ticsBRWux6dLYFL |
21 | xFb/VeAeGCPIh5XxNq34S82EV80MMw2DK1l7T3440cTteSv4byAE2ZWo3/iH1lOXp |
22 | cYNvfVYj3c0IwBmxUNtNzFvSZLdJOAkKenk7ODGgrHSZarKNWOl6wkb3IYdNFefgM |
22 | oUEulv7DBhHv1OZHbZsU9klfScZcQVJM+FmVqtK6krBZtx5p2a49N9kD0ZOn2lc6O |
23 | g== |
23 | w== |
24 | </ViaThinkSoftSignature> */ ?> |
24 | </ViaThinkSoftSignature> */ ?> |
25 | <?php |
25 | <?php |
26 | 26 | ||
27 | /* |
27 | /* |
28 | * VNag - Nagios Framework for PHP |
28 | * VNag - Nagios Framework for PHP |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
30 | * Licensed under the terms of the Apache 2.0 license |
30 | * Licensed under the terms of the Apache 2.0 license |
31 | * |
31 | * |
32 | * Revision 2021-05-13 |
32 | * Revision 2022-05-11 |
33 | */ |
33 | */ |
34 | 34 | ||
35 | declare(ticks=1); |
35 | declare(ticks=1); |
36 | 36 | ||
37 | class SmartCheck extends VNag { |
37 | class SmartCheck extends VNag { |
- | 38 | protected $argType = null; |
|
- | 39 | ||
38 | public function __construct() { |
40 | public function __construct() { |
39 | parent::__construct(); |
41 | parent::__construct(); |
40 | 42 | ||
41 | if ($this->is_http_mode()) { |
43 | if ($this->is_http_mode()) { |
42 | // Don't allow the standard arguments via $_REQUEST |
44 | // Don't allow the standard arguments via $_REQUEST |
Line 47... | Line 49... | ||
47 | 49 | ||
48 | $this->getHelpManager()->setPluginName('vnag_smart'); |
50 | $this->getHelpManager()->setPluginName('vnag_smart'); |
49 | $this->getHelpManager()->setVersion('1.0'); |
51 | $this->getHelpManager()->setVersion('1.0'); |
50 | $this->getHelpManager()->setShortDescription('This plugin checks the contents of the SMART data and warns when a harddisk has failed.'); |
52 | $this->getHelpManager()->setShortDescription('This plugin checks the contents of the SMART data and warns when a harddisk has failed.'); |
51 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
53 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
52 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ (no additional arguments expected)'); |
54 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-T <type>]'); |
53 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
55 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
- | 56 | ||
- | 57 | // TODO: also add a command to check a single drive [ -d /dev/sda,/dev/sdb ] |
|
- | 58 | // Individual (non-standard) arguments: |
|
- | 59 | $this->addExpectedArgument($this->argType = new VNagArgument('T', 'type', VNagArgument::VALUE_REQUIRED, 'type', 'e.g. for RAID devices "sat+cciss,0" for drive 0.')); |
|
54 | } |
60 | } |
55 | 61 | ||
56 | private function check_smart($dev) { |
62 | private function check_smart($dev) { |
57 | if (!`which which`) { |
63 | if (!`which which`) { |
58 | throw new VNagException("Program 'which' is not installed on your system"); |
64 | throw new VNagException("Program 'which' is not installed on your system"); |
Line 68... | Line 74... | ||
68 | throw new VNagException("You don't have SUDO privileges. Please run 'visudo' and allow the command /usr/sbin/smartctl for user ".get_current_user()."."); |
74 | throw new VNagException("You don't have SUDO privileges. Please run 'visudo' and allow the command /usr/sbin/smartctl for user ".get_current_user()."."); |
69 | } |
75 | } |
70 | 76 | ||
71 | $code = 0; |
77 | $code = 0; |
72 | $out = array(); |
78 | $out = array(); |
- | 79 | ||
- | 80 | if ($this->argType->getValue() != '') { |
|
- | 81 | exec('sudo smartctl --all '.escapeshellarg($dev).' -d '.escapeshellarg($this->argType->getValue()), $out, $code); |
|
- | 82 | } else { |
|
73 | exec('sudo smartctl --all '.escapeshellarg($dev), $out, $code); |
83 | exec('sudo smartctl --all '.escapeshellarg($dev), $out, $code); |
- | 84 | } |
|
74 | $cont = implode("\n", $out); |
85 | $cont = implode("\n", $out); |
75 | 86 | ||
76 | $msg = array(); |
87 | $msg = array(); |
77 | $status = -1; |
88 | $status = -1; |
78 | 89 | ||
Line 136... | Line 147... | ||
136 | protected function cbRun() { |
147 | protected function cbRun() { |
137 | $devices = array(); |
148 | $devices = array(); |
138 | $devices = array_merge($devices, glob('/dev/sd?')); |
149 | $devices = array_merge($devices, glob('/dev/sd?')); |
139 | $devices = array_merge($devices, glob('/dev/hd?')); |
150 | $devices = array_merge($devices, glob('/dev/hd?')); |
140 | 151 | ||
- | 152 | if (count($devices) == 0) { |
|
- | 153 | throw new Exception("No SDx or HDx drives found"); |
|
- | 154 | } |
|
- | 155 | ||
- | 156 | if (strpos($this->argType->getValue(),'cciss') !== false) { |
|
- | 157 | $devices = array($devices[0]); // we just need a "fake" drive; the drive number is given as parameter to cciss |
|
- | 158 | } |
|
- | 159 | ||
141 | $count_total = 0; |
160 | $count_total = 0; |
142 | $count_ok = 0; |
161 | $count_ok = 0; |
143 | $count_warning = 0; |
162 | $count_warning = 0; |
144 | $count_critical = 0; |
163 | $count_critical = 0; |
145 | $count_unknown = 0; |
164 | $count_unknown = 0; |