PHP scripts to display a more user-friendly overview of nagios status
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StatusFileParser.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?PHP
  2. require_once(dirname(__FILE__) . '/FileParser.php');
  3. class StatusFileParser extends FileParser {
  4. private $hosts = array();
  5. private $services = array();
  6. protected function parse_line($line) {
  7. $index = strpos($line, '=');
  8. return array(substr($line, 0, $index) => substr($line, 1 + $index));
  9. }
  10. protected function parse_servicestatus($data) { $this->services[$data['host_name']][$data['service_description']] = $data; }
  11. protected function parse_hoststatus($data) { $this->hosts[$data['host_name']] = $data; }
  12. protected function parse_info($data) {}
  13. protected function parse_programstatus($data) { }
  14. protected function parse_contactstatus($data) { }
  15. protected function parse_servicecomment($data) { }
  16. protected function analyse() {
  17. foreach ($this->hosts as $hostname => $data) {
  18. $this->hosts[$hostname]['services'] = $this->services[$hostname];
  19. }
  20. unset($this->services);
  21. }
  22. public function getHosts() { return $this->hosts; }
  23. public function __construct($file = '/var/cache/nagios3/status.dat') {
  24. parent::__construct($file);
  25. }
  26. }
  27. ?>