private function _exportService($service, $type, $targetObj) { global $lilac; $fp = $this->getOutputFile(); fputs($fp, "define service {\n"); $finalArray = array(); switch ($type) { case 'host': fputs($fp, "\thost_name\t" . $targetObj->getName() . "\n"); break; case 'hostgroup': fputs($fp, "\thostgroup_name\t" . $targetObj->getName() . "\n"); break; } $values = $service->getValues(); foreach ($values as $key => $valArray) { $value = $valArray['value']; if ($key == 'id' || $key == 'name' || $key == 'host' || $key == 'host_template' || $key == 'hostgroup' || $key == 'notification_on_warning' || $key == 'notification_on_unknown' || $key == 'notification_on_critical' || $key == 'notification_on_recovery' || $key == 'notification_on_flapping' || $key == 'notification_on_scheduled_downtime' || $key == 'flap_detection_on_ok' || $key == 'flap_detection_on_warning' || $key == 'flap_detection_on_unknown' || $key == 'flap_detection_on_critical' || $key == 'stalking_on_ok' || $key == 'stalking_on_warning' || $key == 'stalking_on_unknown' || $key == 'stalking_on_critical' || $key == '' || $key == "parent_host") { continue; } if ($key == 'description') { $key = 'service_description'; } if ($key == 'maximum_check_attempts') { $key = 'max_check_attempts'; } if ($key == "check_period" || $key == "notification_period") { $timeperiod = NagiosTimeperiodPeer::retrieveByPK($value); if (!$timeperiod) { $job->addError("Unable to find timeperiod with id: " . $value . " for " . $key); return false; } $value = $timeperiod->getName(); } if ($key == "check_command" || $key == "event_handler") { $command = NagiosCommandPeer::retrieveByPK($value); if (!$command) { $job->addError("Unable to find command with id: " . $value . " for " . $key); } $value = $command->getName(); if ($key == "check_command") { $cmdObj = $service->getInheritedCommandWithParameters(); foreach ($cmdObj['parameters'] as $parameterArray) { $value .= "!" . $parameterArray['parameter']->getParameter(); } } } if ($value === null) { continue; } if ($value === false) { $value = '0'; } $finalArray[$key] = $value; } foreach ($finalArray as $key => $val) { fputs($fp, "\t" . $key . "\t" . (string) $val . "\n"); } // Notifications if (isset($values['notification_on_warning']['value'])) { if (!$values['notification_on_warning']['value'] && !$values['notification_on_unknown']['value'] && !$values['notification_on_critical']['value'] && !$values['notification_on_recovery']['value'] && !$values['notification_on_flapping']['value']) { fputs($fp, "\tnotification_options\tn\n"); } else { fputs($fp, "\tnotification_options\t"); $tempValues = array(); if ($values['notification_on_warning']['value']) { $tempValues[] = "w"; } if ($values['notification_on_unknown']['value']) { $tempValues[] = "u"; } if ($values['notification_on_critical']['value']) { $tempValues[] = "c"; } if ($values['notification_on_recovery']['value']) { $tempValues[] = "r"; } if ($values['notification_on_flapping']['value']) { $tempValues[] = "f"; } if ($values['notification_on_scheduled_downtime']['value']) { $tempValues[] = "s"; } fputs($fp, implode(",", $tempValues)); fputs($fp, "\n"); } } // Stalking if ($values['flap_detection_on_ok']['value'] || $values['flap_detection_on_warning']['value'] || $values['flap_detection_on_unknown']['value'] || $values['flap_detection_on_critical']['value']) { fputs($fp, "\tflap_detection_options\t"); if ($values['flap_detection_on_ok']['value']) { fputs($fp, "o"); if ($values['flap_detection_on_warning']['value'] || $values['flap_detection_on_unknown']['value'] || $values['flap_detection_on_critical']['value']) { fputs($fp, ","); } } if ($values['flap_detection_on_warning']['value']) { fputs($fp, "w"); if ($values['flap_detection_on_unknown']['value'] || $values['flap_detection_on_critical']['value']) { fputs($fp, ","); } } if ($values['flap_detection_on_unknown']['value']) { fputs($fp, "u"); if ($values['flap_detection_on_critical']['value']) { fputs($fp, ","); } } if ($values['flap_detection_on_critical']['value']) { fputs($fp, "c"); } fputs($fp, "\n"); } // Stalking if ($values['stalking_on_ok']['value'] || $values['stalking_on_warning']['value'] || $values['stalking_on_unknown']['value'] || $values['stalking_on_critical']['value']) { fputs($fp, "\tstalking_options\t"); if ($values['stalking_on_ok']['value']) { fputs($fp, "o"); if ($values['stalking_on_warning']['value'] || $values['stalking_on_unknown']['value'] || $values['stalking_on_critical']['value']) { fputs($fp, ","); } } if ($values['stalking_on_warning']['value']) { fputs($fp, "w"); if ($values['stalking_on_unknown']['value'] || $values['stalking_on_critical']['value']) { fputs($fp, ","); } } if ($values['stalking_on_unknown']['value']) { fputs($fp, "u"); if ($values['stalking_on_critical']['value']) { fputs($fp, ","); } } if ($values['stalking_on_critical']['value']) { fputs($fp, "c"); } fputs($fp, "\n"); } // Contacts $contactList = array(); $inherited_list = $service->getInheritedContacts(); $contact_list = $service->getNagiosServiceContactMembers(); foreach ($inherited_list as $group) { if (!key_exists($group->getName(), $contactList)) { $contactList[$group->getName()] = $group; } } foreach ($contact_list as $contact) { $contact = $contact->getNagiosContact(); if (!key_exists($contact->getName(), $contactList)) { $contactList[$contact->getName()] = $contact; } } if (count($contactList)) { fputs($fp, "\tcontacts\t"); $first = true; foreach ($contactList as $contact) { if (!$first) { fputs($fp, ","); } else { $first = false; } fputs($fp, $contact->getName()); } fputs($fp, "\n"); } // Contact Groups $groupList = array(); $inherited_list = $service->getInheritedContactGroups(); $c = new Criteria(); $c->add(NagiosServiceContactGroupMemberPeer::SERVICE, $service->getId()); $contactgroups_list = NagiosServiceContactGroupMemberPeer::doSelect($c); foreach ($inherited_list as $group) { if (!key_exists($group->getName(), $groupList)) { $groupList[$group->getName()] = $group; } } foreach ($contactgroups_list as $group) { $group = $group->getNagiosContactgroup(); if (!key_exists($group->getName(), $groupList)) { $groupList[$group->getName()] = $group; } } if (count($groupList)) { fputs($fp, "\tcontact_groups\t"); $first = true; foreach ($groupList as $group) { if (!$first) { fputs($fp, ","); } else { $first = false; } fputs($fp, $group->getName()); } fputs($fp, "\n"); } // Service Groups $groupList = array(); $inherited_list = $service->getInheritedServiceGroups(); $hostgroups_list = $service->getNagiosServiceGroupMembers(); foreach ($inherited_list as $group) { if (!key_exists($group->getName(), $groupList)) { $groupList[$group->getName()] = $group; } } foreach ($hostgroups_list as $group) { $group = $group->getNagiosServiceGroup(); if (!key_exists($group->getName(), $groupList)) { $groupList[$group->getName()] = $group; } } if (count($groupList)) { fputs($fp, "\tservicegroups\t"); $first = true; foreach ($groupList as $group) { if (!$first) { fputs($fp, ","); } else { $first = false; } fputs($fp, $group->getName()); } fputs($fp, "\n"); } fputs($fp, "}\n"); fputs($fp, "\n"); }
/** * 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(NagiosServiceContactGroupMemberPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(NagiosServiceContactGroupMemberPeer::DATABASE_NAME); $criteria->add(NagiosServiceContactGroupMemberPeer::ID, $pks, Criteria::IN); $objs = NagiosServiceContactGroupMemberPeer::doSelect($criteria, $con); } return $objs; }
?> <?php echo $lilac->element_desc("contact_groups", "nagios_hosts_desc"); ?> <br /> <br /> </form> </td> </tr> </table> <?php $inherited_list = $service->getInheritedContactGroups(); $numOfInheritedGroups = count($inherited_list); $c = new Criteria(); $c->add(NagiosServiceContactGroupMemberPeer::SERVICE, $_GET['id']); $contactgroups_list = NagiosServiceContactGroupMemberPeer::doSelect($c); $numOfContactGroups = count($contactgroups_list); ?> <table width="100%" border="0"> <tr> <td width="100" align="center" valign="top"> <img src="<?php echo $path_config['image_root']; ?> contact.gif" /> </td> <td valign="top"> <?php if ($numOfInheritedGroups) { ?> <table width="100%" align="center" cellspacing="0" cellpadding="2" border="0">
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = NagiosContactGroupPeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related NagiosContactGroupMember objects $c = new Criteria(NagiosContactGroupMemberPeer::DATABASE_NAME); $c->add(NagiosContactGroupMemberPeer::CONTACTGROUP, $obj->getId()); $affectedRows += NagiosContactGroupMemberPeer::doDelete($c, $con); // delete related NagiosServiceContactGroupMember objects $c = new Criteria(NagiosServiceContactGroupMemberPeer::DATABASE_NAME); $c->add(NagiosServiceContactGroupMemberPeer::CONTACT_GROUP, $obj->getId()); $affectedRows += NagiosServiceContactGroupMemberPeer::doDelete($c, $con); // delete related NagiosEscalationContactgroup objects $c = new Criteria(NagiosEscalationContactgroupPeer::DATABASE_NAME); $c->add(NagiosEscalationContactgroupPeer::CONTACTGROUP, $obj->getId()); $affectedRows += NagiosEscalationContactgroupPeer::doDelete($c, $con); // delete related NagiosHostContactgroup objects $c = new Criteria(NagiosHostContactgroupPeer::DATABASE_NAME); $c->add(NagiosHostContactgroupPeer::CONTACTGROUP, $obj->getId()); $affectedRows += NagiosHostContactgroupPeer::doDelete($c, $con); } return $affectedRows; }
if ($tempContact) { $membership = new NagiosServiceContactMember(); $membership->setService($_GET['id']); $membership->setNagiosContact($tempContact); $membership->save(); $success = "New Service Template Contact Link added."; } else { $error = "That contact is not found."; } } } else { if ($_POST['request'] == 'add_contactgroup_command') { $c = new Criteria(); $c->add(NagiosServiceContactGroupMemberPeer::TEMPLATE, $_GET['id']); $c->add(NagiosServiceContactGroupMemberPeer::CONTACT_GROUP, $_POST['contactgroup_id']); $membership = NagiosServiceContactGroupMemberPeer::doSelectOne($c); if ($membership) { $error = "That contact group already exists in that list!"; } else { $tempGroup = NagiosContactGroupPeer::retrieveByPk($_POST['contactgroup_id']); if ($tempGroup) { $membership = new NagiosServiceContactGroupMember(); $membership->setTemplate($_GET['id']); $membership->setNagiosContactGroup($tempGroup); $membership->save(); $success = "New Service Contact Group Link added."; } } } else { if ($_POST['request'] == 'add_servicegroup_command') { $c = new Criteria();
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this NagiosServiceTemplate is new, it will return * an empty collection; or if this NagiosServiceTemplate has previously * been saved, it will retrieve related NagiosServiceContactGroupMembers 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 NagiosServiceTemplate. */ public function getNagiosServiceContactGroupMembersJoinNagiosContactGroup($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { if ($criteria === null) { $criteria = new Criteria(NagiosServiceTemplatePeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collNagiosServiceContactGroupMembers === null) { if ($this->isNew()) { $this->collNagiosServiceContactGroupMembers = array(); } else { $criteria->add(NagiosServiceContactGroupMemberPeer::TEMPLATE, $this->id); $this->collNagiosServiceContactGroupMembers = NagiosServiceContactGroupMemberPeer::doSelectJoinNagiosContactGroup($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(NagiosServiceContactGroupMemberPeer::TEMPLATE, $this->id); if (!isset($this->lastNagiosServiceContactGroupMemberCriteria) || !$this->lastNagiosServiceContactGroupMemberCriteria->equals($criteria)) { $this->collNagiosServiceContactGroupMembers = NagiosServiceContactGroupMemberPeer::doSelectJoinNagiosContactGroup($criteria, $con, $join_behavior); } } $this->lastNagiosServiceContactGroupMemberCriteria = $criteria; return $this->collNagiosServiceContactGroupMembers; }
/** * This is a method for emulating ON DELETE CASCADE for DBs that don't support this * feature (like MySQL or SQLite). * * This method is not very speedy because it must perform a query first to get * the implicated records and then perform the deletes by calling those Peer classes. * * This method should be used within a transaction if possible. * * @param Criteria $criteria * @param PropelPDO $con * @return int The number of affected rows (if supported by underlying database driver). */ protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con) { // initialize var to track total num of affected rows $affectedRows = 0; // first find the objects that are implicated by the $criteria $objects = NagiosServicePeer::doSelect($criteria, $con); foreach ($objects as $obj) { // delete related NagiosServiceCheckCommandParameter objects $c = new Criteria(NagiosServiceCheckCommandParameterPeer::DATABASE_NAME); $c->add(NagiosServiceCheckCommandParameterPeer::SERVICE, $obj->getId()); $affectedRows += NagiosServiceCheckCommandParameterPeer::doDelete($c, $con); // delete related NagiosServiceGroupMember objects $c = new Criteria(NagiosServiceGroupMemberPeer::DATABASE_NAME); $c->add(NagiosServiceGroupMemberPeer::SERVICE, $obj->getId()); $affectedRows += NagiosServiceGroupMemberPeer::doDelete($c, $con); // delete related NagiosServiceContactMember objects $c = new Criteria(NagiosServiceContactMemberPeer::DATABASE_NAME); $c->add(NagiosServiceContactMemberPeer::SERVICE, $obj->getId()); $affectedRows += NagiosServiceContactMemberPeer::doDelete($c, $con); // delete related NagiosServiceContactGroupMember objects $c = new Criteria(NagiosServiceContactGroupMemberPeer::DATABASE_NAME); $c->add(NagiosServiceContactGroupMemberPeer::SERVICE, $obj->getId()); $affectedRows += NagiosServiceContactGroupMemberPeer::doDelete($c, $con); // delete related NagiosDependency objects $c = new Criteria(NagiosDependencyPeer::DATABASE_NAME); $c->add(NagiosDependencyPeer::SERVICE, $obj->getId()); $affectedRows += NagiosDependencyPeer::doDelete($c, $con); // delete related NagiosDependencyTarget objects $c = new Criteria(NagiosDependencyTargetPeer::DATABASE_NAME); $c->add(NagiosDependencyTargetPeer::TARGET_SERVICE, $obj->getId()); $affectedRows += NagiosDependencyTargetPeer::doDelete($c, $con); // delete related NagiosEscalation objects $c = new Criteria(NagiosEscalationPeer::DATABASE_NAME); $c->add(NagiosEscalationPeer::SERVICE, $obj->getId()); $affectedRows += NagiosEscalationPeer::doDelete($c, $con); // delete related NagiosServiceTemplateInheritance objects $c = new Criteria(NagiosServiceTemplateInheritancePeer::DATABASE_NAME); $c->add(NagiosServiceTemplateInheritancePeer::SOURCE_SERVICE, $obj->getId()); $affectedRows += NagiosServiceTemplateInheritancePeer::doDelete($c, $con); } return $affectedRows; }
function addContactGroupByName($name) { $c = new Criteria(); $c->add(NagiosContactGroupPeer::NAME, $name); $c->setIgnoreCase(true); $contactgroup = NagiosContactGroupPeer::doSelectOne($c); if (!$contactgroup) { return false; } // Okay, contactgroup is valid, check for relationship $id = $this->getId(); if (!empty($id)) { $c = new Criteria(); $c->add(NagiosServiceContactGroupMemberPeer::TEMPLATE, $this->getId()); $c->add(NagiosServiceContactGroupMemberPeer::CONTACT_GROUP, $contactgroup->getId()); $relationship = NagiosServiceContactGroupMemberPeer::doSelectOne($c); if ($relationship) { return false; } } $relationship = new NagiosServiceContactGroupMember(); $relationship->setNagiosServiceTemplate($this); $relationship->setNagiosContactGroup($contactgroup); $relationship->save(); 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 = NagiosServiceContactGroupMemberPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setService($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setTemplate($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setContactGroup($arr[$keys[3]]); } }