public function import() { $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("FruityCommandImporter beginning to import Command Configuration."); foreach ($this->dbConn->query("SELECT * FROM nagios_commands", PDO::FETCH_ASSOC) as $command) { $newCommand = new NagiosCommand(); foreach ($command as $key => $val) { unset($name); if ($key == "command_id" || $key == "network_id") { continue; } if ($key == "command_name") { $key = "name"; } if ($key == "command_line") { $key = "line"; } if ($key == "command_desc") { $key = "description"; } try { $name = NagiosCommandPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Command Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newCommand->{$method}($val); } } // Check to see if the command already exists if (NagiosCommandPeer::getByName($newCommand->getName())) { $job->addNotice("Fruity Command Importer: The command " . $newCommand->getName() . " already exists. Aborting it's import."); } else { $newCommand->save(); } } $job->addNotice("FruityCommandImporter finished importing Command Configuration."); }
private function importHost($hostData) { $job = $this->getEngine()->getJob(); // check to see if we have a host by that name if (NagiosHostPeer::getByName($hostData['host_name'])) { $job->addNotice("Fruity Host Importer: Host " . $hostData['host_name'] . " already exists. Aborting it's import."); return true; } $newHost = new NagiosHost(); $newHost->setName($hostData['host_name']); // Check to see if we need the template if (!empty($hostData['use_template_id'])) { $name = $this->getHostTemplateNameById($hostData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Host Importer: Could not find template with id: " . $hostData['use_template_id'] . ". Aborting it's import."); return false; } else { // Okay, we got the name, does this template exist? $template = NagiosHostTemplatePeer::getByName($name); if (!$template) { $job->addNotice("Fruity Host Importer: Could not find a template in the system with the name of: " . $name . ". Aborting it's import."); return false; } else { // Create a new inheritance relationship $inheritance = new NagiosHostTemplateInheritance(); $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosHost($newHost); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Host Importer: Cannot add inheritance from " . $template->getName() . " to " . $newHost->getName()); } } } } // Okay, start 'er up! foreach ($hostData as $key => $val) { unset($name); if ($key == "host_id" || $key == "use_template_id" || $key == "host_name") { continue; } if ($key == "parents") { // we're gonna do parents after this continue; } if ($key == "notification_options_down") { $key = "notification_on_down"; } if ($key == "notification_options_unreachable") { $key = "notification_on_unreachable"; } if ($key == "notification_options_recovery") { $key = "notification_on_recovery"; } if ($key == "notification_options_flapping") { $key = "notification_on_flapping"; } if ($key == "stalking_options_up") { $key = "stalking_on_up"; } if ($key == "stalking_options_down") { $key = "stalking_on_down"; } if ($key == "stalking_options_unreachable") { $key = "stalking_on_unreachable"; } if ($key == "max_check_attempts") { $key = "maximum_check_attempts"; } if ($key == "retry_check_interval") { $key = "retry_interval"; } if ($key == "check_command") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newHost->setCheckCommand($command->getId()); } } continue; } if ($key == "check_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newHost->setCheckPeriod($timeperiod->getId()); } } continue; } if ($key == "event_handler") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newHost->setEventHandler($command->getId()); } } continue; } if ($key == "notification_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newHost->setNotificationPeriod($timeperiod->getId()); } } continue; } try { $name = NagiosHostPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Host Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newHost->{$method}($val); } } $newHost->save(); $job->addNotice("FruityHostImporter: Imported new host: " . $newHost->getName()); $this->totalImported++; return true; }
private function importService($serviceData) { $job = $this->getEngine()->getJob(); $newService = new NagiosService(); // Check to see if host or host template exists first if (!empty($serviceData['host_id'])) { $hostName = $this->getHostNameById($serviceData['host_id']); if (!$hostName) { $job->addNotice("Fruity Service Importer: Failed to find host with id: " . $serviceData['host_id']); return true; } $host = NagiosHostPeer::getByName($hostName); if (!$host) { $job->addNotice("Fruity Service Importer: Failed to find host with name: " . $hostName); return true; } $newService->setHost($host->getId()); } else { if (!empty($serviceData['host_template_id'])) { $hostTemplateName = $this->getHostTemplateNameById($serviceData['host_template_id']); if (!$hostTemplateName) { $job->addNotice("Fruity Service Importer: Failed to find host template with id: " . $serviceData['host_template_id']); return true; } $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName); if (!$hostTemplate) { $job->addNotice("Fruity Service Importer: Failed to find host template with name: " . $hostTemplateName); return true; } $newService->setHostTemplate($hostTemplate->getId()); } else { if (!empty($serviceData['hostgroup_id'])) { $hostgroupName = $this->getHostGroupNameById($serviceData['hostgroup_id']); if (!$hostgroupName) { $job->addNotice("Fruity Service Importer: Failed to find host group with id: " . $serviceData['host_template_id']); return true; } $hostgroup = NagiosHostGroupPeer::getByName($hostgroupName); if (!$hostgroup) { $job->addNotice("Fruity Service Importer: Failed to find host group with name: " . $hostGroupName); return true; } $newService->setHostgroup($hostgroup->getId()); } } } // Check to see if we need the template if (!empty($serviceData['use_template_id'])) { $name = $this->getServiceTemplateNameById($serviceData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Service Importer: Could not find template with id: " . $serviceData['use_template_id'] . ". Aborting it's import."); return false; } else { // Okay, we got the name, does this template exist? $template = NagiosServiceTemplatePeer::getByName($name); if (!$template) { return false; } else { // Create a new inheritance relationship $inheritance = new NagiosServiceTemplateInheritance(); $inheritance->setNagiosServiceTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosService($newService); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Service Template Importer: Cannot add inheritance from " . $template->getName() . " to " . $newService->getName()); } } } } // Okay, start 'er up! foreach ($serviceData as $key => $val) { unset($name); if ($key == "service_template_id" || $key == "use_template_id" || $key == "template_name" || $key == "host_id" || $key == "hostgroup_id" || $key == "host_template_id" || $key == "service_id") { continue; } if ($key == "service_description") { $key = "description"; } if ($key == "notification_options_warning") { $key = "notification_on_warning"; } if ($key == "notification_options_unknown") { $key = "notification_on_unknown"; } if ($key == "notification_options_critical") { $key = "notification_on_critical"; } if ($key == "notification_options_recovery") { $key = "notification_on_recovery"; } if ($key == "notification_options_flapping") { $key = "notification_on_flapping"; } if ($key == "stalking_options_warning") { $key = "stalking_on_warning"; } if ($key == "stalking_options_unknown") { $key = "stalking_on_unknown"; } if ($key == "stalking_options_critical") { $key = "stalking_on_critical"; } if ($key == "stalking_options_ok") { $key = "stalking_on_ok"; } if ($key == "max_check_attempts") { $key = "maximum_check_attempts"; } if ($key == "retry_check_interval") { $key = "retry_interval"; } if ($key == "check_command") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newService->setCheckCommand($command->getId()); } } continue; } if ($key == "check_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newService->setCheckPeriod($timeperiod->getId()); } } continue; } if ($key == "event_handler") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newService->setEventHandler($command->getId()); } } continue; } if ($key == "notification_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newService->setNotificationPeriod($timeperiod->getId()); } } continue; } try { $name = NagiosServiceTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Service Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newService->{$method}($val); } } $job->addNotice("Fruity Service Importer: Saved service: " . $newService->getDescription() . " on " . $newService->getOwnerDescription()); $newService->save(); $this->totalImported++; return true; }
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."); }
public function import() { global $lilac; $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("FruityMainImporter beginning to import Main Configuration."); $res = $this->dbConn->query("SELECT * FROM nagios_main"); // Fruity has just one record in the main, if we get it, import // it. $row = $res->fetch(PDO::FETCH_ASSOC); // Get our main obj. $mainConfig = $lilac->get_main_conf(); foreach ($row as $key => $val) { unset($name); if ($key == "id" || $key == "p1_file" || $key == "comment_file" || $key == "downtime_file" || $key == "aggregate_status_updates") { continue; } if ($key == "service_perfdata_template") { $key = "service_perfdata_file_template"; } if ($key == "host_perfdata_template") { $key = "host_perfdata_file_template"; } if ($key == "global_host_event_handler") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } if ($key == "global_service_event_handler") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } if ($key == "ocsp_command") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } if ($key == "ochp_command") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } if ($key == "host_perfdata_command") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } if ($key == "service_perfdata_command") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } if ($key == "host_perfdata_file_processing_command") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } if ($key == "service_perfdata_file_processing_command") { $commandName = $this->getCommandNameById($val); $command = NagiosCommandPeer::getByName($commandName); if ($command) { $val = $command->getId(); } else { $val = null; } } try { $name = NagiosMainConfigurationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Main Configuration: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $mainConfig->{$method}($val); } } $mainConfig->save(); // Save main configuration // Broker modules foreach ($this->dbConn->query("SELECT * FROM nagios_broker_modules", PDO::FETCH_ASSOC) as $brokerModule) { $newModule = new NagiosBrokerModule(); foreach ($brokerModule as $key => $val) { unset($name); if ($key == "module_id") { continue; } if ($key == "module_line") { $key = "line"; } try { $name = NagiosBrokerModulePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Broker Module: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newModule->{$method}($val); } } $newModule->save(); } $job->addNotice("FruityMainImporter finished importing Main Configuration."); }