コード例 #1
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityServiceGroupImporter beginning to import Service Group Configuration.");
     // service groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_servicegroups", PDO::FETCH_ASSOC) as $serviceGroup) {
         if (NagiosContactGroupPeer::getByName($serviceGroup['servicegroup_name'])) {
             $job->addNotice("Fruity Service Group Importer: Group " . $serviceGroup['servicegroup_name'] . " already exists.  Aborting it's import.");
             continue;
         }
         $newServiceGroup = new NagiosServiceGroup();
         $newServiceGroup->setName($serviceGroup['servicegroup_name']);
         $newServiceGroup->setAlias($serviceGroup['alias']);
         $newServiceGroup->save();
     }
     $job->addNotice("FruityServiceGroupImporter finished importing Service Group Configuration.");
 }
コード例 #2
0
ファイル: FruityHostImporter.php プロジェクト: Evolix/lilac
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityHostImporter beginning to import Host Configuration.");
     // Hosts
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts", PDO::FETCH_ASSOC) as $hostData) {
         $this->importHost($hostData);
     }
     // Host parents
     // go through, check if the host actually exists in our system
     // now, then add the parents, if it's found.
     // First the host table,
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts", PDO::FETCH_ASSOC) as $hostData) {
         if (empty($hostData['parents'])) {
             continue;
         }
         // Okay, there's actually an parent in here.
         // Get the name.
         $name = $this->getHostNameById($hostData['parents'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Importer: Could not find host with id: " . $hostData['parents'] . " to add as parent.");
         } else {
             // Okay, $name is equal to the parent host name.  Let's get the name
             // of the host this parent belongs to
             $childName = $this->getHostNameById($hostData['host_id'], $this->dbConn);
             // Okay, fetch our host which should have this name.
             $host = NagiosHostPeer::getByName($childName);
             if (!$host) {
                 $job->addWarning("Fruity Host Importer: Could not find host in Lilac with name: " . $childName);
             } else {
                 $host->addParentByName($name);
                 $host->save();
             }
         }
     }
     // then the nagios_host_parents table
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_parents", PDO::FETCH_ASSOC) as $hostData) {
         // Get the name.
         $name = $this->getHostNameById($hostData['parent_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Importer: Could not find host with id: " . $hostData['parents'] . " to add as parent.");
         } else {
             // Okay, $name is equal to the parent host name.  Let's get the name
             // of the host this parent belongs to
             $childName = $this->getHostNameById($hostData['child_id'], $this->dbConn);
             // Okay, fetch our host which should have this name.
             $host = NagiosHostPeer::getByName($childName);
             if (!$host) {
                 $job->addWarning("Fruity Host Importer: Could not find host in Lilac with name: " . $childName);
             } else {
                 $host->addParentByName($name);
                 $host->save();
             }
         }
     }
     // Host Check Command Parameters
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts_check_command_parameters WHERE host_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $hostName = $this->getHostNameById($commandParameterInfo['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Host Check Command Parameter Importer: Could not find host with id " . $commandParameterInfo['host_id']);
             continue;
         }
         // Get the host
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Host Check Command Parameter Importer: Could not find host with name " . $hostTemplateName);
             continue;
         }
         $newParameter = new NagiosHostCheckCommandParameter();
         $newParameter->setHost($host->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Host Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostName = $this->getHostNameById($membershipInfo['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find host with id " . $membershipInfo['host_id']);
             continue;
         }
         // Get the template
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find host with name " . $hostName);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Host Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosHostContactGroup();
         $membership->setHost($host->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Host Extended Information
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $hostName = $this->getHostNameById($extInfo['host_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Extended Info Importer: Could not find host with id " . $extInfo['host_id']);
             continue;
         }
         // Get the host
         $host = NagiosHostPeer::getByName($hostName);
         if (!$hostName) {
             $job->addNotice("Fruity Host Extended Info Importer: Could not find host with name " . $hostTemplateName);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $host->setNotes($extInfo['notes']);
         $host->setNotesUrl($extInfo['notes_url']);
         $host->setActionUrl($extInfo['action_url']);
         $host->setIconImage($extInfo['icon_image']);
         $host->setIconImageAlt($extInfo['icon_image_alt']);
         $host->setVrmlImage($extInfo['vrml_image']);
         $host->setStatusmapImage($extInfo['statusmap_image']);
         $host->setTwoDCoords($extInfo['two_d_coords']);
         $host->setThreeDCoords($extInfo['three_d_coords']);
         $host->save();
     }
     // Host group memberships
     foreach ($this->dbConn->query("SELECT * FROM nagios_hostgroup_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostName = $this->getHostNameById($membershipInfo['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host with id " . $membershipInfo['host_id']);
             continue;
         }
         // Get the template
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host with name " . $hostName);
             continue;
         }
         // Now get Host Group Name
         $hostGroupName = $this->getHostGroupNameById($membershipInfo['hostgroup_id']);
         if (!$hostGroupName) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host group with id: " . $membershipInfo['hostgroup_id']);
             continue;
         }
         $hostGroup = NagiosHostGroupPeer::getByName($hostGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Host Host Group Importer: Could not find host group with name: " . $hostGroupName);
             continue;
         }
         $membership = new NagiosHostgroupMembership();
         $membership->setHost($host->getId());
         $membership->setNagiosHostGroup($hostGroup);
         $membership->save();
     }
     $job->addNotice("FruityHostImported: Finished importing a total of " . $this->totalImported . " hosts.");
 }
