Exemple #1
0
 public function setHostNotificationPeriodByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosTimeperiodPeer::NAME, $name);
     $timeperiod = NagiosTimeperiodPeer::doSelectOne($c);
     if (!empty($timeperiod)) {
         $this->setNagiosTimeperiodRelatedByHostNotificationPeriod($timeperiod);
         return true;
     }
     return false;
 }
 public function getByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosTimeperiodPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $timeperiod = NagiosTimeperiodPeer::doSelectOne($c);
     if (!$timeperiod) {
         return false;
     }
     return $timeperiod;
 }
 /**
  * Get the associated NagiosTimeperiod object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     NagiosTimeperiod The associated NagiosTimeperiod object.
  * @throws     PropelException
  */
 public function getNagiosTimeperiod(PropelPDO $con = null)
 {
     if ($this->aNagiosTimeperiod === null && $this->escalation_period !== null) {
         $c = new Criteria(NagiosTimeperiodPeer::DATABASE_NAME);
         $c->add(NagiosTimeperiodPeer::ID, $this->escalation_period);
         $this->aNagiosTimeperiod = NagiosTimeperiodPeer::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->aNagiosTimeperiod->addNagiosEscalations($this);
         		 */
     }
     return $this->aNagiosTimeperiod;
 }
Exemple #4
0
 function setNotificationPeriodByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosTimeperiodPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $command = NagiosTimeperiodPeer::doSelectOne($c);
     if (!$command) {
         return false;
     }
     $this->setNagiosTimeperiodRelatedByNotificationPeriod($command);
     $this->save();
     return true;
 }
