示例#1
0
 function nagios_check()
 {
     $conn =& $this->conn;
     $sql = "desc host_services;";
     $res = $conn->Execute($sql);
     $sql = "show columns from host_services where Field like 'nagios';";
     $res = $conn->Execute($sql);
     if ($res->EOF) {
         echo "Creating nagios flag for host_services<br>";
         $sql = "ALTER TABLE `host_services` ADD COLUMN `nagios` boolean  NOT NULL DEFAULT 1 AFTER `anom`;";
         $res = $conn->Execute($sql);
         if (!$res) {
             echo "Nagios flag was NOT created!";
             return true;
         }
     } else {
         echo "Nagios flag already created.. ok<br>";
     }
     // Create configurations for the old hosts that have nagios enabled
     $sql = "select h.ip, h.hostname from host h, host_scan hs where hs.plugin_id=2007 and hs.host_ip=inet_aton(h.ip);";
     $res = $conn->Execute($sql);
     if (!$res->EOF) {
         echo "Creating nagios host definitions<br>";
         while (!$res->EOF) {
             $host_ip = $res->fields["ip"];
             $hostname = $res->fields["hostname"];
             echo "Checking nagios config for {$hostname} ({$host_ip})<br>";
             $sensors = "";
             $q = new NagiosAdm();
             $q->addHost(new NagiosHost($host_ip, $hostname, $sensors));
             $q->close();
             $res->MoveNext();
         }
         echo "Done!<br>";
     } else {
         echo "The creation of nagios host definition is not needed right now<br>";
     }
     return true;
 }