コード例 #3
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityServiceImporter beginning to import Service Configuration.");
     // Services
     foreach ($this->dbConn->query("SELECT * FROM nagios_services", PDO::FETCH_ASSOC) as $service) {
         $this->importService($service);
     }
     // Service template check commands
     $job->addNotice("FruityServiceImporter now processing Service Check Commands.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_services_check_command_parameters WHERE service_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $service = $this->getLilacServiceById($commandParameterInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id: " . $commandParameterInfo['service_id']);
             continue;
         }
         $newParameter = new NagiosServiceCheckCommandParameter();
         $newParameter->setService($service->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Service extended information
     $job->addNotice("FruityServiceImporter now processing Service Extended Information.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_services_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $service = $this->getLilacServiceById($extInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $extInfo['service_id']);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $service->setNotes($extInfo['notes']);
         $service->setNotesUrl($extInfo['notes_url']);
         $service->setActionUrl($extInfo['action_url']);
         $service->setIconImage($extInfo['icon_image']);
         $service->setIconImageAlt($extInfo['icon_image_alt']);
         $service->save();
     }
     // Service contact group memberships
     $job->addNotice("FruityServiceImporter now processing Service Contact Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_service_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $service = $this->getLilacServiceById($membershipInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $membershipInfo['service_id']);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Service Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosServiceContactGroupMember();
         $membership->setService($service->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Service service group memberships
     $job->addNotice("FruityServiceImporter now processing Service Service Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_servicegroup_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $service = $this->getLilacServiceById($membershipInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $membershipInfo['service_id']);
             continue;
         }
         // Now get Contact Group Name
         $serviceGroupName = $this->getServiceGroupNameById($membershipInfo['servicegroup_id']);
         if (!$serviceGroupName) {
             $job->addNotice("Fruity Service Service Group Importer: Could not find service group with id: " . $membershipInfo['servicegroup_id']);
             continue;
         }
         $serviceGroup = NagiosServiceGroupPeer::getByName($serviceGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Service Group Importer: Could not find service group with name: " . $serviceGroupName);
             continue;
         }
         $membership = new NagiosServiceGroupMember();
         $membership->setService($service->getId());
         $membership->setNagiosServiceGroup($serviceGroup);
         $membership->save();
     }
     $job->addNotice("FruityServiceImporter finished importing Service Group Configuration.");
     $job->addNotice("FruityServiceImporter imported a total of " . $this->totalImported . " services.");
 }
コード例 #4
0
 private function __addContacts($escalation)
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // Check if we need to bring in values from a template
     if (isset($values['use'])) {
         // We sure are using a template!
         // Okay, hokey multi-inheritance support for the importer
         $tempValues = $this->getTemplateValues($values['use'][0]['value']);
         // Okay, go through each
         foreach ($tempValues as $key => $val) {
             if (!isset($values[$key])) {
                 $values[$key] = $val;
             }
         }
     }
     if (isset($values['contacts'])) {
         $contactNames = explode(",", $values['contacts'][0]['value']);
         foreach ($contactNames as $contact_name) {
             $contact = NagiosContactPeer::getByName($contact_name);
             if (!$contact) {
                 return false;
             }
             $relationship = new NagiosEscalationContact();
             $relationship->setNagiosContact($contact);
             $relationship->setNagiosEscalation($escalation);
             $relationship->save();
             $contact->clearAllReferences(true);
             $relationship->clearAllReferences(true);
         }
     }
     if (isset($values['contact_groups'])) {
         $contactGroupNames = explode(",", $values['contact_groups'][0]['value']);
         foreach ($contactGroupNames as $contactgroup_name) {
             $contactgroup = NagiosContactGroupPeer::getByName($contactgroup_name);
             if (!$contactgroup) {
                 return false;
             }
             $relationship = new NagiosEscalationContactGroup();
             $relationship->setNagiosContactGroup($contactgroup);
             $relationship->setNagiosEscalation($escalation);
             $relationship->save();
             $contactgroup->clearAllReferences(true);
             $relationship->clearAllReferences(true);
         }
     }
     return true;
 }
