public function getByName($name) { $c = new Criteria(); $c->add(NagiosContactGroupPeer::NAME, $name); $c->setIgnoreCase(true); $contactgroup = NagiosContactGroupPeer::doSelectOne($c); if (!$contactgroup) { return false; } return $contactgroup; }
public function export() { // Grab our export job $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("NagiosContactGroupExporter attempting to export contact configuration."); $fp = $this->getOutputFile(); fputs($fp, "# Written by NagiosContactGroupExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n"); $contactgroups = NagiosContactGroupPeer::doSelect(new Criteria()); foreach ($contactgroups as $contactgroup) { fputs($fp, "define contactgroup {\n"); $finalArray = array(); $values = $contactgroup->toArray(BasePeer::TYPE_FIELDNAME); foreach ($values as $key => $value) { if ($key == 'id') { continue; } if ($key == 'name') { $key = 'contactgroup_name'; } if ($value === null) { continue; } if ($value === false) { $value = '0'; } $finalArray[$key] = $value; } foreach ($finalArray as $key => $val) { fputs($fp, "\t" . $key . "\t" . $val . "\n"); } // Members $memberships = $contactgroup->getNagiosContactGroupMembers(); if (count($memberships)) { fputs($fp, "\tmembers\t"); $first = true; foreach ($memberships as $membership) { if (!$first) { fputs($fp, ","); } else { $first = false; } fputs($fp, $membership->getNagiosContact()->getName()); } fputs($fp, "\n"); } fputs($fp, "}\n"); fputs($fp, "\n"); } $job->addNotice("NagiosContactGroupExporter complete."); return true; }
public function joinNagiosContactGroupByName($name) { $c = new Criteria(); $c->add(NagiosContactGroupPeer::NAME, $name); $group = NagiosContactGroupPeer::doSelectOne($c); if (!empty($group)) { $membership = new NagiosContactGroupMember(); $membership->setNagiosContact($this); $membership->setNagiosContactGroup($group); $membership->save(); return true; } return false; }
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."); }
$membership->save(); $success = "New Service Template Contact Link added."; } else { $error = "That contact is not found."; } } } else { if ($_POST['request'] == 'add_contactgroup_command') { $c = new Criteria(); $c->add(NagiosServiceContactGroupMemberPeer::SERVICE, $_GET['id']); $c->add(NagiosServiceContactGroupMemberPeer::CONTACT_GROUP, $_POST['contactgroup_id']); $membership = NagiosServiceContactGroupMemberPeer::doSelectOne($c); if ($membership) { $error = "That contact group already exists in that list!"; } else { $tempGroup = NagiosContactGroupPeer::retrieveByPk($_POST['contactgroup_id']); if ($tempGroup) { $membership = new NagiosServiceContactGroupMember(); $membership->setService($_GET['id']); $membership->setNagiosContactGroup($tempGroup); $membership->save(); $success = "New Service Contact Group Link added."; } } } else { if ($_POST['request'] == 'add_servicegroup_command') { $c = new Criteria(); $c->add(NagiosServiceGroupMemberPeer::SERVICE, $service->getId()); $c->add(NagiosServiceGroupMemberPeer::SERVICE_GROUP, $_POST['servicegroup_id']); $tempMembership = NagiosServiceGroupMemberPeer::doSelectOne($c); if ($tempMembership) {
public function valid() { $values = $this->getSegment()->getValues(); $job = $this->getEngine()->getJob(); if (isset($values['use'])) { // We need to use a template $job->addNotice("This Host uses a template: " . $values['use'][0]['value']); $template = NagiosHostTemplatePeer::getByName($values['use'][0]['value']); if (empty($template)) { if (!isset($values['name'][0]['value'])) { $job->addNotice("That template is not found yet. Setting this host (" . $values['host_name'][0]['value'] . ") as queued."); } else { $job->addNotice("That template is not found yet. Setting this host template (" . $values['name'][0]['value'] . ") as queued."); } return false; } } // Check time period existence if (isset($values['check_period'])) { $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $values['check_period'][0]['value']); $timePeriod = NagiosTimeperiodPeer::doSelectOne($c); if (empty($timePeriod)) { $job->addNotice("The time period specified by " . $values['check_period'][0]['value'] . " was not found."); return false; } $timePeriod->clearAllReferences(true); } if (isset($values['notification_period'])) { $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $values['notification_period'][0]['value']); $timePeriod = NagiosTimeperiodPeer::doSelectOne($c); if (empty($timePeriod)) { $job->addNotice("The time period specified by " . $values['notification_period'][0]['value'] . " was not found."); return false; } $timePeriod->clearAllReferences(true); } // Check command existence if (isset($values['check_command'])) { $params = explode("!", $values['check_command'][0]['value']); $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $params[0]); $command = NagiosCommandPeer::doSelectOne($c); if (empty($command)) { $job->addNotice("The command specified by " . $params[0] . " was not found."); return false; } $command->clearAllReferences(true); } if (isset($values['event_handler'])) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $values['event_handler'][0]['value']); $command = NagiosCommandPeer::doSelectOne($c); if (empty($command)) { $job->addNotice("The command specified by " . $values['event_handler'][0]['value'] . " was not found."); return false; } $command->clearAllReferences(true); } // Check contact groups if (isset($values['contact_groups'])) { foreach ($values['contact_groups'] as $contactGroupValues) { $c = new Criteria(); $c->add(NagiosContactGroupPeer::NAME, $contactGroupValues['value']); $contactgroup = NagiosContactGroupPeer::doSelectOne($c); if (empty($contactgroup)) { $job->addNotice("The contact group specified by " . $contactGroupValues['value'] . " was not found."); return false; } $contactgroup->clearAllReferences(); } } if (isset($values['contacts'])) { foreach ($values['contacts'] as $contactValues) { $c = new Criteria(); $c->add(NagiosContactPeer::NAME, $contactValues['value']); $contactgroup = NagiosContactPeer::doSelectOne($c); if (empty($contactgroup)) { $job->addNotice("The contact specified by " . $contactValues['value'] . " was not found."); return false; } $contactgroup->clearAllReferences(); } } // Check host groups if (isset($values['hostgroups'])) { foreach ($values['hostgroups'] as $hostGroupValues) { $c = new Criteria(); $c->add(NagiosHostgroupPeer::NAME, $hostGroupValues['value']); $hostgroup = NagiosHostgroupPeer::doSelectOne($c); if (empty($hostgroup)) { $job->addNotice("The host group specified by " . $hostGroupValues['value'] . " was not found."); return false; } $hostgroup->clearAllReferences(); } } // Check parents if (isset($values['parents'])) { foreach ($values['parents'] as $parentValues) { $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $parentValues['value']); $host = NagiosHostPeer::doSelectOne($c); if (empty($host)) { $job->addNotice("The host specified by " . $parentValues['value'] . " was not found."); return false; } $host->clearAllReferences(); } } return true; }
public function init() { $job = $this->getJob(); $job->addNotice("NagiosImportEngine Starting..."); $config = $this->getConfig(); // Attempt to try and open each config file $job->addNotice("Attempting to open " . $config->GetVar('config_file')); if (!file_exists($config->getVar('config_file')) || !@fopen($config->getVar('config_file'), "r")) { $job->addError("Failed to open " . $config->getVar('config_file')); return false; } $job->addNotice("Attempting to open " . $config->GetVar('cgi_file')); if (!file_exists($config->getVar('cgi_file')) || !@fopen($config->getVar('cgi_file'), "r")) { $job->addError("Failed to open " . $config->getVar('cgi_file')); return false; } $job->addNotice("Attempting to open " . $config->GetVar('resources_file')); if (!file_exists($config->getVar('resources_file')) || !@fopen($config->getVar('resources_file'), "r")) { $job->addError("Failed to open " . $config->getVar('resources_file')); return false; } $job->addNotice("Config passed sanity check for Nagios import. Finished initializing."); if ($config->getVar('delete_existing')) { $job->addNotice("Removing existing Nagios objects."); NagiosTimeperiodPeer::doDeleteAll(); NagiosCommandPeer::doDeleteAll(); NagiosContactPeer::doDeleteAll(); NagiosContactGroupPeer::doDeleteAll(); NagiosHostTemplatePeer::doDeleteAll(); NagiosHostPeer::doDeleteAll(); NagiosHostgroupPeer::doDeleteAll(); NagiosServiceGroupPeer::doDeleteAll(); NagiosServiceTemplatePeer::doDeleteAll(); NagiosServicePeer::doDeleteAll(); NagiosDependencyPeer::doDeleteAll(); NagiosDependencyTargetPeer::doDeleteAll(); NagiosEscalationPeer::doDeleteAll(); } return true; }
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."); }
$membership->save(); $success = "New Host Contact Link added."; } else { $error = "That contact is not found."; } } } else { if ($_POST['request'] == 'add_contactgroup_command') { $c = new Criteria(); $c->add(NagiosHostContactgroupPeer::HOST, $_GET['id']); $c->add(NagiosHostContactgroupPeer::CONTACTGROUP, $_POST['host_manage']['contactgroup_add']['contactgroup_id']); $membership = NagiosHostContactgroupPeer::doSelectOne($c); if ($membership) { $error = "That contact group already exists in that list!"; } else { $tempGroup = NagiosContactGroupPeer::retrieveByPk($_POST['host_manage']['contactgroup_add']['contactgroup_id']); if ($tempGroup) { $membership = new NagiosHostContactgroup(); $membership->setHost($_GET['id']); $membership->setNagiosContactGroup($tempGroup); $membership->save(); $success = "New Host Contact Group Link added."; } } } else { if ($_POST['request'] == 'parent_add') { // Wants to add a parent $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $_POST['parenthost']); $c->setIgnoreCase(true); $parentHost = NagiosHostPeer::doSelectOne($c);
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() { $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."); }
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."); }
public function import() { $job = $this->getJob(); $job->addNotice("FruityImportEngine beginning import..."); $config = $this->getConfig(); $job->addNotice("Removing existing Nagios objects."); NagiosTimeperiodPeer::doDeleteAll(); NagiosCommandPeer::doDeleteAll(); NagiosContactPeer::doDeleteAll(); NagiosContactGroupPeer::doDeleteAll(); NagiosHostTemplatePeer::doDeleteAll(); NagiosHostPeer::doDeleteAll(); NagiosHostgroupPeer::doDeleteAll(); NagiosServiceGroupPeer::doDeleteAll(); NagiosServiceTemplatePeer::doDeleteAll(); NagiosServicePeer::doDeleteAll(); NagiosDependencyPeer::doDeleteAll(); NagiosDependencyTargetPeer::doDeleteAll(); NagiosEscalationPeer::doDeleteAll(); NagiosBrokerModulePeer::doDeleteAll(); NagiosMainConfigurationPeer::doDeleteAll(); NagiosCgiConfigurationPeer::doDeleteAll(); $importer = new FruityResourceImporter($this, $this->dbConn); $importer->import(); $importer = new FruityCgiImporter($this, $this->dbConn); $importer->import(); $importer = new FruityCommandImporter($this, $this->dbConn); $importer->import(); $importer = new FruityTimeperiodImporter($this, $this->dbConn); $importer->import(); $importer = new FruityContactImporter($this, $this->dbConn); $importer->import(); $importer = new FruityServiceGroupImporter($this, $this->dbConn); $importer->import(); $importer = new FruityServiceTemplateImporter($this, $this->dbConn); $importer->import(); $importer = new FruityHostTemplateImporter($this, $this->dbConn); $importer->import(); $importer = new FruityHostGroupImporter($this, $this->dbConn); $importer->import(); $importer = new FruityHostImporter($this, $this->dbConn); $importer->import(); $importer = new FruityServiceImporter($this, $this->dbConn); $importer->import(); $importer = new FruityDependencyImporter($this, $this->dbConn); $importer->import(); $importer = new FruityEscalationImporter($this, $this->dbConn); $importer->import(); $importer = new FruityMainImporter($this, $this->dbConn); $importer->import(); $job->addNotice("FruityImportEngine completed job."); return true; }
private function search_text($text) { // LOTS of places to check... // Hosts: name, alias, addresses $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(nagiosHostPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c3 = $c->getNewCriterion(nagiosHostPeer::ADDRESS, "%" . $text . "%", Criteria::LIKE); $c2->addOr($c3); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosHostPeer::NAME); $matchedHosts = NagiosHostPeer::doSelect($c); if (count($matchedHosts)) { foreach ($matchedHosts as $host) { $this->searchResults['hosts'][$host->getId()] = $host; $this->searchCount++; } } // Hostgroups: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostgroupPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(nagiosHostgroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosHostgroupPeer::NAME); $matchedHostgroups = NagiosHostgroupPeer::doSelect($c); if (count($matchedHostgroups)) { foreach ($matchedHostgroups as $hostgroup) { $this->searchResults['hostgroups'][$hostgroup->getId()] = $hostgroup; $this->searchCount++; } } // Host Templates: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostTemplatePeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosHostTemplatePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosHostTemplatePeer::NAME); $matchedTemplates = NagiosHostTemplatePeer::doSelect($c); if (count($matchedTemplates)) { foreach ($matchedTemplates as $template) { $this->searchResults['host_templates'][$template->getId()] = $template; $this->searchCount++; } } // Services: description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosServicePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosServicePeer::DESCRIPTION); $matchedServices = NagiosServicePeer::doSelect($c); if (count($matchedServices)) { foreach ($matchedServices as $service) { $this->searchResults['services'][$service->getId()] = $service; $this->searchCount++; } } // Servicegroups: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosServiceGroupPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosServiceGroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosServiceGroupPeer::NAME); $matchedServicegroups = NagiosServiceGroupPeer::doSelect($c); if (count($matchedServicegroups)) { foreach ($matchedServicegroups as $servicegroup) { $this->searchResults['servicegroups'][$servicegroup->getId()] = $servicegroup; $this->searchCount++; } } // Service Templates: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosServiceTemplatePeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosServiceTemplatePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosServiceTemplatePeer::NAME); $matchedTemplates = NagiosServiceTemplatePeer::doSelect($c); if (count($matchedTemplates)) { foreach ($matchedTemplates as $template) { $this->searchResults['service_templates'][$template->getId()] = $template; $this->searchCount++; } } // Service Templates: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosContactPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosContactPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c3 = $c->getNewCriterion(NagiosContactPeer::EMAIL, "%" . $text . "%", Criteria::LIKE); $c2->addOr($c3); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosContactPeer::NAME); $matchedContacts = NagiosContactPeer::doSelect($c); if (count($matchedContacts)) { foreach ($matchedContacts as $contact) { $this->searchResults['contacts'][$contact->getId()] = $contact; $this->searchCount++; } } // ContactGroups: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosContactGroupPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosContactGroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosContactGroupPeer::NAME); $matchedContactgroups = NagiosContactGroupPeer::doSelect($c); if (count($matchedContactgroups)) { foreach ($matchedContactgroups as $contactgroup) { $this->searchResults['contactgroups'][$contactgroup->getId()] = $contactgroup; $this->searchCount++; } } // Timeperiod: name, alias $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosTimeperiodPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosTimeperiodPeer::ALIAS, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosTimeperiodPeer::NAME); $matchedPeriods = NagiosTimeperiodPeer::doSelect($c); if (count($matchedPeriods)) { foreach ($matchedPeriods as $period) { $this->searchResults['timeperiods'][$period->getId()] = $period; $this->searchCount++; } } // Command: name, description $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosCommandPeer::NAME, "%" . $text . "%", Criteria::LIKE); $c2 = $c->getNewCriterion(NagiosCommandPeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE); $c1->addOr($c2); $c->add($c1); $c->setIgnoreCase(true); $c->addAscendingOrderByColumn(NagiosCommandPeer::NAME); $matchedCommands = NagiosCommandPeer::doSelect($c); if (count($matchedCommands)) { foreach ($matchedCommands as $command) { $this->searchResults['commands'][$command->getId()] = $command; $this->searchCount++; } } }
function addContactGroupByName($name) { $c = new Criteria(); $c->add(NagiosContactGroupPeer::NAME, $name); $c->setIgnoreCase(true); $contactgroup = NagiosContactGroupPeer::doSelectOne($c); if (!$contactgroup) { return false; } // Okay, contactgroup is valid, check for relationship $id = $this->getId(); if (!empty($id)) { $c = new Criteria(); $c->add(NagiosHostContactgroupPeer::HOST_TEMPLATE, $this->getId()); $c->add(NagiosHostContactgroupPeer::CONTACTGROUP, $contactgroup->getId()); $relationship = NagiosHostContactgroupPeer::doSelectOne($c); if ($relationship) { return false; } } $relationship = new NagiosHostContactgroup(); $relationship->setNagiosHostTemplate($this); $relationship->setNagiosContactGroup($contactgroup); $relationship->save(); return true; }
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."); }
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; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(NagiosContactGroupPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(NagiosContactGroupPeer::DATABASE_NAME); $criteria->add(NagiosContactGroupPeer::ID, $pks, Criteria::IN); $objs = NagiosContactGroupPeer::doSelect($criteria, $con); } return $objs; }
/** * Get the associated NagiosContactGroup object * * @param PropelPDO Optional Connection object. * @return NagiosContactGroup The associated NagiosContactGroup object. * @throws PropelException */ public function getNagiosContactGroup(PropelPDO $con = null) { if ($this->aNagiosContactGroup === null && $this->contactgroup !== null) { $c = new Criteria(NagiosContactGroupPeer::DATABASE_NAME); $c->add(NagiosContactGroupPeer::ID, $this->contactgroup); $this->aNagiosContactGroup = NagiosContactGroupPeer::doSelectOne($c, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aNagiosContactGroup->addNagiosHostContactgroups($this); */ } return $this->aNagiosContactGroup; }
<td><?php echo NagiosTimeperiodPeer::doCount(new Criteria()); ?> </td> </tr> <tr> <td><strong>Total Nagios Contacts:</strong></td> <td><?php echo NagiosContactPeer::doCount(new Criteria()); ?> </td> </tr> <tr class="odd"> <td><strong>Total Nagios Contact Groups:</strong></td> <td><?php echo NagiosContactGroupPeer::doCount(new Criteria()); ?> </td> </tr> <tr> <td><strong>Total Nagios Host Groups:</strong></td> <td><?php echo NagiosHostgroupPeer::doCount(new Criteria()); ?> </td> </tr> <tr class="odd"> <td><strong>Total Nagios Service Groups:</strong></td> <td><?php echo NagiosServiceGroupPeer::doCount(new Criteria()); ?>
// Field Error Checking if ($tempData['contact_name'] == '' || $tempData['alias'] == '') { $addError = 1; $error = "Fields shown are required and cannot be left blank."; } else { // Check for pre-existing contact with same name if ($lilac->contact_exists($tempData['contact_name'])) { $error = "A contact with that name already exists!"; } else { $tempContactGroup = $tempData['contact_group']; unset($tempData['contact_group']); // All is well for error checking, add the contact into the db. $contact = $lilac->add_contact($tempData); $success = "Contact added"; if ($tempContactGroup && $tempContactGroup != 0) { $contactGroup = NagiosContactGroupPeer::retrieveByPK($tempContactGroup); if ($contactGroup && $contact) { $contactGroupMember = new NagiosContactGroupMember(); $contactGroupMember->setContact($contact->getId()); $contactGroupMember->setContactgroup($contactGroup->getId()); $contactGroupMember->save(); } } unset($_GET['contact_add']); } } } else { if ($_POST['request'] == 'modify_contact') { // Error check! if (count($tempData)) { foreach ($tempData as $tempVariable) {
/** * Selects a collection of NagiosServiceContactGroupMember objects pre-filled with all related objects except NagiosServiceTemplate. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of NagiosServiceContactGroupMember objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptNagiosServiceTemplate(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden // $c->getDbName() will return the same object if not set to another value // so == check is okay and faster if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } NagiosServiceContactGroupMemberPeer::addSelectColumns($c); $startcol2 = NagiosServiceContactGroupMemberPeer::NUM_COLUMNS - NagiosServiceContactGroupMemberPeer::NUM_LAZY_LOAD_COLUMNS; NagiosServicePeer::addSelectColumns($c); $startcol3 = $startcol2 + (NagiosServicePeer::NUM_COLUMNS - NagiosServicePeer::NUM_LAZY_LOAD_COLUMNS); NagiosContactGroupPeer::addSelectColumns($c); $startcol4 = $startcol3 + (NagiosContactGroupPeer::NUM_COLUMNS - NagiosContactGroupPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(NagiosServiceContactGroupMemberPeer::SERVICE), array(NagiosServicePeer::ID), $join_behavior); $c->addJoin(array(NagiosServiceContactGroupMemberPeer::CONTACT_GROUP), array(NagiosContactGroupPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = NagiosServiceContactGroupMemberPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = NagiosServiceContactGroupMemberPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = NagiosServiceContactGroupMemberPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); NagiosServiceContactGroupMemberPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined NagiosService rows $key2 = NagiosServicePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = NagiosServicePeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = NagiosServicePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); NagiosServicePeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (NagiosServiceContactGroupMember) to the collection in $obj2 (NagiosService) $obj2->addNagiosServiceContactGroupMember($obj1); } // if joined row is not null // Add objects for joined NagiosContactGroup rows $key3 = NagiosContactGroupPeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = NagiosContactGroupPeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = NagiosContactGroupPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); NagiosContactGroupPeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (NagiosServiceContactGroupMember) to the collection in $obj3 (NagiosContactGroup) $obj3->addNagiosServiceContactGroupMember($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
public function valid() { $values = $this->getSegment()->getValues(); $job = $this->getEngine()->getJob(); if (isset($values['use'])) { // We need to use a template $job->addNotice("This Contact uses a template: " . $values['use'][0]['value']); $template = NagiosContactImporter::getTemplateByName($values['use'][0]['value']); if (empty($template)) { $job->addNotice("That template is not found yet. Setting this contact as queued."); return false; } } // Check time period existence if (isset($values['host_notification_period'])) { $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $values['host_notification_period'][0]['value']); $timePeriod = NagiosTimeperiodPeer::doSelectOne($c); if (empty($timePeriod)) { $job->addNotice("The time period specified by " . $values['host_notification_period'][0]['value'] . " was not found. Setting this contact as queued."); return false; } $timePeriod->clearAllReferences(true); } if (isset($values['service_notification_period'])) { $c = new Criteria(); $c->add(NagiosTimeperiodPeer::NAME, $values['service_notification_period'][0]['value']); $timePeriod = NagiosTimeperiodPeer::doSelectOne($c); if (empty($timePeriod)) { $job->addNotice("The time period specified by " . $values['service_notification_period'][0]['value'] . " was not found. Setting this contact as queued."); return false; } $timePeriod->clearAllReferences(true); } // Check command existence if (isset($values['service_notification_commands'])) { foreach ($values['service_notification_commands'] as $commandValues) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $commandValues['value']); $command = NagiosCommandPeer::doSelectOne($c); if (empty($command)) { $job->addNotice("The command specified by " . $commandValues['value'] . " was not found. Setting this contact as queued."); return false; } $command->clearAllReferences(true); } } if (isset($values['host_notification_commands'])) { foreach ($values['host_notification_commands'] as $commandValues) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $commandValues['value']); $command = NagiosCommandPeer::doSelectOne($c); if (empty($command)) { $job->addNotice("The command specified by " . $commandValues['value'] . " was not found. Setting this contact as queued."); return false; } $command->clearAllReferences(true); } } // Check contact groups if (isset($values['contactgroups'])) { foreach ($values['contactgroups'] as $contactGroupValues) { $c = new Criteria(); $c->add(NagiosContactGroupPeer::NAME, $contactGroupValues['value']); $contactgroup = NagiosContactGroupPeer::doSelectOne($c); if (empty($contactgroup)) { $job->addNotice("The contact group specified by " . $contactGroupValues['value'] . " was not found. Setting this contact as queued."); return false; } $contactgroup->clearAllReferences(true); } } return true; }