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 getTopLevelHosts() { $con = Propel::getConnection(BaseNagiosHostPeer::DATABASE_NAME); $sql = "SELECT * from nagios_host WHERE (select count(*) FROM nagios_host_parent WHERE nagios_host_parent.child_host = nagios_host.id) = 0 ORDER BY nagios_host.name"; $stmt = $con->prepare($sql); $stmt->execute(); $hosts = NagiosHostPeer::populateObjects($stmt); return $hosts; }
public static function getByHostAndDescription($hostname, $description) { // First get host $host = NagiosHostPeer::getByName($hostname); if (!$host) { return false; } $c = new Criteria(); $c->add(NagiosServicePeer::HOST, $host->getId()); $c->add(NagiosServicePeer::DESCRIPTION, $description); $c->setIgnoreCase(true); $service = NagiosServicePeer::doSelectOne($c); if (!$service) { return false; } return $service; }
public function valid() { $values = $this->getSegment()->getValues(); $job = $this->getEngine()->getJob(); if (isset($values['use'])) { // We need to use a template $job->addNotice("This Service Ext Info uses a template: " . $values['use'][0]['value']); $template = NagiosServiceExtInfoImporter::getTemplateByName($values['use'][0]['value']); if (empty($template)) { $job->addNotice("That template is not found yet. Setting this host ext info as queued."); return false; } } // Check for service existence if (!isset($values['host_name']) || !isset($values['service_description'])) { $job->addNotice("The host or service for this service ext info is blank. Service ext Info requires a host name."); return false; } $service = NagiosServicePeer::getByHostAndDescription($values['host_name'][0]['value'], $values['service_description'][0]['value']); if (empty($service)) { // Okay, so it's not assigned by hostname, last ditch effort, look // through hostgroups $host = NagiosHostPeer::getByName($values['host_name'][0]['value']); if (!$host) { $job->addNotice("The service specified by " . $values['host_name'][0]['value'] . ":" . $values['service_description'][0]['value'] . " was not found. Setting this service ext info as queued."); return false; } // Go through the hostgroups for the host $memberships = $host->getNagiosHostgroupMemberships(); foreach ($memberships as $membership) { $hostgroup = $membership->getNagiosHostgroup(); $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup->getName(), $values['service_description'][0]['value']); if ($service) { break; } } } if ($service) { $service->clearAllReferences(true); } if (!$service) { $job->addNotice("The service specified by " . $values['host_name'][0]['value'] . ":" . $values['service_description'][0]['value'] . " was not found. Setting this service ext info as queued."); return false; } return true; }
/** * 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; }
/** * Get the associated NagiosHost object * * @param PropelPDO Optional Connection object. * @return NagiosHost The associated NagiosHost object. * @throws PropelException */ public function getNagiosHost(PropelPDO $con = null) { if ($this->aNagiosHost === null && $this->host !== null) { $c = new Criteria(NagiosHostPeer::DATABASE_NAME); $c->add(NagiosHostPeer::ID, $this->host); $this->aNagiosHost = NagiosHostPeer::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->aNagiosHost->addNagiosEscalations($this); */ } return $this->aNagiosHost; }
header("Location: hosts.php?id=" . $tempHost->getId()); die; } } } $add_template_list[] = array("host_template_id" => '', "template_name" => "None"); $lilac->get_host_template_list($template_list); if (count($template_list)) { foreach ($template_list as $tempTemplate) { $add_template_list[] = array('host_template_id' => $tempTemplate->getId(), 'template_name' => $tempTemplate->getName()); } } print_header("Add New Host"); $title = "Add A Top-Level Host"; if (isset($_GET['parent_id'])) { $tempHostInfo = NagiosHostPeer::retrieveByPK($_GET['parent_id']); if ($tempHostInfo) { $title = "Add A Host Under " . $tempHostInfo->getName(); } } print_window_header($title, "100%"); ?> <form name="host_add_form" method="post" action="add_host.php<?php if (isset($_GET['parent_id'])) { print "?parent_id=" . $_GET['parent_id']; } ?> "> <input type="hidden" name="request" value="add_host" /> <?php if (isset($_GET['parent_id']) && $_GET['parent_id'] != 0) {
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this NagiosTimeperiod is new, it will return * an empty collection; or if this NagiosTimeperiod has previously * been saved, it will retrieve related NagiosHostsRelatedByNotificationPeriod from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in NagiosTimeperiod. */ public function getNagiosHostsRelatedByNotificationPeriodJoinNagiosCommandRelatedByEventHandler($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(NagiosTimeperiodPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collNagiosHostsRelatedByNotificationPeriod === null) { if ($this->isNew()) { $this->collNagiosHostsRelatedByNotificationPeriod = array(); } else { $criteria->add(NagiosHostPeer::NOTIFICATION_PERIOD, $this->id); $this->collNagiosHostsRelatedByNotificationPeriod = NagiosHostPeer::doSelectJoinNagiosCommandRelatedByEventHandler($criteria, $con, $join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(NagiosHostPeer::NOTIFICATION_PERIOD, $this->id); if (!isset($this->lastNagiosHostRelatedByNotificationPeriodCriteria) || !$this->lastNagiosHostRelatedByNotificationPeriodCriteria->equals($criteria)) { $this->collNagiosHostsRelatedByNotificationPeriod = NagiosHostPeer::doSelectJoinNagiosCommandRelatedByEventHandler($criteria, $con, $join_behavior); } } $this->lastNagiosHostRelatedByNotificationPeriodCriteria = $criteria; return $this->collNagiosHostsRelatedByNotificationPeriod; }
function build_navbar($host_id, &$navbar) { global $path_config; global $sys_config; global $lilac; $tempID = $host_id; $tempNavBar = ''; while ($tempID != 0) { // If anything other than the network object $host = NagiosHostPeer::retrieveByPK($tempID); $tempNavBar = "<a href=\"hosts.php?id=" . $tempID . "\">" . $host->getName() . "</a> > " . $tempNavBar; $tempID = $host->getParentHost(); } $tempNavBar = $tempNavBar; $navbar = $tempNavBar; }
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; }
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 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() { $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; }
* */ include_once 'includes/config.inc'; if (isset($_GET['host_template_id'])) { $hostTemplate = NagiosHostTemplatePeer::retrieveByPK($_GET['host_template_id']); if (!$hostTemplate) { header("Location: welcome.php"); die; } else { $title = " for Host Template " . $hostTemplate->getName(); $sublink = "?host_template_id=" . $hostTemplate->getId(); $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 {
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; }
/** * Selects a collection of AutodiscoveryDevice objects pre-filled with all related objects except NagiosHostTemplate. * * @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 AutodiscoveryDevice objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAllExceptNagiosHostTemplate(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); } AutodiscoveryDevicePeer::addSelectColumns($c); $startcol2 = AutodiscoveryDevicePeer::NUM_COLUMNS - AutodiscoveryDevicePeer::NUM_LAZY_LOAD_COLUMNS; AutodiscoveryJobPeer::addSelectColumns($c); $startcol3 = $startcol2 + (AutodiscoveryJobPeer::NUM_COLUMNS - AutodiscoveryJobPeer::NUM_LAZY_LOAD_COLUMNS); NagiosHostPeer::addSelectColumns($c); $startcol4 = $startcol3 + (NagiosHostPeer::NUM_COLUMNS - NagiosHostPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(AutodiscoveryDevicePeer::JOB_ID), array(AutodiscoveryJobPeer::ID), $join_behavior); $c->addJoin(array(AutodiscoveryDevicePeer::PROPOSED_PARENT), array(NagiosHostPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = AutodiscoveryDevicePeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = AutodiscoveryDevicePeer::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 = AutodiscoveryDevicePeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); AutodiscoveryDevicePeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined AutodiscoveryJob rows $key2 = AutodiscoveryJobPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = AutodiscoveryJobPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = AutodiscoveryJobPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); AutodiscoveryJobPeer::addInstanceToPool($obj2, $key2); } // if $obj2 already loaded // Add the $obj1 (AutodiscoveryDevice) to the collection in $obj2 (AutodiscoveryJob) $obj2->addAutodiscoveryDevice($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 (AutodiscoveryDevice) to the collection in $obj3 (NagiosHost) $obj3->addAutodiscoveryDevice($obj1); } // if joined row is not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
private function importService($serviceData) { $job = $this->getEngine()->getJob(); $newService = new NagiosService(); // Check to see if host or host template exists first if (!empty($serviceData['host_id'])) { $hostName = $this->getHostNameById($serviceData['host_id']); if (!$hostName) { $job->addNotice("Fruity Service Importer: Failed to find host with id: " . $serviceData['host_id']); return true; } $host = NagiosHostPeer::getByName($hostName); if (!$host) { $job->addNotice("Fruity Service Importer: Failed to find host with name: " . $hostName); return true; } $newService->setHost($host->getId()); } else { if (!empty($serviceData['host_template_id'])) { $hostTemplateName = $this->getHostTemplateNameById($serviceData['host_template_id']); if (!$hostTemplateName) { $job->addNotice("Fruity Service Importer: Failed to find host template with id: " . $serviceData['host_template_id']); return true; } $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName); if (!$hostTemplate) { $job->addNotice("Fruity Service Importer: Failed to find host template with name: " . $hostTemplateName); return true; } $newService->setHostTemplate($hostTemplate->getId()); } else { if (!empty($serviceData['hostgroup_id'])) { $hostgroupName = $this->getHostGroupNameById($serviceData['hostgroup_id']); if (!$hostgroupName) { $job->addNotice("Fruity Service Importer: Failed to find host group with id: " . $serviceData['host_template_id']); return true; } $hostgroup = NagiosHostGroupPeer::getByName($hostgroupName); if (!$hostgroup) { $job->addNotice("Fruity Service Importer: Failed to find host group with name: " . $hostGroupName); return true; } $newService->setHostgroup($hostgroup->getId()); } } } // Check to see if we need the template if (!empty($serviceData['use_template_id'])) { $name = $this->getServiceTemplateNameById($serviceData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Service Importer: Could not find template with id: " . $serviceData['use_template_id'] . ". Aborting it's import."); return false; } else { // Okay, we got the name, does this template exist? $template = NagiosServiceTemplatePeer::getByName($name); if (!$template) { return false; } else { // Create a new inheritance relationship $inheritance = new NagiosServiceTemplateInheritance(); $inheritance->setNagiosServiceTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosService($newService); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Service Template Importer: Cannot add inheritance from " . $template->getName() . " to " . $newService->getName()); } } } } // Okay, start 'er up! foreach ($serviceData as $key => $val) { unset($name); if ($key == "service_template_id" || $key == "use_template_id" || $key == "template_name" || $key == "host_id" || $key == "hostgroup_id" || $key == "host_template_id" || $key == "service_id") { continue; } if ($key == "service_description") { $key = "description"; } if ($key == "notification_options_warning") { $key = "notification_on_warning"; } if ($key == "notification_options_unknown") { $key = "notification_on_unknown"; } if ($key == "notification_options_critical") { $key = "notification_on_critical"; } if ($key == "notification_options_recovery") { $key = "notification_on_recovery"; } if ($key == "notification_options_flapping") { $key = "notification_on_flapping"; } if ($key == "stalking_options_warning") { $key = "stalking_on_warning"; } if ($key == "stalking_options_unknown") { $key = "stalking_on_unknown"; } if ($key == "stalking_options_critical") { $key = "stalking_on_critical"; } if ($key == "stalking_options_ok") { $key = "stalking_on_ok"; } if ($key == "max_check_attempts") { $key = "maximum_check_attempts"; } if ($key == "retry_check_interval") { $key = "retry_interval"; } if ($key == "check_command") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newService->setCheckCommand($command->getId()); } } continue; } if ($key == "check_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newService->setCheckPeriod($timeperiod->getId()); } } continue; } if ($key == "event_handler") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newService->setEventHandler($command->getId()); } } continue; } if ($key == "notification_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newService->setNotificationPeriod($timeperiod->getId()); } } continue; } try { $name = NagiosServiceTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Service Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newService->{$method}($val); } } $job->addNotice("Fruity Service Importer: Saved service: " . $newService->getDescription() . " on " . $newService->getOwnerDescription()); $newService->save(); $this->totalImported++; return true; }
/** * 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(NagiosHostPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(NagiosHostPeer::DATABASE_NAME); $criteria->add(NagiosHostPeer::ID, $pks, Criteria::IN); $objs = NagiosHostPeer::doSelect($criteria, $con); } return $objs; }
/** * 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 = NagiosHostPeer::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->setDisplayName($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setInitialState($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setAddress($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setCheckCommand($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setRetryInterval($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setFirstNotificationDelay($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setMaximumCheckAttempts($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setCheckInterval($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setPassiveChecksEnabled($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setCheckPeriod($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setObsessOverHost($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setCheckFreshness($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { $this->setFreshnessThreshold($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { $this->setActiveChecksEnabled($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { $this->setChecksEnabled($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { $this->setEventHandler($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { $this->setEventHandlerEnabled($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { $this->setLowFlapThreshold($arr[$keys[20]]); } if (array_key_exists($keys[21], $arr)) { $this->setHighFlapThreshold($arr[$keys[21]]); } if (array_key_exists($keys[22], $arr)) { $this->setFlapDetectionEnabled($arr[$keys[22]]); } if (array_key_exists($keys[23], $arr)) { $this->setProcessPerfData($arr[$keys[23]]); } if (array_key_exists($keys[24], $arr)) { $this->setRetainStatusInformation($arr[$keys[24]]); } if (array_key_exists($keys[25], $arr)) { $this->setRetainNonstatusInformation($arr[$keys[25]]); } if (array_key_exists($keys[26], $arr)) { $this->setNotificationInterval($arr[$keys[26]]); } if (array_key_exists($keys[27], $arr)) { $this->setNotificationPeriod($arr[$keys[27]]); } if (array_key_exists($keys[28], $arr)) { $this->setNotificationsEnabled($arr[$keys[28]]); } if (array_key_exists($keys[29], $arr)) { $this->setNotificationOnDown($arr[$keys[29]]); } if (array_key_exists($keys[30], $arr)) { $this->setNotificationOnUnreachable($arr[$keys[30]]); } if (array_key_exists($keys[31], $arr)) { $this->setNotificationOnRecovery($arr[$keys[31]]); } if (array_key_exists($keys[32], $arr)) { $this->setNotificationOnFlapping($arr[$keys[32]]); } if (array_key_exists($keys[33], $arr)) { $this->setNotificationOnScheduledDowntime($arr[$keys[33]]); } if (array_key_exists($keys[34], $arr)) { $this->setStalkingOnUp($arr[$keys[34]]); } if (array_key_exists($keys[35], $arr)) { $this->setStalkingOnDown($arr[$keys[35]]); } if (array_key_exists($keys[36], $arr)) { $this->setStalkingOnUnreachable($arr[$keys[36]]); } if (array_key_exists($keys[37], $arr)) { $this->setFailurePredictionEnabled($arr[$keys[37]]); } if (array_key_exists($keys[38], $arr)) { $this->setFlapDetectionOnUp($arr[$keys[38]]); } if (array_key_exists($keys[39], $arr)) { $this->setFlapDetectionOnDown($arr[$keys[39]]); } if (array_key_exists($keys[40], $arr)) { $this->setFlapDetectionOnUnreachable($arr[$keys[40]]); } if (array_key_exists($keys[41], $arr)) { $this->setNotes($arr[$keys[41]]); } if (array_key_exists($keys[42], $arr)) { $this->setNotesUrl($arr[$keys[42]]); } if (array_key_exists($keys[43], $arr)) { $this->setActionUrl($arr[$keys[43]]); } if (array_key_exists($keys[44], $arr)) { $this->setIconImage($arr[$keys[44]]); } if (array_key_exists($keys[45], $arr)) { $this->setIconImageAlt($arr[$keys[45]]); } if (array_key_exists($keys[46], $arr)) { $this->setVrmlImage($arr[$keys[46]]); } if (array_key_exists($keys[47], $arr)) { $this->setStatusmapImage($arr[$keys[47]]); } if (array_key_exists($keys[48], $arr)) { $this->setTwoDCoords($arr[$keys[48]]); } if (array_key_exists($keys[49], $arr)) { $this->setThreeDCoords($arr[$keys[49]]); } }
public function import() { $engine = $this->getEngine(); $job = $engine->getJob(); $job->addNotice("FruityDependencyImporter beginning to import Dependency Configuration."); foreach ($this->dbConn->query("SELECT * FROM nagios_dependencies", PDO::FETCH_ASSOC) as $dependency) { $newDependency = new NagiosDependency(); if (!empty($dependency['service_id'])) { // This is a service dependency $lilacService = $this->getLilacServiceById($dependency['service_id']); if (!$lilacService) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['service_id']); return true; } $newDependency->setService($lilacService->getId()); // Create Target $targetLilacService = $this->getLilacServiceById($dependency['target_service_id']); if (!$targetLilacService) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['target_service_id']); return true; } $target = new NagiosDependencyTarget(); $target->setNagiosDependency($newDependency); $target->setTargetService($targetLilacService->getId()); $target->save(); } else { if (!empty($dependency['host_id'])) { // This is a host dependency $hostName = $this->getHostNameById($dependency['host_id']); $host = NagiosHostPeer::getByName($hostName); if (!$host) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName); return true; } $newDependency->setHost($host->getId()); // Create Target $hostName = $this->getHostNameById($dependency['target_host_id']); $host = NagiosHostPeer::getByName($hostName); if (!$host) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName); return true; } $target = new NagiosDependencyTarget(); $target->setNagiosDependency($newDependency); $target->setTargetHost($host->getId()); $target->save(); } else { if (!empty($dependency['service_template_id'])) { // This is a service template dependency $templateName = $this->getServiceTemplateNameById($dependency['service_template_id']); $template = NagiosServiceTemplatePeer::getByName($templateName); if (!$template) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service template with name matching: " . $templateName); return true; } $newDependency->setServiceTemplate($template->getId()); // Create Target $targetLilacService = $this->getLilacServiceById($dependency['target_service_id']); if (!$targetLilacService) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac service with an id matching: " . $dependency['target_service_id']); return true; } $target = new NagiosDependencyTarget(); $target->setNagiosDependency($newDependency); $target->setTargetService($targetLilacService->getId()); $target->save(); } else { if (!empty($dependency['host_template_id'])) { // This is for a host template dependency $templateName = $this->getHostTemplateNameById($dependency['host_template_id']); $template = NagiosHostTemplatePeer::getByName($templateName); if (!$template) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host template with name matching: " . $templateName); return true; } $newDependency->setHostTemplate($template->getId()); $hostName = $this->getHostNameById($dependency['target_host_id']); $host = NagiosHostPeer::getByName($hostName); if (!$host) { $job->addNotice("Fruity Dependency Importer: Failed to get Lilac host with an name matching: " . $hostName); return true; } $target = new NagiosDependencyTarget(); $target->setNagiosDependency($newDependency); $target->setTargetHost($host->getId()); $target->save(); } } } } foreach ($dependency as $key => $val) { unset($name); if ($key == "dependency_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id" || $key == "target_service_id" || $key == "target_host_id") { continue; } if ($key == "command_name") { $key = "name"; } if ($key == "command_line") { $key = "line"; } if ($key == "command_desc") { $key = "description"; } try { $name = NagiosDependencyPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Dependency Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newDependency->{$method}($val); } } $newDependency->save(); $newDependency->setName("Imported Dependency #" . $newDependency->getId()); $newDependency->save(); $job->addNotice("FruityDependencyImporter imported dependency with id: " . $newDependency->getId()); } $job->addNotice("FruityDependencyImporter finished importing Dependency Configuration."); }
private function importHost($hostData) { $job = $this->getEngine()->getJob(); // check to see if we have a host by that name if (NagiosHostPeer::getByName($hostData['host_name'])) { $job->addNotice("Fruity Host Importer: Host " . $hostData['host_name'] . " already exists. Aborting it's import."); return true; } $newHost = new NagiosHost(); $newHost->setName($hostData['host_name']); // Check to see if we need the template if (!empty($hostData['use_template_id'])) { $name = $this->getHostTemplateNameById($hostData['use_template_id'], $this->dbConn); if (!$name) { $job->addNotice("Fruity Host Importer: Could not find template with id: " . $hostData['use_template_id'] . ". Aborting it's import."); return false; } else { // Okay, we got the name, does this template exist? $template = NagiosHostTemplatePeer::getByName($name); if (!$template) { $job->addNotice("Fruity Host Importer: Could not find a template in the system with the name of: " . $name . ". Aborting it's import."); return false; } else { // Create a new inheritance relationship $inheritance = new NagiosHostTemplateInheritance(); $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template); $inheritance->setNagiosHost($newHost); try { $inheritance->save(); } catch (Exception $e) { $job->addNotice("Fruity Host Importer: Cannot add inheritance from " . $template->getName() . " to " . $newHost->getName()); } } } } // Okay, start 'er up! foreach ($hostData as $key => $val) { unset($name); if ($key == "host_id" || $key == "use_template_id" || $key == "host_name") { continue; } if ($key == "parents") { // we're gonna do parents after this continue; } if ($key == "notification_options_down") { $key = "notification_on_down"; } if ($key == "notification_options_unreachable") { $key = "notification_on_unreachable"; } if ($key == "notification_options_recovery") { $key = "notification_on_recovery"; } if ($key == "notification_options_flapping") { $key = "notification_on_flapping"; } if ($key == "stalking_options_up") { $key = "stalking_on_up"; } if ($key == "stalking_options_down") { $key = "stalking_on_down"; } if ($key == "stalking_options_unreachable") { $key = "stalking_on_unreachable"; } if ($key == "max_check_attempts") { $key = "maximum_check_attempts"; } if ($key == "retry_check_interval") { $key = "retry_interval"; } if ($key == "check_command") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newHost->setCheckCommand($command->getId()); } } continue; } if ($key == "check_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newHost->setCheckPeriod($timeperiod->getId()); } } continue; } if ($key == "event_handler") { $name = $this->getCommandNameById($val); if ($name) { $command = NagiosCommandPeer::getByName($name); if ($command) { $newHost->setEventHandler($command->getId()); } } continue; } if ($key == "notification_period") { $name = $this->getTimeperiodNameById($val); if ($name) { $timeperiod = NagiosTimeperiodPeer::getByName($name); if ($timeperiod) { $newHost->setNotificationPeriod($timeperiod->getId()); } } continue; } try { $name = NagiosHostPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); } catch (Exception $e) { $job->addNotice("Fruity Host Importer: Was unable to store unsupported value: " . $key); } if (!empty($name)) { $method = "set" . $name; $newHost->{$method}($val); } } $newHost->save(); $job->addNotice("FruityHostImporter: Imported new host: " . $newHost->getName()); $this->totalImported++; return true; }
/** * Method perform a DELETE on the database, given a NagiosTimeperiod or Criteria object OR a primary key value. * * @param mixed $values Criteria or NagiosTimeperiod object or primary key or array of primary keys * which is used to create the DELETE statement * @param PropelPDO $con the connection to use * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows * if supported by native driver or if emulated using Propel. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doDelete($values, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(NagiosTimeperiodPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } if ($values instanceof Criteria) { // invalidate the cache for all objects of this type, since we have no // way of knowing (without running a query) what objects should be invalidated // from the cache based on this Criteria. NagiosTimeperiodPeer::clearInstancePool(); // rename for clarity $criteria = clone $values; } elseif ($values instanceof NagiosTimeperiod) { // invalidate the cache for this single object NagiosTimeperiodPeer::removeInstanceFromPool($values); // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it must be the primary key $criteria = new Criteria(self::DATABASE_NAME); $criteria->add(NagiosTimeperiodPeer::ID, (array) $values, Criteria::IN); foreach ((array) $values as $singleval) { // we can invalidate the cache for this single object NagiosTimeperiodPeer::removeInstanceFromPool($singleval); } } // Set the correct dbName $criteria->setDbName(self::DATABASE_NAME); $affectedRows = 0; // initialize var to track total num of affected rows try { // use transaction because $criteria could contain info // for more than one table or we could emulating ON DELETE CASCADE, etc. $con->beginTransaction(); $affectedRows += NagiosTimeperiodPeer::doOnDeleteCascade($criteria, $con); NagiosTimeperiodPeer::doOnDeleteSetNull($criteria, $con); // Because this db requires some delete cascade/set null emulation, we have to // clear the cached instance *after* the emulation has happened (since // instances get re-added by the select statement contained therein). if ($values instanceof Criteria) { NagiosTimeperiodPeer::clearInstancePool(); } else { // it's a PK or object NagiosTimeperiodPeer::removeInstanceFromPool($values); } $affectedRows += BasePeer::doDelete($criteria, $con); // invalidate objects in NagiosTimeperiodEntryPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodEntryPeer::clearInstancePool(); // invalidate objects in NagiosTimeperiodExcludePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodExcludePeer::clearInstancePool(); // invalidate objects in NagiosTimeperiodExcludePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosTimeperiodExcludePeer::clearInstancePool(); // invalidate objects in NagiosContactPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosContactPeer::clearInstancePool(); // invalidate objects in NagiosContactPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosContactPeer::clearInstancePool(); // invalidate objects in NagiosHostTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostTemplatePeer::clearInstancePool(); // invalidate objects in NagiosHostTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostTemplatePeer::clearInstancePool(); // invalidate objects in NagiosHostPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostPeer::clearInstancePool(); // invalidate objects in NagiosHostPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosHostPeer::clearInstancePool(); // invalidate objects in NagiosServiceTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServiceTemplatePeer::clearInstancePool(); // invalidate objects in NagiosServiceTemplatePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServiceTemplatePeer::clearInstancePool(); // invalidate objects in NagiosServicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServicePeer::clearInstancePool(); // invalidate objects in NagiosServicePeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosServicePeer::clearInstancePool(); // invalidate objects in NagiosDependencyPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosDependencyPeer::clearInstancePool(); // invalidate objects in NagiosEscalationPeer instance pool, since one or more of them may be deleted by ON DELETE CASCADE rule. NagiosEscalationPeer::clearInstancePool(); $con->commit(); return $affectedRows; } catch (PropelException $e) { $con->rollBack(); throw $e; } }
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; }
* Provides interface to maintain host templates * */ include_once 'includes/config.inc'; if (isset($_GET['host_template_id'])) { $tempSource = NagiosHostTemplatePeer::retrieveByPK($_GET['host_template_id']); $link = "host_template.php"; $fieldName = "host_template_id"; if (!$tempSource) { header("Location: welcome.php"); } $type = "hosttemplate"; $title = "Host Template"; } else { if (isset($_GET['host_id'])) { $tempSource = NagiosHostPeer::retrieveByPK($_GET['host_id']); $fieldName = "host_id"; $link = "hosts.php"; if (!$tempSource) { header("Location: welcome.php"); } $type = "host"; $title = "Host"; } else { if (isset($_GET['service_template_id'])) { $tempSource = NagiosServiceTemplatePeer::retrieveByPK($_GET['service_template_id']); $fieldName = "service_template_id"; $link = "service_template.php"; if (!$tempSource) { header("Location: welcome.php"); }
<td><?php echo NagiosHostTemplatePeer::doCount(new Criteria()); ?> </td> </tr> <tr class="odd"> <td><strong>Total Nagios Service Templates:</strong></td> <td><?php echo NagiosServiceTemplatePeer::doCount(new Criteria()); ?> </td> </tr> <tr> <td><strong>Total Nagios Hosts:</strong></td> <td><?php echo NagiosHostPeer::doCount(new Criteria()); ?> </td> </tr> <tr class="odd"> <td><strong>Total Nagios Services:</strong></td> <td><?php echo NagiosServicePeer::doCountAll(); ?> </td> </tr> </table> <?php print_window_footer();
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; }
foreach ($devices as $device) { $autodiscoveryJob->addNotice("Attempting Traceroute to " . $device->getAddress()); $tr = Net_Traceroute::factory(); if (!PEAR::isError($tr)) { $response = $tr->traceroute($device->getAddress()); $hops = $response->getHops(); $numOfHops = count($hops); $found = false; for ($counter = $numOfHops - 1; $counter >= 0; $counter--) { // Check the farthest hop first $c = new Criteria(); $c1 = $c->getNewCriterion(NagiosHostPeer::ADDRESS, $hops[$counter]['ip']); $c2 = $c->getNewCriterion(NagiosHostPeer::ADDRESS, $hops[$counter['machine']]); $c1->addOr($c2); $c->add($c1); $host = NagiosHostPeer::doSelectOne($c); if ($host) { // Found parent $autodiscoveryJob->addNotice("Found parent: " . $host->getName()); $device->setProposedParent($host->getId()); $device->save(); $found = true; } } if (!$found) { $autodiscoveryJob->addNotice("Could not find a suitable parent. Setting as a top-level device."); } } else { $autodiscoveryJob->addNotce("Failed to run Traceroute. Not using it."); } }
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; }
function addParentByName($name) { $parentId = $this->getParentHost(); $c = new Criteria(); $c->add(NagiosHostPeer::NAME, $name); $c->setIgnoreCase(true); $host = NagiosHostPeer::doSelectOne($c); if (!$host) { return false; } if (empty($parentId)) { $this->setParentHost($host->getId()); return true; } // Okay, let's first see if there's a parent relationship around $id = $this->getId(); if (!empty($id)) { $c = new Criteria(); $c->add(NagiosHostParentPeer::CHILD_HOST_TEMPLATE, $this->getId()); $c->add(NagiosHostParentPeer::PARENT_HOST, $host->getId()); $relationship = NagiosHostParentPeer::doSelectOne($c); if ($relationship) { return false; } } // Okay, relationship doesn't exist, let's add it! $relationship = new NagiosHostParent(); $relationship->setNagiosHostTemplate($this); $relationship->setNagiosHostRelatedByParentHost($host); $relationship->save(); return true; }