コード例 #5
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityContactImporter beginning to import Contact Configuration.");
     // Contacts
     foreach ($this->dbConn->query("SELECT * FROM nagios_contacts", PDO::FETCH_ASSOC) as $contact) {
         // Check for existing
         if (NagiosContactPeer::getByName($contact['contact_name'])) {
             $job->addNotice("Fruity Contact Importer: Contact " . $contact['contact_name'] . " already exists.  Aborting it's import.");
             continue;
         }
         $newContact = new NagiosContact();
         foreach ($contact as $key => $val) {
             unset($name);
             if ($key == "contact_id") {
                 continue;
             }
             if ($key == "contact_name") {
                 $key = "name";
             }
             if ($key == "host_notification_options_down") {
                 $key = "host_notification_on_down";
             }
             if ($key == "host_notification_options_unreachable") {
                 $key = "host_notification_on_unreachable";
             }
             if ($key == "host_notification_options_recovery") {
                 $key = "host_notification_on_recovery";
             }
             if ($key == "host_notification_options_flapping") {
                 $key = "host_notification_on_flapping";
             }
             if ($key == "service_notification_options_warning") {
                 $key = "service_notification_on_warning";
             }
             if ($key == "service_notification_options_unknown") {
                 $key = "service_notification_on_unknown";
             }
             if ($key == "service_notification_options_critical") {
                 $key = "service_notification_on_critical";
             }
             if ($key == "service_notification_options_recovery") {
                 $key = "service_notification_on_recovery";
             }
             if ($key == "service_notification_options_flapping") {
                 $key = "service_notification_on_flapping";
             }
             if ($key == "host_notification_period") {
                 $name = $this->getTimeperiodNameById($val, $this->dbConn);
                 if ($name) {
                     $newContact->setHostNotificationPeriodByName($name);
                 }
                 continue;
             }
             if ($key == "service_notification_period") {
                 $name = $this->getTimeperiodNameById($val, $this->dbConn);
                 if ($name) {
                     $newContact->setServiceNotificationPeriodByName($name);
                 }
                 continue;
             }
             try {
                 $name = NagiosContactPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Contact Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newContact->{$method}($val);
             }
         }
         $newContact->save();
     }
     // Contact Addresses
     foreach ($this->dbConn->query("SELECT * FROM nagios_contact_addresses", PDO::FETCH_ASSOC) as $address) {
         // Check for required contact
         $name = $this->getContactNameById($address['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Address Importer: Could not find contact with id: " . $address['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Address Importer: Could not find contact with name: " . $name);
             continue;
         }
         $newContactAddress = new NagiosContactAddress();
         $newContactAddress->setNagiosContact($contact);
         $newContactAddress->setAddress($address['address']);
         $newContactAddress->save();
     }
     // Contact Notification Commands
     foreach ($this->dbConn->query("SELECT * FROM nagios_contacts_notification_commands", PDO::FETCH_ASSOC) as $notificationCommand) {
         // Check for required contact
         $name = $this->getContactNameById($notificationCommand['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find contact with id: " . $notificationCommand['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find contact with name: " . $name);
             continue;
         }
         // Okay, now get the required command
         $name = $this->getCommandNameById($notificationCommand['command_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Crontact Notification Command Importer: Could not find command with id: " . $notificationCommand['contact_id']);
             continue;
         }
         $command = NagiosCommandPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find command with name: " . $name);
             continue;
         }
         $newNotificationCommand = new NagiosContactNotificationCommand();
         $newNotificationCommand->setNagiosContact($contact);
         $newNotificationCommand->setNagiosCommand($command);
         $newNotificationCommand->setType($notificationCommand['notification_type']);
         $newNotificationCommand->save();
     }
     // Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_contactgroups", PDO::FETCH_ASSOC) as $contactGroup) {
         if (NagiosContactGroupPeer::getByName($contactGroup['contactgroup_name'])) {
             $job->addNotice("Fruity Contact Group Importer: Group " . $contactGroup['contactgroup_name'] . "already exists.  Aborting it's import.");
             continue;
         }
         $newContactGroup = new NagiosContactGroup();
         $newContactGroup->setName($contactGroup['contactgroup_name']);
         $newContactGroup->setAlias($contactGroup['alias']);
         $newContactGroup->save();
     }
     // Contact Group Members
     foreach ($this->dbConn->query("SELECT * FROM nagios_contactgroup_membership", PDO::FETCH_ASSOC) as $membership) {
         // Check for required contact
         $name = $this->getContactNameById($membership['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact with id: " . $membership['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact with name: " . $name);
             continue;
         }
         // Okay, now get the required contact group
         $name = $this->getContactGroupNameById($membership['contactgroup_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact group with id: " . $membership['contactgroup_id']);
             continue;
         }
         $contactgroup = NagiosContactGroupPeer::getByName($name);
         if (!$contactgroup) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact group with name: " . $name);
             continue;
         }
         $newMembership = new NagiosContactGroupMember();
         $newMembership->setNagiosContact($contact);
         $newMembership->setNagiosContactGroup($contactgroup);
         $newMembership->save();
     }
     $job->addNotice("FruityContactImporter finished importing Contact Configuration.");
 }
コード例 #6
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityEscalationImporter beginning to import Dependency Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_escalations", PDO::FETCH_ASSOC) as $escalation) {
         $newEscalation = new NagiosEscalation();
         if (!empty($escalation['service_id'])) {
             // This is a service escalation
             $lilacService = $this->getLilacServiceById($escalation['service_id']);
             if (!$lilacService) {
                 $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service with an id matching: " . $escalation['service_id']);
                 return true;
             }
             $newEscalation->setService($lilacService->getId());
         } else {
             if (!empty($escalation['host_id'])) {
                 // This is a host escalation
                 $hostName = $this->getHostNameById($escalation['host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $newEscalation->setHost($host->getId());
             } else {
                 if (!empty($escalation['service_template_id'])) {
                     // This is a service template escalation
                     $templateName = $this->getServiceTemplateNameById($escalation['service_template_id']);
                     $template = NagiosServiceTemplatePeer::getByName($templateName);
                     if (!$template) {
                         $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service template with  name matching: " . $templateName);
                         return true;
                     }
                     $newEscalation->setServiceTemplate($template->getId());
                 } else {
                     if (!empty($escalation['host_template_id'])) {
                         // This is for a host template escalation
                         $templateName = $this->getHostTemplateNameById($escalation['host_template_id']);
                         $template = NagiosHostTemplatePeer::getByName($templateName);
                         if (!$template) {
                             $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host template with  name matching: " . $templateName);
                             return true;
                         }
                         $newEscalation->setHostTemplate($template->getId());
                     }
                 }
             }
         }
         foreach ($escalation as $key => $val) {
             unset($name);
             if ($key == "escalation_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id") {
                 continue;
             }
             if ($key == "escalation_description") {
                 $key = "description";
             }
             if ($key == "escalation_period") {
                 $escalationName = $this->getTimeperiodNameById($id);
                 if ($escalationName) {
                     $newEscalation->setEscalationPeriodByName($escalationName);
                 }
                 continue;
             }
             try {
                 $name = NagiosEscalationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Escalation Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newEscalation->{$method}($val);
             }
         }
         $newEscalation->save();
         // Handle escalation contact groups.
         foreach ($this->dbConn->query("SELECT * FROM nagios_escalation_contactgroups WHERE escalation_id = " . $escalation['escalation_id'], PDO::FETCH_ASSOC) as $contactgroup) {
             $contactgroupName = $this->getContactGroupNameById($contactgroup['contactgroup_id']);
             if ($contactgroupName) {
                 $lilacContactGroup = NagiosContactGroupPeer::getByName($contactgroupName);
                 if ($lilacContactGroup) {
                     $newContactGroup = new NagiosEscalationContactgroup();
                     $newContactGroup->setEscalation($newEscalation->getId());
                     $newContactGroup->setContactgroup($lilacContactGroup->getId());
                     $newContactGroup->save();
                 }
             }
         }
     }
     $job->addNotice("FruityEscalationImporter finished importing Escalation Configuration.");
 }
コード例 #7
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityHostTemplateImporter beginning to import Host Template Configuration.");
     // Host templates
     $queuedHostTemplates = array();
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_templates", PDO::FETCH_ASSOC) as $hostTemplate) {
         if (!$this->importHostTemplate($hostTemplate)) {
             $queuedHostTemplates[] = $hostTemplate;
         }
     }
     while (count($queuedHostTemplates)) {
         for ($counter = 0; $counter < count($queuedHostTemplates); $counter++) {
             if ($this->importHostTemplate($queuedHostTemplates[$counter])) {
                 unset($queuedHostTemplates[$counter]);
             }
         }
     }
     // Host Template Check Command Parameters
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts_check_command_parameters WHERE host_template_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($commandParameterInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Check Command Parameter Importer: Could not find host template with id " . $commandParameterInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Check Command Parameter Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         $newParameter = new NagiosHostCheckCommandParameter();
         $newParameter->setTemplate($hostTemplate->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Host Template Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_template_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($membershipInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find host template with id " . $membershipInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosHostContactGroup();
         $membership->setHostTemplate($hostTemplate->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Host Template Extended Information
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_template_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($extInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Extended Info Importer: Could not find host template with id " . $extInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Extended Info Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $hostTemplate->setNotes($extInfo['notes']);
         $hostTemplate->setNotesUrl($extInfo['notes_url']);
         $hostTemplate->setActionUrl($extInfo['action_url']);
         $hostTemplate->setIconImage($extInfo['icon_image']);
         $hostTemplate->setIconImageAlt($extInfo['icon_image_alt']);
         $hostTemplate->setVrmlImage($extInfo['vrml_image']);
         $hostTemplate->setStatusmapImage($extInfo['statusmap_image']);
         $hostTemplate->setTwoDCoords($extInfo['two_d_coords']);
         $hostTemplate->setThreeDCoords($extInfo['three_d_coords']);
         $hostTemplate->save();
     }
     // Host group template memberships
     foreach ($this->dbConn->query("SELECT * FROM nagios_hostgroup_template_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($membershipInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host template with id " . $membershipInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $hostGroupName = $this->getHostGroupNameById($membershipInfo['hostgroup_id']);
         if (!$hostGroupName) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host group with id: " . $membershipInfo['hostgroup_id']);
             continue;
         }
         $hostGroup = NagiosHostgroupPeer::getByName($hostGroupName);
         if (!$hostGroup) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host group with name: " . $hostGroupName);
             continue;
         }
         $membership = new NagiosHostgroupMembership();
         $membership->setHostTemplate($hostTemplate->getId());
         $membership->setNagiosHostgroup($hostGroup);
         $membership->save();
     }
     $job->addNotice("FruityHostTemplateImporter finished importing Host Template Configuration.");
     $job->addNotice("FruityHostTemplateImporter: Finished importing a total of " . $this->totalImported . " host templates.");
 }