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.

FileParser.php 931B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?PHP
  2. abstract class FileParser {
  3. protected abstract function parse_line($line);
  4. protected function parse_blockname($block) { return $block; }
  5. protected function analyse() {}
  6. public function __construct($file) {
  7. $contents = file($file);
  8. $block = '';
  9. $lines = array();
  10. foreach ($contents as $line) {
  11. $tline = trim($line);
  12. // Comments and empty lines
  13. if (empty($tline) || $tline[0] == '#') {
  14. continue;
  15. }
  16. // Close braces
  17. if ($tline[0] == '}') {
  18. if (method_exists(&$this, 'parse_' . $block)) {
  19. call_user_func(array(&$this, 'parse_' . $block), $lines);
  20. }
  21. continue;
  22. }
  23. // Open braces
  24. if (substr($tline, -1) == '{') {
  25. $block = $this->parse_blockname(trim(substr($tline, 0, -1)));
  26. $lines = array();
  27. continue;
  28. }
  29. // Other lines
  30. $lines = array_merge($lines, $this->parse_line($tline));
  31. }
  32. $this->analyse();
  33. }
  34. }
  35. ?>