/** * Read Nagios status from Nagios's status.dat file * @return {boolean} Returns TRUE if we file could be opened and * read, FALSE otherwise */ public function readFromStatusFile($path) { $handle = fopen($path, 'r', FALSE); if ($handle === FALSE) { return FALSE; } while ($line = StatusBase::readLine($handle)) { switch ($line) { case 'contactstatus {': $c = new ContactStatus(); $c->readFromHandle($handle); $this->contacts[$c->contact_name] = $c; break; case 'hoststatus {': $host = new HostStatus(); $host->readFromHandle($handle); $this->hosts[$host->host_name] = $host; break; case 'info {': $i = new Info(); $i->readFromHandle($handle); // FIXME: Use this for something break; case 'programstatus {': $p = new ProgramStatus(); $p->readFromHandle($handle); // FIXME: Use this for something break; case 'servicestatus {': $service = new ServiceStatus(); $service->readFromHandle($handle); $this->services[] = $service; // Add the host to the ServiceStatus class $service->host = $this->hosts[$service->host_name]; // Add the service to the "parent" HostStatus class $this->hosts[$service->host_name]->services[] = $service; break; default: break; } } fclose($handle); return TRUE; }
/** * check if the json array is valid * @param array $json * @return boolean */ public static function isJsonValid($json) { if (empty($json)) { return true; } if (isset($json['id']) && isset($json['login']) && isset($json['email']) && isset($json['identity']) && ContactIdentity::isJsonValid($json['identity']) && isset($json['status']) && ContactStatus::isJsonValid($json['status'])) { return true; } return false; }