public function valid() { $values = $this->getSegment()->getValues(); $job = $this->getEngine()->getJob(); // Check contact existence if (isset($values['members'])) { foreach ($values['members'] as $hostValues) { if ($hostValues['value'] == "*") { // Means every host continue; } $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $hostValues['value']); $host = NagiosHostPeer::doSelectOne($c); if (empty($host)) { $job->addNotice("The host specified by " . $hostValues['value'] . " was not found. Setting this host group as queued."); return false; } $host->clearAllReferences(true); } } if (isset($values['hostgroup_members'])) { foreach ($values['hostgroup_members'] as $hostGroupValues) { $c = new Criteria(); $c->add(NagiosHostgroupPeer::NAME, $hostGroupValues['value']); $host = NagiosHostgroupPeer::doSelectOne($c); if (empty($host)) { $job->addNotice("The host group specified by " . $hostValues['value'] . " was not found. Setting this host group as queued."); return false; } $host->clearAllReferences(true); } } return true; }
public function addMembersByHostgroup($name) { // First get hostgroup $hostgroup = NagiosHostgroupPeer::getByName($name); if (!$hostgroup) { return false; } // Get the members $memberships = $hostgroup->getNagiosHostgroupMemberships(); foreach ($memberships as $membership) { $host = $membership->getNagiosHost(); // Check to see if we already have this in our member list $id = $this->getId(); if (!empty($id)) { $c = new Criteria(); $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $this->getId()); $c->add(NagiosHostgroupMembershipPeer::HOST, $host->getId()); $relationship = NagiosHostgroupMembershipPeer::doSelectOne($c); if ($relationship) { continue; } } // Create new relationship $relationship = new NagiosHostgroupMembership(); $relationship->setNagiosHost($host); $relationship->setNagiosHostgroup($this); $relationship->save(); } return true; }
public function getByName($name) { $c = new Criteria(); $c->add(NagiosHostgroupPeer::NAME, $name); $c->setIgnoreCase(true); $hostgroup = NagiosHostgroupPeer::doSelectOne($c); if (!$hostgroup) { return false; } return $hostgroup; }
public static function getByHostgroupAndDescription($hostgroupname, $description) { // First get hostgroup $hostgroup = NagiosHostgroupPeer::getByName($hostgroupname); if (!$hostgroup) { return false; } $c = new Criteria(); $c->add(NagiosServicePeer::HOSTGROUP, $hostgroup->getId()); $c->add(NagiosServicePeer::DESCRIPTION, $description); $c->setIgnoreCase(true); $service = NagiosServicePeer::doSelectOne($c); if (!$service) { return false; } return $service; }
public function import() { $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("FruityHostGroupImporter beginning to import Host Group Configuration."); // Host groups foreach ($this->dbConn->query("SELECT * FROM nagios_hostgroups", PDO::FETCH_ASSOC) as $hostgroupInfo) { // Check to see if hostgroup exists $tempHostgroup = NagiosHostgroupPeer::getByName($hostgroupInfo['hostgroup_name']); if ($tempHostgroup) { $job->addNotice("Fruity Host Group Importer: Host group " . $hostgroupInfo['hostgroup_name'] . " already exists, skipping import."); continue; } // Let's create a hostgroup $newHostgroup = new NagiosHostgroup(); $newHostgroup->setName($hostgroupInfo['hostgroup_name']); $newHostgroup->setAlias($hostgroupInfo['alias']); $newHostgroup->save(); } $job->addNotice("FruityHostGroupImporter finished importing Host Group Configuration."); }
public function export() { // Grab our export job $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("NagiosHostGroupExporter attempting to export host group configuration."); $fp = $this->getOutputFile(); fputs($fp, "# Written by NagiosHostGroupExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n"); $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria()); foreach ($hostgroups as $hostgroup) { fputs($fp, "define hostgroup {\n"); $finalArray = array(); $values = $hostgroup->toArray(BasePeer::TYPE_FIELDNAME); foreach ($values as $key => $value) { if ($key == 'id') { continue; } if ($value === null) { continue; } if ($value === false) { $value = '0'; } if ($key == "name") { $key = "hostgroup_name"; } $finalArray[$key] = $value; } foreach ($finalArray as $key => $val) { fputs($fp, "\t" . $key . "\t" . $val . "\n"); } fputs($fp, "}\n"); fputs($fp, "\n"); } $job->addNotice("NagiosHostGroupExporter complete."); return true; }
function addHostgroupByName($name) { $c = new Criteria(); $c->add(NagiosHostgroupPeer::NAME, $name); $c->setIgnoreCase(true); $hostgroup = NagiosHostgroupPeer::doSelectOne($c); if (!$hostgroup) { return false; } // Okay, hostgroup is valid, check for relationship $id = $this->getId(); if (!empty($id)) { $c = new Criteria(); $c->add(NagiosHostgroupMembershipPeer::HOST_TEMPLATE, $this->getId()); $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $hostgroup->getId()); $relationship = NagiosHostgroupMembershipPeer::doSelectOne($c); if ($relationship) { return false; } } $relationship = new NagiosHostgroupMembership(); $relationship->setNagiosHostTemplate($this); $relationship->setNagiosHostgroup($hostgroup); $relationship->save(); return true; }
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; }
$type = "servicetemplate"; $title = "Service Template"; } else { if (isset($_GET['service_id'])) { $tempSource = NagiosServicePeer::retrieveByPK($_GET['service_id']); $fieldName = "service_id"; $link = "service.php"; if (!$tempSource) { header("Location: welcome.php"); } $type = "service"; $title = ""; // This can be ignored later on. } else { if (isset($_GET['hostgroup_id'])) { $tempSource = NagiosHostgroupPeer::retrieveByPK($_GET['hostgroup_id']); $fieldName = "hostgroup_id"; $link = "hostgroups.php"; if (!$tempSource) { header("Location: welcome.php"); } $type = "hostgroup"; $title = "Hostgroup"; } } } } } if (isset($_POST['request'])) { if ($_POST['request'] == "add_dependency") { // Error checking
} else { // Add the target. $target = new NagiosDependencyTarget(); $target->setNagiosDependency($dependency); $target->setNagiosHost($tempHost); $target->save(); $success = "Created target."; } } } else { if ($_POST['typeselect'] == "hostgroup") { // First find the hostgroup $c = new Criteria(); $c->add(NagiosHostgroupPeer::NAME, $_POST['name']); $c->setIgnoreCase(true); $tempHostgroup = NagiosHostgroupPeer::doSelectOne($c); if (!$tempHostgroup) { $error = "The hostgroup specified by name " . $_POST['name'] . " was not found."; } else { // Check for target existence $c = new Criteria(); $c->add(NagiosDependencyTargetPeer::DEPENDENCY, $dependency->getId()); $c->add(NagiosDependencyTargetPeer::TARGET_HOSTGROUP, $tempHostgroup->getId()); $target = NagiosDependencyTargetPeer::doSelectOne($c); if ($target) { $error = "That target already exists."; } else { // Add the target. $target = new NagiosDependencyTarget(); $target->setNagiosDependency($dependency); $target->setNagiosHostgroup($tempHostgroup);
/** * Selects a collection of NagiosEscalation objects pre-filled with all related objects except NagiosTimeperiod. * * @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 NagiosEscalation objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptNagiosTimeperiod(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); } NagiosEscalationPeer::addSelectColumns($c); $startcol2 = NagiosEscalationPeer::NUM_COLUMNS - NagiosEscalationPeer::NUM_LAZY_LOAD_COLUMNS; NagiosHostTemplatePeer::addSelectColumns($c); $startcol3 = $startcol2 + (NagiosHostTemplatePeer::NUM_COLUMNS - NagiosHostTemplatePeer::NUM_LAZY_LOAD_COLUMNS); NagiosHostPeer::addSelectColumns($c); $startcol4 = $startcol3 + (NagiosHostPeer::NUM_COLUMNS - NagiosHostPeer::NUM_LAZY_LOAD_COLUMNS); NagiosServiceTemplatePeer::addSelectColumns($c); $startcol5 = $startcol4 + (NagiosServiceTemplatePeer::NUM_COLUMNS - NagiosServiceTemplatePeer::NUM_LAZY_LOAD_COLUMNS); NagiosServicePeer::addSelectColumns($c); $startcol6 = $startcol5 + (NagiosServicePeer::NUM_COLUMNS - NagiosServicePeer::NUM_LAZY_LOAD_COLUMNS); NagiosHostgroupPeer::addSelectColumns($c); $startcol7 = $startcol6 + (NagiosHostgroupPeer::NUM_COLUMNS - NagiosHostgroupPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(NagiosEscalationPeer::HOST_TEMPLATE), array(NagiosHostTemplatePeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::HOST), array(NagiosHostPeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::SERVICE_TEMPLATE), array(NagiosServiceTemplatePeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::SERVICE), array(NagiosServicePeer::ID), $join_behavior); $c->addJoin(array(NagiosEscalationPeer::HOSTGROUP), array(NagiosHostgroupPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = NagiosEscalationPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = NagiosEscalationPeer::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 = NagiosEscalationPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); NagiosEscalationPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined NagiosHostTemplate rows $key2 = NagiosHostTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = NagiosHostTemplatePeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = NagiosHostTemplatePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); NagiosHostTemplatePeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj2 (NagiosHostTemplate) $obj2->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosHost rows $key3 = NagiosHostPeer::getPrimaryKeyHashFromRow($row, $startcol3); if ($key3 !== null) { $obj3 = NagiosHostPeer::getInstanceFromPool($key3); if (!$obj3) { $omClass = NagiosHostPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj3 = new $cls(); $obj3->hydrate($row, $startcol3); NagiosHostPeer::addInstanceToPool($obj3, $key3); } // if $obj3 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj3 (NagiosHost) $obj3->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosServiceTemplate rows $key4 = NagiosServiceTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol4); if ($key4 !== null) { $obj4 = NagiosServiceTemplatePeer::getInstanceFromPool($key4); if (!$obj4) { $omClass = NagiosServiceTemplatePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj4 = new $cls(); $obj4->hydrate($row, $startcol4); NagiosServiceTemplatePeer::addInstanceToPool($obj4, $key4); } // if $obj4 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj4 (NagiosServiceTemplate) $obj4->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosService rows $key5 = NagiosServicePeer::getPrimaryKeyHashFromRow($row, $startcol5); if ($key5 !== null) { $obj5 = NagiosServicePeer::getInstanceFromPool($key5); if (!$obj5) { $omClass = NagiosServicePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj5 = new $cls(); $obj5->hydrate($row, $startcol5); NagiosServicePeer::addInstanceToPool($obj5, $key5); } // if $obj5 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj5 (NagiosService) $obj5->addNagiosEscalation($obj1); } // if joined row is not null // Add objects for joined NagiosHostgroup rows $key6 = NagiosHostgroupPeer::getPrimaryKeyHashFromRow($row, $startcol6); if ($key6 !== null) { $obj6 = NagiosHostgroupPeer::getInstanceFromPool($key6); if (!$obj6) { $omClass = NagiosHostgroupPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj6 = new $cls(); $obj6->hydrate($row, $startcol6); NagiosHostgroupPeer::addInstanceToPool($obj6, $key6); } // if $obj6 already loaded // Add the $obj1 (NagiosEscalation) to the collection in $obj6 (NagiosHostgroup) $obj6->addNagiosEscalation($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
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++; } } }
private function getAppliedHosts($hostValues, $hostgroupValues) { $appliedHosts = array(); foreach ($hostValues as $val) { $val = $val['value']; if ($val == "*") { // Get all hosts $tempHosts = NagiosHostPeer::doSelect(new Criteria()); foreach ($tempHosts as $tempHost) { if (!array_key_exists($tempHost->getName(), $appliedHosts)) { $appliedHosts[] = $tempHost; } } } else { if (preg_match("/^!/", $val)) { continue; } else { $host = NagiosHostPeer::getByName($val); if (!$host) { // Give error $values = $this->getSegment()->getValues(); $job = $this->getEngine()->getJob(); $job->addError("The host specified by name: " . $val . " was not found. Setting this host ext info as queued."); return false; } else { if (!array_key_exists($host->getName(), $appliedHosts)) { $appliedHosts[] = $host; } } } } } foreach ($hostgroupValues as $val) { $val = $val['value']; // First check for * // then check for each hostgroup existence, then // each additional hostgroup if ($val == "*") { // Get all hostgroups $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria()); foreach ($hostgroups as $hg) { $hosts = $hostgroup->getNagiosHosts(); foreach ($hosts as $tempHost) { if (!array_key_exists($tempHost->getName(), $appliedHosts)) { $appliedHosts[] = $tempHost; } } } } else { if (preg_match("/^!/", $val)) { continue; } else { $hg = NagiosHostgroupPeer::getByName($val); if (!$hg) { // Give error $values = $this->getSegment()->getValues(); $job = $this->getEngine()->getJob(); $job->addError("The hostgroup specified by name: " . $val . " was not found. Setting this host ext info as queued."); return false; } else { $hosts = $hg->getMembers(); foreach ($hosts as $tempHost) { if (!array_key_exists($tempHost->getName(), $appliedHosts)) { $appliedHosts[] = $tempHost; } } } } } } // Okay, do exclusions foreach ($hostValues as $val) { $val = $val['value']; if (preg_match("/^!/", $val)) { unset($appliedHosts[$val]); } } foreach ($hostgroupValues as $val) { $val = $val['value']; if (preg_match("/^!/", $val)) { $hg = NagiosHostgroupPeer::getByName($val); if (!$hg) { // Do nothing } else { $hosts = $hg->getMembers(); foreach ($hosts as $tempHost) { unset($appliedHosts[$tempHost->getName()]); } } } } return $appliedHosts; }
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; }
$cancelLink = "host_template.php?id=" . $hostTemplate->getId() . "§ion=services"; } } else { if (isset($_GET['host_id'])) { $host = NagiosHostPeer::retrieveByPK($_GET['host_id']); if (!$host) { header("Location: welcome.php"); die; } else { $title = " for Host " . $host->getName(); $sublink = "?host_id=" . $host->getId(); $cancelLink = "hosts.php?id=" . $host->getId() . "§ion=services"; } } else { if (isset($_GET['hostgroup_id'])) { $hostgroup = NagiosHostgroupPeer::retrieveByPK($_GET['hostgroup_id']); if (!$hostgroup) { header("Location: welcome.php"); die; } else { $title = " for Hostgroup " . $hostgroup->getName(); $sublink = "?hostgroup_id=" . $hostgroup->getId(); $cancelLink = "hostgroups.php?id=" . $hostgroup->getId() . "§ion=services"; } } else { header("Location: welcome.php"); die; } } } if (isset($_POST['request'])) {
public function import() { $job = $this->getEngine()->getJob(); $config = $this->getEngine()->getConfig(); $segment = $this->getSegment(); $values = $segment->getValues(); $fileName = $segment->getFilename(); // We need to determine if we are a template $isTemplate = false; if (isset($values['name'])) { // We're a template, just do a template process. $obj = new NagiosServiceTemplate(); $ret = $this->__process($obj); if (!$ret) { return false; } $obj->save(); $obj->clearAllReferences(true); $job->addNotice("NagiosServiceImporter finished importing service template: " . $obj->getName()); return true; } else { // Okay, we need to create new Services for each type if (isset($values['host_name'])) { foreach ($values['host_name'] as $hostNameValues) { $obj = new NagiosService(); $host = NagiosHostPeer::getByName($hostNameValues['value']); if (!$host) { return false; } // Okay, we got a proper host $obj->setNagiosHost($host); $ret = $this->__process($obj); if (!$ret) { return false; } $obj->save(); $host->clearAllReferences(true); $job->addNotice("NagiosServiceImporter finished importing service : " . $obj->getDescription() . " for host: " . $host->getName()); } } // Okay, now search for hostgroups if (isset($values['hostgroup_name'])) { foreach ($values['hostgroup_name'] as $hostGroupValues) { $obj = new NagiosService(); $hostgroup = NagiosHostgroupPeer::getByName($hostGroupValues['value']); if (!$hostgroup) { return false; } // Okay, we got a proper hostgroup $obj->setNagiosHostgroup($hostgroup); $ret = $this->__process($obj); if (!$ret) { return false; } $obj->save(); $hostgroup->clearAllReferences(true); } } // Okay, now search for hostgroups if (isset($values['hostgroup'])) { foreach ($values['hostgroup'] as $hostGroupValues) { $obj = new NagiosService(); $hostgroup = NagiosHostgroupPeer::getByName($hostGroupValues['value']); if (!$hostgroup) { return false; } // Okay, we got a proper hostgroup $obj->setNagiosHostgroup($hostgroup); $ret = $this->__process($obj); if (!$ret) { return false; } $obj->save(); $hostgroup->clearAllReferences(true); } } } $obj->clearAllReferences(true); return true; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = NagiosHostgroupPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setName($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setAlias($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setNotes($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setNotesUrl($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setActionUrl($arr[$keys[5]]); } }
include_once 'includes/config.inc'; // AJAX behavior if (isset($_GET['request']) && $_GET['request'] == "search") { $results = array(); switch ($_GET['type']) { case 'host': $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $_GET['q'] . "%", Criteria::LIKE); $c->setIgnoreCase(true); $results = NagiosHostPeer::doSelect($c); break; case 'hostgroup': $c = new Criteria(); $c->add(NagiosHostgroupPeer::NAME, $_GET['q'] . "%", Criteria::LIKE); $c->setIgnoreCase(true); $results = NagiosHostgroupPeer::doSelect($c); case 'service': // Get the host $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $_GET['host']); $c->setIgnoreCase(true); $host = NagiosHostPeer::doSelectOne($c); $returnObj = array(); if (!$host) { $returnObj['error'] = "Host " . $_GET['host'] . " not found."; print json_encode($returnObj); exit; } else { $returnObj['services'] = array(); // Okay, let's get services. $services = $host->getNagiosServices();
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."); }
/** * Get the associated NagiosHostgroup object * * @param PropelPDO Optional Connection object. * @return NagiosHostgroup The associated NagiosHostgroup object. * @throws PropelException */ public function getNagiosHostgroup(PropelPDO $con = null) { if ($this->aNagiosHostgroup === null && $this->hostgroup !== null) { $c = new Criteria(NagiosHostgroupPeer::DATABASE_NAME); $c->add(NagiosHostgroupPeer::ID, $this->hostgroup); $this->aNagiosHostgroup = NagiosHostgroupPeer::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->aNagiosHostgroup->addNagiosEscalations($this); */ } return $this->aNagiosHostgroup; }
<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()); ?> </td> </tr> <tr> <td><strong>Total Nagios Host Templates:</strong></td> <td><?php echo NagiosHostTemplatePeer::doCount(new Criteria()); ?>
/** * 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(NagiosHostgroupPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(NagiosHostgroupPeer::DATABASE_NAME); $criteria->add(NagiosHostgroupPeer::ID, $pks, Criteria::IN); $objs = NagiosHostgroupPeer::doSelect($criteria, $con); } return $objs; }
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() { $job = $this->getEngine()->getJob(); $config = $this->getEngine()->getConfig(); $segment = $this->getSegment(); $values = $segment->getValues(); $fileName = $segment->getFilename(); // We need to determine if we are a template if (isset($values['name'])) { // We are a template $job->addNotice("Saving internal host escalation template: " . $values['name'][0]['value']); NagiosHostEscalationImporter::saveTemplate($values['name'][0]['value'], $segment); return true; } // 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; } } } // Okay, we first iterate through any possible dependent_host_name's if (isset($values['host_name'])) { $host_names = explode(",", $values['host_name'][0]['value']); foreach ($host_names as $host_name) { $escalation = new NagiosEscalation(); $host = NagiosHostPeer::getByName($host_name); if (!$host) { return false; } $escalation->setNagiosHost($host); $ret = $this->__process($escalation); if (!$ret) { return false; } $ret = $this->__addContacts($escalation); if (!$ret) { return false; } // Need to give it a temp name $escalation->save(); $escalation->setDescription("Imported Escalation #" . $escalation->getId()); $escalation->save(); $job->addNotice("NagiosHostEscalation finished importing Host Escalation for " . $host_name); $host->clearAllReferences(true); $escalation->clearAllReferences(true); } } if (isset($values['hostgroup_name'])) { $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']); foreach ($hostgroup_names as $hostgroup_name) { $escalation = new NagiosEscalation(); $hostgroup = NagiosHostgroupPeer::getByName($hostgroup_name); if (!$hostgroup) { return false; } $escalation->setNagiosHostgroup($hostgroup); $ret = $this->__process($escalation); if (!$ret) { return false; } $ret = $this->__addContacts($escalation); if (!$ret) { return false; } $escalation->save(); $escalation->setDescription("Imported Escalation #" . $escalation->getId()); $escalation->save(); $job->addNotice("NagiosHostEscalation finished importing Host Escalation for hostgroup " . $hostgroup_name); $hostgroup->clearAllReferences(true); $escalation->clearAllReferences(true); } } return true; }
public function export() { global $lilac; // Grab our export job $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("NagiosServiceExporter attempting to export service configuration."); $fp = $this->getOutputFile(); fputs($fp, "# Written by NagiosServiceExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n"); $hosts = NagiosHostPeer::doSelect(new Criteria()); foreach ($hosts as $host) { // Got hosts // Get our inherited services first $job->addNotice("Processing services for host: " . $host->getName()); $inheritedServices = $host->getInheritedServices(); foreach ($inheritedServices as $service) { $job->addNotice("Processing service " . $service->getDescription()); $this->_exportService($service, "host", $host); } $services = $host->getNagiosServices(); foreach ($services as $service) { $job->addNotice("Processing service " . $service->getDescription()); $this->_exportService($service, "host", $host); } $job->addNotice("Completed services export for host: " . $host->getName()); } $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria()); foreach ($hostgroups as $hostgroup) { $job->addNotice("Processing services for hostgroup: " . $hostgroup->getName()); $services = $hostgroup->getNagiosServices(); foreach ($services as $service) { $job->addNotice("Processing service " . $service->getDescription()); $this->_exportService($service, "hostgroup", $hostgroup); } } $job->addNotice("NagiosServiceExporter complete."); return true; }
public function export() { global $lilac; // Grab our export job $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("NagiosEscalationExporter attempting to export escalation configuration."); $fp = $this->getOutputFile(); fputs($fp, "# Written by NagiosEscalationExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n"); $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria()); foreach ($hostgroups as $hostgroup) { $job->addNotice("Processing escalations for hostgroup: " . $hostgroup->getName()); $escalations = $hostgroup->getNagiosEscalations(); foreach ($escalations as $escalation) { $this->_exportEscalation($escalation, "hostgroup", $hostgroup); } } $hosts = NagiosHostPeer::doSelect(new Criteria()); foreach ($hosts as $host) { // Got hosts // Get inherited escalations first $job->addNotice("Processing escalations for host: " . $host->getName()); $inheritedEscalations = $host->getInheritedEscalations(); foreach ($inheritedEscalations as $escalation) { $this->_exportEscalation($escalation, "host", $host); } ${$escalations} = $host->getNagiosEscalations(); foreach (${$escalations} as $escalation) { $this->_exportEscalation($escalation, "host", $host); } // Get our services $inheritedServices = $host->getInheritedServices(); foreach ($inheritedServices as $service) { $job->addNotice("Processing escalations for service: " . $service->getDescription() . " on " . $host->getName()); $serviceInheritedEscalations = $service->getInheritedEscalations(); foreach ($serviceInheritedEscalations as $escalation) { $this->_exportEscalation($escalation, "service", $service, $host); } $c = new Criteria(); $c->add(NagiosEscalationPeer::HOST, $host->getId()); $c->add(NagiosEscalationPeer::SERVICE, $service->getId()); $serviceEscalations = NagiosEscalationPeer::doSelect($c); foreach ($serviceEscalations as $escalation) { $this->_exportEscalation($escalation, "service", $service, $host); } } $services = $host->getNagiosServices(); foreach ($services as $service) { $job->addNotice("Processing escalations for service: " . $service->getDescription() . " on " . $host->getName()); $serviceInheritedEscalations = $service->getInheritedEscalations(); foreach ($serviceInheritedEscalations as $escalation) { $this->_exportEscalation($escalation, "service", $service, $host); } $serviceEscalations = $service->getNagiosEscalations(); foreach ($serviceEscalations as $escalation) { $this->_exportEscalation($escalation, "service", $service, $host); } } $job->addNotice("Completed escalations export for host: " . $host->getName()); } $job->addNotice("NagiosEscalationExporter complete."); return true; }