Exemple #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;
 }
 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 Escalation uses a template: " . $values['use'][0]['value']);
         $template = NagiosServiceEscalationImporter::getTemplateByName($values['use'][0]['value']);
         if (empty($template)) {
             $job->addNotice("That template is not found yet. Setting this service escalation as queued.");
             return false;
         }
     }
     // Check time period existence
     if (isset($values['escalation_period'])) {
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $values['escalation_period'][0]['value']);
         $timePeriod = NagiosTimeperiodPeer::doSelectOne($c);
         if (empty($timePeriod)) {
             $job->addNotice("The time period specified by " . $values['escalation_period'][0]['value'] . " was not found.  Setting this service escalation as queued.");
             return false;
         }
         $timePeriod->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.  Setting this service escalation as queued.");
                 return false;
             }
             $contactgroup->clearAllReferences(true);
         }
     }
     // Check contacts
     if (isset($values['contacts'])) {
         foreach ($values['contacts'] as $contactValues) {
             $c = new Criteria();
             $c->add(NagiosContactPeer::NAME, $contactValues['value']);
             $contact = NagiosContactPeer::doSelectOne($c);
             if (empty($contact)) {
                 $job->addNotice("The contact specified by " . $contactValues['value'] . " was not found.  Setting this service escalation as queued.");
                 return false;
             }
             $contact->clearAllReferences(true);
         }
     }
     if (isset($values['host_name'])) {
         foreach ($values['host_name'] as $hostValues) {
             $service = NagiosServicePeer::getByHostAndDescription($hostValues['value'], $values['service_description'][0]['value']);
             if (empty($service)) {
                 $job->addNotice("The service specified by " . $hostValues['value'] . ":" . $values['service_description'][0]['value'] . " was not found.  Setting this host escalation as queued.");
                 return false;
             }
             $service->clearAllReferences(true);
         }
     }
     // Check for hostgroup_name
     if (isset($values['hostgroup_name'])) {
         foreach ($values['hostgroup_name'] as $hostgroupValues) {
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroupValues['value'], $values['service_description'][0]['value']);
             if (empty($service)) {
                 $job->addNotice("The service specified by hostgroup " . $hostgroupValues['value'] . ":" . $values['service_description'][0]['value'] . " was not found.  Setting this host escalation as queued.");
                 return false;
             }
             $service->clearAllReferences(true);
         }
     }
     return true;
 }
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $timePeriod = new NagiosTimeperiod();
     $segment = $this->getSegment();
     // First check if we have a use
     $useTemplate = $segment->get("use");
     if ($useTemplate) {
         // Okay, we need to check to see if we have an existing dependency
         $val = $useTemplate[0]['value'];
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $dependant = NagiosTimeperiodPeer::doSelectOne($c);
         if ($dependant) {
             // We need to add all the entries from that time period to ours.
             $entries = $dependant->getNagiosTimeperiodEntrys();
             foreach ($entries as $entry) {
                 $tempEntry = new NagiosTimeperiodEntry();
                 $tempEntry->setEntry($entry->getEntry());
                 $tempEntry->setValue($entry->getValue());
                 $timePeriod->addNagiosTimeperiodEntry($tempEntry);
             }
             $exclusions = $dependant->getNagiosTimeperiodExcludesRelatedByTimeperiodId();
             foreach ($exclusions as $exclusion) {
                 $tempExclusion = new NagiosTimeperiodExclude();
                 $tempExclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod);
                 $tempExclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($exclusion->getNagiosTimeperiodRelatedByExcludedTimePeriod);
             }
             $dependent->clearAllReferences(true);
         }
     }
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             if ($key == "exclude") {
                 continue;
             }
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if ($key == "use") {
                 continue;
             }
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($timePeriod, $this->fieldMethods[$key])) {
                     $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName);
                     if (!$config->getVar('continue_error')) {
                         return false;
                     }
                 } else {
                     call_user_method($this->fieldMethods[$key], $timePeriod, $value);
                 }
             } else {
                 // It's an entry. Let's rebuild the string and grab the entry and value
                 // This is pretty hackish
                 $pos = $this->preg_pos("/[0-9]{1,2}:[0-9]{1,2}/", $entry['text']);
                 // Look for the first 00:00
                 $tempLabel = trim(substr($entry['text'], 0, $pos - 1));
                 $commentPos = strpos($entry['text'], ";");
                 if ($commentPos === false) {
                     $commentLength = 0;
                 } else {
                     $commentLength = strlen(substr($entry['text'], $commentPos));
                 }
                 $valLength = strlen($entry['text']) - ($commentLength + $pos);
                 $tempValue = trim(substr($entry['text'], $pos, $valLength));
                 $tempEntry = new NagiosTimeperiodEntry();
                 $tempEntry->setEntry($tempLabel);
                 $tempEntry->setValue($tempValue);
                 $timePeriod->addNagiosTimeperiodEntry($tempEntry);
                 $tempEntry->clearAllReferences(true);
             }
         }
     }
     // Check to see if there is an exclusion
     $excludes = $segment->get("exclude");
     if ($excludes) {
         $val = $excludes[0]['value'];
         // Multiple timeperiods are seperated by a comma
         $timeperiods = explode(",", $val);
         if (count($timeperiods)) {
             foreach ($timeperiods as $timeperiod) {
                 $timeperiod = trim($timeperiod);
                 $c = new Criteria();
                 $c->add(NagiosTimeperiodPeer::NAME, $val);
                 $c->setIgnoreCase(true);
                 $target = NagiosTimeperiodPeer::doSelectOne($c);
                 if (!$target) {
                     $job->addLogEntry("Dependent exclude timeperiod " . $timeperiod . " not found. ", ImportLogEntry::TYPE_NOTICE);
                     return false;
                 } else {
                     $exclusion = new NagiosTimeperiodExclude();
                     $exclusion->setNagiosTimeperiodRelatedByTimeperiodId($timePeriod);
                     $exclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($target);
                     $exclusion->clearAllReferences(true);
                     $target->clearAllReferences(true);
                 }
             }
         }
     }
     $timePeriod->save();
     $timePeriod->clearAllReferences(true);
     $job->addNotice("NagiosTimePeriodImporter finished importing timeperiod: " . $timePeriod->getName());
     return true;
 }
 public function valid()
 {
     $values = $this->getSegment()->getValues();
     $job = $this->getEngine()->getJob();
     if (isset($values['use'])) {
         // We need to use a template
         $job->addNotice("This Service Dependency uses a template: " . $values['use'][0]['value']);
         $template = NagiosServiceDependencyImporter::getTemplateByName($values['use'][0]['value']);
         if (empty($template)) {
             $job->addNotice("That template is not found yet. Setting this service dependency as queued.");
             return false;
         }
     }
     // Check for hosts
     //
     if (!isset($values['service_description']) || !isset($values['dependent_service_description'])) {
         $job->addNotice("The service dependency does not have a service desciption assigned to it.");
         return false;
     }
     if (isset($values['dependent_host_name'])) {
         foreach ($values['dependent_host_name'] as $hostValues) {
             $service = NagiosServicePeer::getByHostAndDescription($hostValues['value'], $values['dependent_service_description'][0]['value']);
             if (empty($service)) {
                 $job->addNotice("The service specified by " . $hostValues['value'] . ":" . $values['dependent_service_description'][0]['value'] . " was not found.  Setting this service dependency as queued.");
                 return false;
             }
             $service->clearAllReferences(true);
         }
     }
     if (isset($values['host_name'])) {
         foreach ($values['host_name'] as $hostValues) {
             $service = NagiosServicePeer::getByHostAndDescription($hostValues['value'], $values['dependent_service_description'][0]['value']);
             if (empty($service)) {
                 $job->addNotice("The service specified by " . $hostValues['value'] . ":" . $values['dependent_service_description'][0]['value'] . " was not found.  Setting this service dependency as queued.");
                 return false;
             }
             $service->clearAllReferences(true);
         }
     }
     // Check for hostgroup_name
     if (isset($values['hostgroup_name'])) {
         foreach ($values['hostgroup_name'] as $hostgroupValues) {
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroupValues['value'], $values['dependent_service_description'][0]['value']);
             if (empty($service)) {
                 $job->addNotice("The service specified by hostgroup " . $hostgroupValues['value'] . ":" . $values['dependent_service_description'][0]['value'] . " was not found.  Setting this service dependency as queued.");
                 return false;
             }
             $service->clearAllReferences(true);
         }
     }
     if (isset($values['dependent_hostgroup_name'])) {
         foreach ($values['dependent_hostgroup_name'] as $hostgroupValues) {
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroupValues['value'], $values['dependent_service_description'][0]['value']);
             if (empty($service)) {
                 $job->addNotice("The service specified by hostgroup " . $hostgroupValues['value'] . ":" . $values['dependent_service_description'][0]['value'] . " was not found.  Setting this service dependency as queued.");
                 return false;
             }
             $service->clearAllReferences(true);
         }
     }
     // Check time period existence
     if (isset($values['dependency_period'])) {
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $values['dependency_period'][0]['value']);
         $timePeriod = NagiosTimeperiodPeer::doSelectOne($c);
         if (empty($timePeriod)) {
             $job->addNotice("The time period specified by " . $values['dependency_period'][0]['value'] . " was not found.  Setting this host dependency as queued.");
             return false;
         }
         $timePeriod->clearAllReferences(true);
     }
     return true;
 }
 public function valid()
 {
     $values = $this->getSegment()->getValues();
     $job = $this->getEngine()->getJob();
     if (isset($values['use'])) {
         // We need to use a template
         $job->addNotice("This Host Dependency uses a template: " . $values['use'][0]['value']);
         $template = NagiosHostDependencyImporter::getTemplateByName($values['use'][0]['value']);
         if (empty($template)) {
             $job->addNotice("That template is not found yet. Setting this host dependency as queued.");
             return false;
         }
     }
     // Check for hosts
     if (isset($values['dependent_host_name'])) {
         foreach ($values['dependent_host_name'] as $hostValues) {
             $host = NagiosHostPeer::getByName($hostValues['value']);
             if (empty($host)) {
                 $job->addNotice("The host specified by " . $hostValues['value'] . " was not found.  Setting this host dependency as queued.");
                 return false;
             }
             $host->clearAllReferences(true);
         }
     }
     if (isset($values['host_name'])) {
         foreach ($values['host_name'] as $hostValues) {
             $host = NagiosHostPeer::getByName($hostValues['value']);
             if (empty($host)) {
                 $job->addNotice("The host specified by " . $hostValues['value'] . " was not found.  Setting this host dependency as queued.");
                 return false;
             }
             $host->clearAllReferences(true);
         }
     }
     // Check for hostgroup_name
     if (isset($values['hostgroup_name'])) {
         foreach ($values['hostgroup_name'] as $hostgroupValues) {
             $hostgroup = NagiosHostgroupPeer::getByName($hostgroupValues['value']);
             if (empty($hostgroup)) {
                 $job->addNotice("The host group specified by " . $hostgroupValues['value'] . " was not found.  Setting this host dependency as queued.");
                 return false;
             }
             $hostgroup->clearAllReferences(true);
         }
     }
     if (isset($values['dependent_hostgroup_name'])) {
         foreach ($values['dependent_hostgroup_name'] as $hostgroupValues) {
             $hostgroup = NagiosHostgroupPeer::getByName($hostgroupValues['value']);
             if (empty($hostgroup)) {
                 $job->addNotice("The host group specified by " . $hostgroupValues['value'] . " was not found.  Setting this host dependency as queued.");
                 return false;
             }
             $hostgroup->clearAllReferences(true);
         }
     }
     // Check time period existence
     if (isset($values['dependency_period'])) {
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $values['dependency_period'][0]['value']);
         $timePeriod = NagiosTimeperiodPeer::doSelectOne($c);
         if (empty($timePeriod)) {
             $job->addNotice("The time period specified by " . $values['dependency_period'][0]['value'] . " was not found.  Setting this host dependency as queued.");
             return false;
         }
         $timePeriod->clearAllReferences(true);
     }
     return true;
 }
 public function valid()
 {
     $values = $this->getSegment()->getValues();
     $job = $this->getEngine()->getJob();
     if (isset($values['use'])) {
         // We need to use a template
         $job->addNotice("This Contact uses a template: " . $values['use'][0]['value']);
         $template = NagiosContactImporter::getTemplateByName($values['use'][0]['value']);
         if (empty($template)) {
             $job->addNotice("That template is not found yet. Setting this contact as queued.");
             return false;
         }
     }
     // Check time period existence
     if (isset($values['host_notification_period'])) {
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $values['host_notification_period'][0]['value']);
         $timePeriod = NagiosTimeperiodPeer::doSelectOne($c);
         if (empty($timePeriod)) {
             $job->addNotice("The time period specified by " . $values['host_notification_period'][0]['value'] . " was not found.  Setting this contact as queued.");
             return false;
         }
         $timePeriod->clearAllReferences(true);
     }
     if (isset($values['service_notification_period'])) {
         $c = new Criteria();
         $c->add(NagiosTimeperiodPeer::NAME, $values['service_notification_period'][0]['value']);
         $timePeriod = NagiosTimeperiodPeer::doSelectOne($c);
         if (empty($timePeriod)) {
             $job->addNotice("The time period specified by " . $values['service_notification_period'][0]['value'] . " was not found.  Setting this contact as queued.");
             return false;
         }
         $timePeriod->clearAllReferences(true);
     }
     // Check command existence
     if (isset($values['service_notification_commands'])) {
         foreach ($values['service_notification_commands'] as $commandValues) {
             $c = new Criteria();
             $c->add(NagiosCommandPeer::NAME, $commandValues['value']);
             $command = NagiosCommandPeer::doSelectOne($c);
             if (empty($command)) {
                 $job->addNotice("The command specified by " . $commandValues['value'] . " was not found.  Setting this contact as queued.");
                 return false;
             }
             $command->clearAllReferences(true);
         }
     }
     if (isset($values['host_notification_commands'])) {
         foreach ($values['host_notification_commands'] as $commandValues) {
             $c = new Criteria();
             $c->add(NagiosCommandPeer::NAME, $commandValues['value']);
             $command = NagiosCommandPeer::doSelectOne($c);
             if (empty($command)) {
                 $job->addNotice("The command specified by " . $commandValues['value'] . " was not found.  Setting this contact as queued.");
                 return false;
             }
             $command->clearAllReferences(true);
         }
     }
     // Check contact groups
     if (isset($values['contactgroups'])) {
         foreach ($values['contactgroups'] 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.  Setting this contact as queued.");
                 return false;
             }
             $contactgroup->clearAllReferences(true);
         }
     }
     return true;
 }