Subversion Repositories vnag

Rev

Rev 2 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>
  2. F9z2AfT7nAZ8u/BI8TAx/BdR2s+t778tdYJG4+lJV7Oqve9Zovt7XxsagYPLn4q3a
  3. cTV8dGL2yaMvIWdPqwpWhu9ssXL9NN81pvIItF5t7GR9NWGS71nHMrr9pjQoIn+R6
  4. exKklwpuSMMQgFYKiCh5tUKnaMtEgQm/uQYTRei2UhOeV1s59MJ5/b6TOOcy/NNkO
  5. /lYQuflZ+mk5L3VcBtdi6F8sLhoiw4gy+oDDyNpGNSNjiB0mi3CMuQDXpnuAOSv9J
  6. luhQMRhQlTfKKaiF+4J7EGKuW3D8lt5FKuF+rGca1Iixtbi4bemQ9RqY3pbgKPg/i
  7. NdpxY+j24FcRJ7P6QvHBcY+lb1YL0ss9LqxMOV6DeNg+UOu5Aa1AerA8vfIQ4k7iK
  8. 8Wt1e+9FXsmGmm84SgJ0gukRNRSzCreb+9glJ52V/PMNZcAiH7Qe7O/bzSeaqHlGI
  9. sgghkwt+XEBfyAiemuwBRN5GzyJsMOK7VH1Z+YGcj+V9I3SKkfZVABP6zyq/GwN4E
  10. OA2sQ9OCo3PVOcreVsIR+mYTUPfWBB+pd/M9Pu73LnA2WweoeKk/owrrb//uDEfBp
  11. Ca5TIiDahng2xKaBBZTBJ++mO1kSzBP8X+n5KQToQQCmTzSJvZBXB6h4dqOVm6Dik
  12. flV62JzOPP2839u48PMIo/6NFheEJnSHLR88f1X0B1lDmAgyc41m1sVk55hiTV5QQ
  13. 9OJthifgehh9p0kakzY5H1PmltTrwlzBbFFE7BypH1rwyzRCwlXMKlFl74DWAY69Z
  14. Rs6UaOXC0gbuKJT+blD4dfuEuUut/fQyFYwsFsyPgPzhjAsqnVgHT5IbkBrw2tVZ9
  15. NZgraYZjZyW+OFBFMk6fhvuxKzPxJXCHT2JAZ6hTwUPoPfq1GogrDMMmLQ0rorUgV
  16. MGuCN/lYtB57ak7QiE6Eczyob8qM60r+m738RysL5Jxg6IPGoT1rtekQKqAFGXUT5
  17. 0jOeTCu6aOSFwLCbisGf+ospZ1POtgFofTPygQJgO2uEkfPDjgkd04oP/p4S9UgIp
  18. UDQwlxZkz+MV2ErOSegvpcirTwt7OT2nJNN/FZUE3SOpP6tsRbYH+61kEhmbRK70e
  19. beX6kwF8C6LB+eBvxMgups32MsFQOMucsqmyxV/uz5SM2BLn1giTn13fjJZMhnmz5
  20. fqHequgbiJ7vIUjUOpE/ccB6EuRFtirMNlZrVq3J26VEy9s3T9Rd/nV1k+cWLda+l
  21. BoLszPI7pRHOIda37RGTbWNPhvxDkG5sIVERQH8/rgTmBK1V/1tabXwDSn6FvzddV
  22. KPyXgcXsGefz6TcUMB0c0JMhnRY+/+m/MCQ1mAppVbAQUX+Ha9CJR1xw0e5P+hePw
  23. w==
  24. </ViaThinkSoftSignature> */ ?>
  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.  *
  32.  * Revision 2018-11-04
  33.  */
  34.  
  35. declare(ticks=1);
  36.  
  37. class DiskRunningCheck extends VNag {
  38.         // 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.
  39.         // If that would happen, the disk might vanish from the device-folder and therefore would not be detected by the wildcard anymore.
  40.         protected $argDisks = null;
  41.  
  42.         public function __construct() {
  43.                 parent::__construct();
  44.  
  45.                 if ($this->is_http_mode()) {
  46.                         // Don't allow the standard arguments via $_REQUEST
  47.                         $this->registerExpectedStandardArguments('');
  48.                 } else {
  49.                         $this->registerExpectedStandardArguments('Vhtv');
  50.                 }
  51.  
  52.                 $this->getHelpManager()->setPluginName('vnag_disk_running');
  53.                 $this->getHelpManager()->setVersion('1.0');
  54.                 $this->getHelpManager()->setShortDescription('This plugin checks if a disk is running/online, even if no SMART functionality is available.');
  55.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  56.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ -d diskname[,diskname[,...]]');
  57.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  58.  
  59.                 // Individual (non-standard) arguments:
  60.                 $this->addExpectedArgument($this->argDisks = new VNagArgument('d', 'disknames', VNagArgument::VALUE_REQUIRED, 'disks', 'Disks to be monitored, e.g. "sda,sdb"'));
  61.         }
  62.  
  63.         protected function cbRun() {
  64.                 $count_total = 0;
  65.                 $count_running = 0;
  66.                 $count_offline = 0;
  67.                 $count_unknown = 0;
  68.  
  69.                 $disks = $this->argDisks->getValue();
  70.                 if (empty($disks)) {
  71.                         throw new Exception("Please specify the disks you want to monitor.");
  72.                 }
  73.                 $disks = explode(',',$disks);
  74.  
  75.                 foreach ($disks as $disk) {
  76.                         // 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/
  77.                         // But we check if everything is OK, and nothing nasty is done here
  78.                         $disk = preg_replace('@[^a-zA-Z0-9]@', '', $disk);
  79.  
  80.                         $count_total++;
  81.                         if (!file_exists("/dev/$disk")) {
  82.                                 $this->addVerboseMessage("$disk : Drive does not exist", VNag::VERBOSITY_SUMMARY);
  83.                                 $this->setStatus(VNag::STATUS_CRITICAL);
  84.                                 $count_offline++;
  85.                         } else {
  86.                                 $state_file = "/sys/block/$disk/device/state";
  87.                                 if (!file_exists($state_file)) {
  88.                                         $this->addVerboseMessage("$disk : Cannot fetch state (Is this a valid block device?)", VNag::VERBOSITY_SUMMARY);
  89.                                         $this->setStatus(VNag::STATUS_CRITICAL);
  90.                                         $count_unknown++;
  91.                                 } else {
  92.                                         $state = trim(file_get_contents($state_file));
  93.                                         if ($state != 'running') {
  94.                                                 $this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_SUMMARY);
  95.                                                 $this->setStatus(VNag::STATUS_CRITICAL);
  96.                                                 $count_offline++;
  97.                                         } else {
  98.                                                 $this->addVerboseMessage("$disk : $state", VNag::VERBOSITY_ADDITIONAL_INFORMATION);
  99.                                                 $this->setStatus(VNag::STATUS_OK); // Note: This won't unset a previously set critical state
  100.                                                 $count_running++;
  101.                                         }
  102.                                 }
  103.                         }
  104.                 }
  105.  
  106.                 $this->setHeadline(sprintf('Checked %d disks (%d running, %d offline, %d unknown)', $count_total, $count_running, $count_offline, $count_unknown));
  107.         }
  108. }
  109.