public function getByName($name) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $name); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { return false; } return $command; }
public function import() { $job = $this->getEngine()->getJob(); $config = $this->getEngine()->getConfig(); $command = new NagiosCommand(); $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(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $dependant = NagiosCommandPeer::doSelectOne($c); if ($dependant) { $command->setLine($dependant->getLine()); } $dependant->clearAllReferences(true); } $values = $segment->getValues(); $fileName = $segment->getFilename(); $commandLine = array(); foreach ($values as $key => $entries) { foreach ($entries as $entry) { $value = $entry['value']; $lineNum = $entry['line']; if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') { if ($key == "command_line") { // Combine into our line array $commandLine[] = $value; continue; } // Okay, let's check that the method DOES exist if (!method_exists($command, $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], $command, $value); } } } } // re-assemble command $commandLine = implode(',', $commandLine); $command->setLine($commandLine); $command->save(); $command->clearAllReferences(true); $job->addNotice("NagiosCommandImporter finished importing command: " . $command->getName()); return true; }
public function addHostNotificationCommandByName($name) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $name); $command = NagiosCommandPeer::doSelectOne($c); if (!empty($command)) { $notificationCommand = new NagiosContactNotificationCommand(); $notificationCommand->setType("host"); $notificationCommand->setNagiosContact($this); $notificationCommand->setNagiosCommand($command); $notificationCommand->save(); return true; } return false; }
/** * Get the associated NagiosCommand object * * @param PropelPDO Optional Connection object. * @return NagiosCommand The associated NagiosCommand object. * @throws PropelException */ public function getNagiosCommandRelatedByEventHandler(PropelPDO $con = null) { if ($this->aNagiosCommandRelatedByEventHandler === null && $this->event_handler !== null) { $c = new Criteria(NagiosCommandPeer::DATABASE_NAME); $c->add(NagiosCommandPeer::ID, $this->event_handler); $this->aNagiosCommandRelatedByEventHandler = NagiosCommandPeer::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->aNagiosCommandRelatedByEventHandler->addNagiosHostsRelatedByEventHandler($this); */ } return $this->aNagiosCommandRelatedByEventHandler; }
function setEventHandlerByName($name) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $name); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { return false; } $this->setNagiosCommandRelatedByEventHandler($command); $this->save(); 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 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() { // We need to check to see if we have dependency issues, if so, state we are invalid at this time $segment = $this->getSegment(); $job = $this->getEngine()->getJob(); $val = $segment->get("ocsp_command"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find ocsp_command command: " . $val); return false; } $command->clearAllReferences(true); } $val = $segment->get("ohcp_command"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find ohcp_command command: " . $val); return false; } $command->clearAllReferences(true); } $val = $segment->get("host_perfdata_command"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find host_perfdata_command command: " . $val); return false; } $command->clearAllReferences(true); } $val = $segment->get("service_perfdata_command"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find service_perfdata_command command: " . $val); return false; } $command->clearAllReferences(true); } $val = $segment->get("host_perfdata_file_processing_command"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find host_perfdata_file_processing_command command: " . $val); return false; } $command->clearAllReferences(true); } $val = $segment->get("service_perfdata_file_processing_command"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find service_perfdata_file_processing command: " . $val); return false; } $command->clearAllReferences(true); } $val = $segment->get("global_service_event_handler"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find global_service_event_handler command: " . $val); return false; } $command->clearAllReferences(true); } $val = $segment->get("global_host_event_handler"); $val = $val[0]['value']; if ($val) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $val); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if (!$command) { $job->addNotice("Main Configuration not yet valid. Could not find global_host_event_handler command: " . $val); return false; } $command->clearAllReferences(true); } return true; }
public function setServicePerfdataFileProcessingCommandByName($command_name) { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME); $c->setIgnoreCase(true); $command = NagiosCommandPeer::doSelectOne($c); if ($command) { $this->setServicePerfdataFileProcessingCommand($command->getId()); return true; } return false; }
$_GET['command_add'] = 1; } else { // All is well for error checking, add the command into the db. $lilac->add_command($_POST['command_manage']); // Remove session data unset($command); $success = "Command added."; } } } else { if ($_POST['request'] == 'modify_command') { $c = new Criteria(); $c->add(NagiosCommandPeer::NAME, $_POST['command_manage']['command_name']); $c->setIgnoreCase(true); $c->add(NagiosCommandPeer::ID, $command->getId(), "!="); $duplicate = NagiosCommandPeer::doSelectOne($c); if ($duplicate && $command->getId() != $duplicate->getId()) { $error = "A command with that name already exists!"; } else { // All is well for error checking, modify the command. $command->updateFromArray($_POST['command_manage']); $command->save(); $success = "Command modified."; unset($command); } } } } // Get list of commands $lilac->return_command_list($command_list); $numOfCommands = count($command_list);
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; }