A very simple monitoring daemon written in PHP without the bloat
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.

Config.php 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace PhpMonitor;
  3. class Config
  4. {
  5. protected static $configfile = 'monitor.json';
  6. protected static $data = null;
  7. public static function load($file = null)
  8. {
  9. if($file === null) {
  10. $file = self::$configfile;
  11. }
  12. if(!file_exists($file) || !is_readable($file)) {
  13. trigger_error(E_USER_ERROR, "Config file ".$file." not found!");
  14. }
  15. $content = file_get_contents($file);
  16. if(!$content) {
  17. return false;
  18. }
  19. self::$data = json_decode($content, true);
  20. return true;
  21. }
  22. public static function get($property, $defaultvalue = null)
  23. {
  24. if(self::$data === null) {
  25. self::load();
  26. }
  27. if(!isset(self::$data['config'][$property])) {
  28. return $defaultvalue;
  29. }
  30. return self::$data['config'][$property];
  31. }
  32. public static function getChecks()
  33. {
  34. if(self::$data === null) {
  35. self::load();
  36. }
  37. return self::$data['checks'];
  38. }
  39. }