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; }
$host->setNotificationPeriod(NagiosTimeperiodPeer::retrieveByPK($modifiedData['notification_period'])->getId()); } else { $host->setNotificationPeriod(null); } $host->save(); // Remove session data unset($modifiedData); $success = "Host modified."; unset($_GET['edit']); } } else { if ($_POST['request'] == 'add_member_command') { $c = new Criteria(); $c->add(NagiosHostgroupMembershipPeer::HOST, $_GET['id']); $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $modifiedData['hostgroup_id']); $tempMembership = NagiosHostgroupMembershipPeer::doSelectOne($c); if ($tempMembership) { $error = "That host group already exists in that list!"; } else { $membership = new NagiosHostgroupMembership(); $membership->setNagiosHost($host); $membership->setHostgroup($modifiedData['hostgroup_id']); $membership->save(); $success = "Host Added To Host Group."; unset($modifiedData); } } else { if ($_POST['request'] == 'command_parameter_add') { // All is well for error checking, modify the command. $lilac->add_host_command_parameter($_GET['id'], $modifiedData); // Remove session data
public function addMemberByName($name) { // Support for adding ALL hosts if ($name == "*") { $hosts = NagiosHostPeer::doSelect(new Criteria()); foreach ($hosts as $host) { $this->addMemberByName($host->getName()); } return true; } $host = NagiosHostPeer::getByName($name); if (!$host) { return false; } $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) { return true; } // Already exists. } // Create new relationship $relationship = new NagiosHostgroupMembership(); $relationship->setNagiosHost($host); $relationship->setNagiosHostgroup($this); $relationship->save(); return true; }