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;
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 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;
 }
Beispiel #5
0
 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;
 }
Beispiel #6
0
         } 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);