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 871B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. call_user_func(array(&$this, 'parse_' . $block), $lines);
  19. continue;
  20. }
  21. // Open braces
  22. if (substr($tline, -1) == '{') {
  23. $block = $this->parse_blockname(trim(substr($tline, 0, -1)));
  24. $lines = array();
  25. continue;
  26. }
  27. // Other lines
  28. $lines = array_merge($lines, $this->parse_line($tline));
  29. }
  30. $this->analyse();
  31. }
  32. }
  33. ?>