예제 #1
0
 public function setEscalationPeriodByName($name)
 {
     $timeperiod = NagiosTimeperiodPeer::getByName($name);
     if (!$timeperiod) {
         return false;
     }
     return $timeperiod;
 }
예제 #2
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosTimePeriodExporter attempting to export time period configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosTimePeriodExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $timeperiods = NagiosTimeperiodPeer::doSelect(new Criteria());
     foreach ($timeperiods as $timeperiod) {
         fputs($fp, "define timeperiod {\n");
         $finalArray = array();
         $values = $timeperiod->toArray(BasePeer::TYPE_FIELDNAME);
         foreach ($values as $key => $value) {
             if ($key == 'id' || $key == 'description') {
                 continue;
             }
             if ($key == 'name') {
                 $key = 'timeperiod_name';
             }
             if ($value === null) {
                 continue;
             }
             if ($value === false) {
                 $value = '0';
             }
             $finalArray[$key] = $value;
         }
         foreach ($finalArray as $key => $val) {
             fputs($fp, "\t" . $key . "\t" . $val . "\n");
         }
         // Get entries
         $entries = $timeperiod->getNagiosTimeperiodEntrys();
         foreach ($entries as $entry) {
             fputs($fp, "\t" . $entry->getEntry() . "\t" . $entry->getValue() . "\n");
         }
         // Get exclusions
         $exclusions = $timeperiod->getNagiosTimeperiodExcludesRelatedByTimeperiodId();
         if (count($exclusions)) {
             fputs($fp, "\texclude\t");
             $first = true;
             foreach ($exclusions as $exclude) {
                 if (!$first) {
                     fputs($fp, ",");
                 } else {
                     $first = false;
                 }
                 fputs($fp, $exclude->getNagiosTimeperiodRelatedByExcludedTimeperiod()->getName());
             }
             fputs($fp, "\n");
         }
         fputs($fp, "}\n");
         fputs($fp, "\n");
     }
     $job->addNotice("NagiosTimePeriodExporter complete.");
     return true;
 }
예제 #3
0
 public function setDependencyPeriodByName($name)
 {
     $timeperiod = NagiosTimeperiodPeer::getByName($name);
     if (!$timeperiod) {
         return false;
     }
     $this->setNagiosTimeperiod($timeperiod);
     $this->save();
 }
예제 #4
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;
 }
예제 #5
0
 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;
 }
예제 #6
0
 public function import()
 {
     $job = $this->getJob();
     $job->addNotice("FruityImportEngine beginning import...");
     $config = $this->getConfig();
     $job->addNotice("Removing existing Nagios objects.");
     NagiosTimeperiodPeer::doDeleteAll();
     NagiosCommandPeer::doDeleteAll();
     NagiosContactPeer::doDeleteAll();
     NagiosContactGroupPeer::doDeleteAll();
     NagiosHostTemplatePeer::doDeleteAll();
     NagiosHostPeer::doDeleteAll();
     NagiosHostgroupPeer::doDeleteAll();
     NagiosServiceGroupPeer::doDeleteAll();
     NagiosServiceTemplatePeer::doDeleteAll();
     NagiosServicePeer::doDeleteAll();
     NagiosDependencyPeer::doDeleteAll();
     NagiosDependencyTargetPeer::doDeleteAll();
     NagiosEscalationPeer::doDeleteAll();
     NagiosBrokerModulePeer::doDeleteAll();
     NagiosMainConfigurationPeer::doDeleteAll();
     NagiosCgiConfigurationPeer::doDeleteAll();
     $importer = new FruityResourceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCgiImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCommandImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityTimeperiodImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityContactImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityDependencyImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityEscalationImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityMainImporter($this, $this->dbConn);
     $importer->import();
     $job->addNotice("FruityImportEngine completed job.");
     return true;
 }
예제 #7
0
 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");
 }
예제 #8
0
 public function init()
 {
     $job = $this->getJob();
     $job->addNotice("NagiosImportEngine Starting...");
     $config = $this->getConfig();
     // Attempt to try and open each config file
     $job->addNotice("Attempting to open " . $config->GetVar('config_file'));
     if (!file_exists($config->getVar('config_file')) || !@fopen($config->getVar('config_file'), "r")) {
         $job->addError("Failed to open " . $config->getVar('config_file'));
         return false;
     }
     $job->addNotice("Attempting to open " . $config->GetVar('cgi_file'));
     if (!file_exists($config->getVar('cgi_file')) || !@fopen($config->getVar('cgi_file'), "r")) {
         $job->addError("Failed to open " . $config->getVar('cgi_file'));
         return false;
     }
     $job->addNotice("Attempting to open " . $config->GetVar('resources_file'));
     if (!file_exists($config->getVar('resources_file')) || !@fopen($config->getVar('resources_file'), "r")) {
         $job->addError("Failed to open " . $config->getVar('resources_file'));
         return false;
     }
     $job->addNotice("Config passed sanity check for Nagios import.  Finished initializing.");
     if ($config->getVar('delete_existing')) {
         $job->addNotice("Removing existing Nagios objects.");
         NagiosTimeperiodPeer::doDeleteAll();
         NagiosCommandPeer::doDeleteAll();
         NagiosContactPeer::doDeleteAll();
         NagiosContactGroupPeer::doDeleteAll();
         NagiosHostTemplatePeer::doDeleteAll();
         NagiosHostPeer::doDeleteAll();
         NagiosHostgroupPeer::doDeleteAll();
         NagiosServiceGroupPeer::doDeleteAll();
         NagiosServiceTemplatePeer::doDeleteAll();
         NagiosServicePeer::doDeleteAll();
         NagiosDependencyPeer::doDeleteAll();
         NagiosDependencyTargetPeer::doDeleteAll();
         NagiosEscalationPeer::doDeleteAll();
     }
     return true;
 }
예제 #9
0
파일: about.php 프로젝트: Evolix/lilac
Lilac Networks can help support your implementation of Lilac & Nagios.  For commercial support of your open source monitoring infrastructure, review our service offerings at <a href="http://www.lilacnetworks.com/services/">www.lilacnetworks.com</a>.  For community support for Lilac Configurator, refer to the community site at <a href="http://www.lilacplatform.com">www.lilacplatform.com</a>.
</p>
<p>
<h2>Statistics</h2>
<table class="statistics">
	<tr>
		<td><strong>Total Nagios Commands:</strong></td>
		<td><?php 
echo NagiosCommandPeer::doCount(new Criteria());
?>
</td>
	</tr>
	<tr class="odd">
		<td><strong>Total Nagios Time Periods:</strong></td>
		<td><?php 
echo NagiosTimeperiodPeer::doCount(new Criteria());
?>
</td>
	</tr>
	<tr>
		<td><strong>Total Nagios Contacts:</strong></td>
		<td><?php 
echo NagiosContactPeer::doCount(new Criteria());
?>
</td>
	</tr>
	<tr class="odd">
		<td><strong>Total Nagios Contact Groups:</strong></td>
		<td><?php 
echo NagiosContactGroupPeer::doCount(new Criteria());
?>
예제 #10
0
 /**
  * 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 = NagiosTimeperiodPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setName($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setAlias($arr[$keys[2]]);
     }
 }
예제 #11
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosContactExporter attempting to export contact configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosContactExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $contacts = NagiosContactPeer::doSelect(new Criteria());
     foreach ($contacts as $contact) {
         fputs($fp, "define contact {\n");
         $finalArray = array();
         $values = $contact->toArray(BasePeer::TYPE_FIELDNAME);
         foreach ($values as $key => $value) {
             if ($key == 'id' || $key == 'host_notification_on_down' || $key == 'host_notification_on_unreachable' || $key == 'host_notification_on_recovery' || $key == 'host_notification_on_flapping' || $key == 'host_notification_on_scheduled_downtime' || $key == 'service_notification_on_warning' || $key == 'service_notification_on_unknown' || $key == 'service_notification_on_critical' || $key == 'service_notification_on_recovery' || $key == 'service_notification_on_flapping') {
                 continue;
             }
             if ($key == 'name') {
                 $key = 'contact_name';
             }
             if ($value === null) {
                 continue;
             }
             if ($value === false) {
                 $value = '0';
             }
             if ($key == "host_notification_period" || $key == "service_notification_period") {
                 $timeperiod = NagiosTimeperiodPeer::retrieveByPK($value);
                 if (!$timeperiod) {
                     $job->addError("Unable to find timeperiod with id: " . $value . " for " . $key);
                     return false;
                 }
                 $value = $timeperiod->getName();
             }
             $finalArray[$key] = $value;
         }
         foreach ($finalArray as $key => $val) {
             fputs($fp, "\t" . $key . "\t" . $val . "\n");
         }
         // Notification On changes
         if (!$contact->getHostNotificationOnDown() && !$contact->getHostNotificationOnUnreachable() && !$contact->getHostNotificationOnRecovery() && !$contact->getHostNotificationOnFlapping()) {
             // Do nothing
         } else {
             fputs($fp, "\thost_notification_options\t");
             if ($contact->getHostNotificationOnDown()) {
                 fputs($fp, "d");
                 if ($contact->getHostNotificationOnUnreachable() || $contact->getHostNotificationOnRecovery() || $contact->getHostNotificationOnFlapping() || $contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnUnreachable()) {
                 fputs($fp, "u");
                 if ($contact->getHostNotificationOnRecovery() || $contact->getHostNotificationOnFlapping() || $contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnRecovery()) {
                 fputs($fp, "r");
                 if ($contact->getHostNotificationOnFlapping() || $contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnFlapping()) {
                 fputs($fp, "f");
                 if ($contact->getHostNotificationOnScheduledDowntime()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getHostNotificationOnScheduledDowntime()) {
                 fputs($fp, "s");
             }
             fputs($fp, "\n");
         }
         if (!$contact->getServiceNotificationOnWarning() && !$contact->getServiceNotificationOnUnknown() && !$contact->getServiceNotificationOnCritical() && !$contact->getServiceNotificationOnRecovery()) {
             // Do nothing
         } else {
             fputs($fp, "\tservice_notification_options\t");
             if ($contact->getServiceNotificationOnWarning()) {
                 fputs($fp, "w");
                 if ($contact->getServiceNotificationOnUnknown() || $contact->getServiceNotificationOnCritical() || $contact->getServiceNotificationOnRecovery()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnUnknown()) {
                 fputs($fp, "u");
                 if ($contact->getServiceNotificationOnCritical() || $contact->getServiceNotificationOnRecovery()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnCritical()) {
                 fputs($fp, "c");
                 if ($contact->getServiceNotificationOnRecovery() || $contact->getServiceNotificationOnFlapping()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnRecovery()) {
                 fputs($fp, "r");
                 if ($contact->getServiceNotificationOnFlapping()) {
                     fputs($fp, ",");
                 }
             }
             if ($contact->getServiceNotificationOnFlapping()) {
                 fputs($fp, "f");
             }
             fputs($fp, "\n");
         }
         // Get notification commands
         $c = new Criteria();
         $c->add(NagiosContactNotificationCommandPeer::TYPE, "host");
         $hostNotificationCommands = $contact->getNagiosContactNotificationCommands($c);
         $c = new Criteria();
         $c->add(NagiosContactNotificationCommandPeer::TYPE, "service");
         $serviceNotificationCommands = $contact->getNagiosContactNotificationCommands($c);
         if (count($hostNotificationCommands)) {
             fputs($fp, "\thost_notification_commands\t");
             $first = true;
             foreach ($hostNotificationCommands as $command) {
                 if (!$first) {
                     fputs($fp, ",");
                 } else {
                     $first = false;
                 }
                 fputs($fp, $command->getNagiosCommand()->getName());
             }
             fputs($fp, "\n");
         }
         if (count($serviceNotificationCommands)) {
             fputs($fp, "\tservice_notification_commands\t");
             $first = true;
             foreach ($serviceNotificationCommands as $command) {
                 if (!$first) {
                     fputs($fp, ",");
                 } else {
                     $first = false;
                 }
                 fputs($fp, $command->getNagiosCommand()->getName());
             }
             fputs($fp, "\n");
         }
         // Get Addresses
         $c = new Criteria();
         $c->addAscendingOrderByColumn(NagiosContactAddressPeer::ID);
         $addresses = $contact->getNagiosContactAddresss($c);
         if (count($addresses)) {
             $counter = 1;
             foreach ($addresses as $address) {
                 fputs($fp, "\taddress" . $counter++ . "\t" . $address->getAddress() . "\n");
             }
         }
         fputs($fp, "}\n");
         fputs($fp, "\n");
     }
     $job->addNotice("NagiosContactExporter complete.");
     return true;
 }
예제 #12
0
 /**
  * Enter description here...
  *
  * @param NagiosEscalation $escalation
  * @param unknown_type $type
  * @param unknown_type $targetObj
  * @param unknown_type $subObj
  */
 private function _exportEscalation($escalation, $type, $targetObj, $subObj = null)
 {
     global $lilac;
     $fp = $this->getOutputFile();
     if ($type == "host") {
         $host = $targetObj;
         fputs($fp, "define hostescalation {\n");
         fputs($fp, "\thost_name\t" . $host->getName() . "\n");
     } else {
         if ($type == 'service') {
             $host = $subObj;
             $service = $targetObj;
             fputs($fp, "define serviceescalation {\n");
             fputs($fp, "\thost_name\t" . $host->getName() . "\n");
             fputs($fp, "\tservice_description\t" . $service->getDescription() . "\n");
         } else {
             if ($type == "hostgroup") {
                 $hostgroup = $targetObj;
                 fputs($fp, "define hostescalation {\n");
                 fputs($fp, "\thostgroup_name\t" . $hostgroup->getName() . "\n");
             }
         }
     }
     // Get contacts
     $contacts = $escalation->getNagiosEscalationContacts();
     if (count($contacts)) {
         fputs($fp, "\tcontacts\t");
         $first = true;
         foreach ($contacts as $membership) {
             $contact = $membership->getNagiosContact();
             if (!$first) {
                 fputs($fp, ",");
             } else {
                 $first = false;
             }
             fputs($fp, $contact->getName());
         }
         fputs($fp, "\n");
     }
     // Get contact groups
     $contactGroups = $escalation->getNagiosEscalationContactgroups();
     if (count($contactGroups)) {
         fputs($fp, "\tcontact_groups\t");
         $first = true;
         foreach ($contactGroups as $membership) {
             $contactGroup = $membership->getNagiosContactGroup();
             if (!$first) {
                 fputs($fp, ",");
             } else {
                 $first = false;
             }
             fputs($fp, $contactGroup->getName());
         }
         fputs($fp, "\n");
     }
     if ($escalation->getEscalationPeriod()) {
         fputs($fp, "\tescalation_period\t");
         $timePeriod = NagiosTimeperiodPeer::retrieveByPK($escalation->getEscalationPeriod());
         fputs($fp, $timePeriod->getName() . "\n");
     }
     if ($escalation->getFirstNotification()) {
         fputs($fp, "\tfirst_notification\t" . $escalation->getFirstNotification() . "\n");
     }
     if ($escalation->getLastNotification()) {
         fputs($fp, "\tlast_notification\t" . $escalation->getLastNotification() . "\n");
     }
     if ($escalation->getNotificationInterval()) {
         fputs($fp, "\tnotification_interval\t" . $escalation->getNotificationInterval() . "\n");
     }
     if ($escalation->getEscalationOptionsUp() != null || $escalation->getEscalationOptionsDown() != null || $escalation->getEscalationOptionsUnreachable() != null || $escalation->getEscalationOptionsOk() != null || $escalation->getEscalationOptionsWarning() != null || $escalation->getEscalationOptionsUnknown() != null || $escalation->getEscalationOptionsCritical() != null) {
         fputs($fp, "\tescalation_options\t");
         if ($escalation->getEscalationOptionsUp()) {
             fputs($fp, "r");
             if ($escalation->getEscalationOptionsDown() || $escalation->getEscalationOptionsUnreachable() || $escalation->getEscalationOptionsOk() || $escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsDown()) {
             fputs($fp, "d");
             if ($escalation->getEscalationOptionsUnreachable() || $escalation->getEscalationOptionsOk() || $escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsUnreachable()) {
             fputs($fp, "u");
             if ($escalation->getEscalationOptionsOk() || $escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsOk()) {
             fputs($fp, "o");
             if ($escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsWarning()) {
             fputs($fp, "w");
             if ($escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsUnknown()) {
             fputs($fp, "u");
             if ($escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsCritical()) {
             fputs($fp, "c");
         }
         fputs($fp, "\n");
     }
     fputs($fp, "}\n");
     fputs($fp, "\n");
 }
예제 #13
0
파일: timeperiod.php 프로젝트: Evolix/lilac
                            $value = '';
                        }
                    }
                }
            }
        } else {
            if ($_POST['request'] == 'exclusion_add') {
                // first hceck to see if the exclusion exists.
                $c = new Criteria();
                $c->add(NagiosTimeperiodExcludePeer::TIMEPERIOD_ID, $timeperiod->getId());
                $c->add(NagiosTimeperiodExcludePeer::EXCLUDED_TIMEPERIOD, $_POST['timeperiod_manage']['exclusion_add']['timeperiod_id']);
                $tempExclusion = NagiosTimeperiodExcludePeer::doSelectOne($c);
                if ($tempExclusion) {
                    $error = "That exclusion already exists.";
                } else {
                    $targetTimeperiod = NagiosTimeperiodPeer::retrieveByPK($_POST['timeperiod_manage']['exclusion_add']['timeperiod_id']);
                    if (!$targetTimeperiod) {
                        $error = "That timeperiod is not in the system.";
                    } else {
                        $tempExclusion = new NagiosTimeperiodExclude();
                        $tempExclusion->setNagiosTimeperiodRelatedByExcludedTimeperiod($targetTimeperiod);
                        $tempExclusion->setNagiosTimeperiodRelatedByTimeperiodId($timeperiod);
                        $tempExclusion->save();
                        $success = "Exclusion added.";
                    }
                }
            }
        }
    }
}
// Create subnav
예제 #14
0
                $error = "A time period with that name already exists!";
            } else {
                // All is well for error checking, add the command into the db.
                $timeperiod = new NagiosTimeperiod();
                $timeperiod->setName($_POST['timeperiod_manage']['timeperiod_name']);
                $timeperiod->setAlias($_POST['timeperiod_manage']['alias']);
                $timeperiod->save();
                // Remove session data
                unset($_GET['timeperiod_add']);
                $success = "Time period added.";
            }
        }
    }
}
if (isset($_GET['timeperiod_id'])) {
    $timeperiod = NagiosTimeperiodPeer::retrieveByPK($_GET['timeperiod_id']);
}
// Get list of commands
$lilac->return_period_list($period_list);
$numOfPeriods = count($period_list);
print_header("Time Period Editor");
if (isset($_GET['timeperiod_id']) || isset($_GET['timeperiod_add'])) {
    if (isset($_GET['timeperiod_id'])) {
        print_window_header("Modify A Time Period", "100%");
    } else {
        print_window_header("Add A Time Period", "100%");
    }
    ?>
		<form name="timeperiod_form" method="post" action="timeperiods.php?timeperiod_add=1">
			<?php 
    if (isset($timeperiod)) {
 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;
 }
예제 #16
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 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;
 }
예제 #17
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;
 }
예제 #18
0
 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;
 }
예제 #19
0
 private function importService($serviceData)
 {
     $job = $this->getEngine()->getJob();
     $newService = new NagiosService();
     // Check to see if host or host template exists first
     if (!empty($serviceData['host_id'])) {
         $hostName = $this->getHostNameById($serviceData['host_id']);
         if (!$hostName) {
             $job->addNotice("Fruity Service Importer: Failed to find host with id: " . $serviceData['host_id']);
             return true;
         }
         $host = NagiosHostPeer::getByName($hostName);
         if (!$host) {
             $job->addNotice("Fruity Service Importer: Failed to find host with name: " . $hostName);
             return true;
         }
         $newService->setHost($host->getId());
     } else {
         if (!empty($serviceData['host_template_id'])) {
             $hostTemplateName = $this->getHostTemplateNameById($serviceData['host_template_id']);
             if (!$hostTemplateName) {
                 $job->addNotice("Fruity Service Importer: Failed to find host template with id: " . $serviceData['host_template_id']);
                 return true;
             }
             $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
             if (!$hostTemplate) {
                 $job->addNotice("Fruity Service Importer: Failed to find host template with name: " . $hostTemplateName);
                 return true;
             }
             $newService->setHostTemplate($hostTemplate->getId());
         } else {
             if (!empty($serviceData['hostgroup_id'])) {
                 $hostgroupName = $this->getHostGroupNameById($serviceData['hostgroup_id']);
                 if (!$hostgroupName) {
                     $job->addNotice("Fruity Service Importer: Failed to find host group with id: " . $serviceData['host_template_id']);
                     return true;
                 }
                 $hostgroup = NagiosHostGroupPeer::getByName($hostgroupName);
                 if (!$hostgroup) {
                     $job->addNotice("Fruity Service Importer: Failed to find host group with name: " . $hostGroupName);
                     return true;
                 }
                 $newService->setHostgroup($hostgroup->getId());
             }
         }
     }
     // Check to see if we need the template
     if (!empty($serviceData['use_template_id'])) {
         $name = $this->getServiceTemplateNameById($serviceData['use_template_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Service Importer:  Could not find template with id: " . $serviceData['use_template_id'] . ". Aborting it's import.");
             return false;
         } else {
             // Okay, we got the name, does this template exist?
             $template = NagiosServiceTemplatePeer::getByName($name);
             if (!$template) {
                 return false;
             } else {
                 // Create a new inheritance relationship
                 $inheritance = new NagiosServiceTemplateInheritance();
                 $inheritance->setNagiosServiceTemplateRelatedByTargetTemplate($template);
                 $inheritance->setNagiosService($newService);
                 try {
                     $inheritance->save();
                 } catch (Exception $e) {
                     $job->addNotice("Fruity Service Template Importer:  Cannot add inheritance from " . $template->getName() . " to " . $newService->getName());
                 }
             }
         }
     }
     // Okay, start 'er up!
     foreach ($serviceData as $key => $val) {
         unset($name);
         if ($key == "service_template_id" || $key == "use_template_id" || $key == "template_name" || $key == "host_id" || $key == "hostgroup_id" || $key == "host_template_id" || $key == "service_id") {
             continue;
         }
         if ($key == "service_description") {
             $key = "description";
         }
         if ($key == "notification_options_warning") {
             $key = "notification_on_warning";
         }
         if ($key == "notification_options_unknown") {
             $key = "notification_on_unknown";
         }
         if ($key == "notification_options_critical") {
             $key = "notification_on_critical";
         }
         if ($key == "notification_options_recovery") {
             $key = "notification_on_recovery";
         }
         if ($key == "notification_options_flapping") {
             $key = "notification_on_flapping";
         }
         if ($key == "stalking_options_warning") {
             $key = "stalking_on_warning";
         }
         if ($key == "stalking_options_unknown") {
             $key = "stalking_on_unknown";
         }
         if ($key == "stalking_options_critical") {
             $key = "stalking_on_critical";
         }
         if ($key == "stalking_options_ok") {
             $key = "stalking_on_ok";
         }
         if ($key == "max_check_attempts") {
             $key = "maximum_check_attempts";
         }
         if ($key == "retry_check_interval") {
             $key = "retry_interval";
         }
         if ($key == "check_command") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newService->setCheckCommand($command->getId());
                 }
             }
             continue;
         }
         if ($key == "check_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newService->setCheckPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         if ($key == "event_handler") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newService->setEventHandler($command->getId());
                 }
             }
             continue;
         }
         if ($key == "notification_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newService->setNotificationPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         try {
             $name = NagiosServiceTemplatePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Fruity Service Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $newService->{$method}($val);
         }
     }
     $job->addNotice("Fruity Service Importer: Saved service: " . $newService->getDescription() . " on " . $newService->getOwnerDescription());
     $newService->save();
     $this->totalImported++;
     return true;
 }
예제 #20
0
 /**
  * Selects a collection of NagiosContact objects pre-filled with all related objects.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of NagiosContact objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     NagiosContactPeer::addSelectColumns($c);
     $startcol2 = NagiosContactPeer::NUM_COLUMNS - NagiosContactPeer::NUM_LAZY_LOAD_COLUMNS;
     NagiosTimeperiodPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (NagiosTimeperiodPeer::NUM_COLUMNS - NagiosTimeperiodPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosTimeperiodPeer::addSelectColumns($c);
     $startcol4 = $startcol3 + (NagiosTimeperiodPeer::NUM_COLUMNS - NagiosTimeperiodPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(NagiosContactPeer::HOST_NOTIFICATION_PERIOD), array(NagiosTimeperiodPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosContactPeer::SERVICE_NOTIFICATION_PERIOD), array(NagiosTimeperiodPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = NagiosContactPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = NagiosContactPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $omClass = NagiosContactPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             NagiosContactPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined NagiosTimeperiod rows
         $key2 = NagiosTimeperiodPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = NagiosTimeperiodPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = NagiosTimeperiodPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 NagiosTimeperiodPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (NagiosContact) to the collection in $obj2 (NagiosTimeperiod)
             $obj2->addNagiosContactRelatedByHostNotificationPeriod($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosTimeperiod rows
         $key3 = NagiosTimeperiodPeer::getPrimaryKeyHashFromRow($row, $startcol3);
         if ($key3 !== null) {
             $obj3 = NagiosTimeperiodPeer::getInstanceFromPool($key3);
             if (!$obj3) {
                 $omClass = NagiosTimeperiodPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj3 = new $cls();
                 $obj3->hydrate($row, $startcol3);
                 NagiosTimeperiodPeer::addInstanceToPool($obj3, $key3);
             }
             // if obj3 loaded
             // Add the $obj1 (NagiosContact) to the collection in $obj3 (NagiosTimeperiod)
             $obj3->addNagiosContactRelatedByServiceNotificationPeriod($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
예제 #21
0
파일: hosts.php 프로젝트: Evolix/lilac
             $host->setFirstNotificationDelay($modifiedData['first_notification_delay']);
         } else {
             $host->setFirstNotificationDelay(null);
         }
         if (isset($modifiedData['notifications_enabled'])) {
             $host->setNotificationsEnabled($modifiedData['notifications_enabled']);
         } else {
             $host->setNotificationsEnabled(null);
         }
         if (isset($modifiedData['notification_interval'])) {
             $host->setNotificationInterval($modifiedData['notification_interval']);
         } else {
             $host->setNotificationInterval(null);
         }
         if (isset($modifiedData['notification_period'])) {
             $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);
예제 #22
0
파일: output.php 프로젝트: Evolix/lilac
function print_timeperiod_display_field($label, $values, $field, $sourceID = null)
{
    if (isset($values[$field])) {
        $timeperiod = NagiosTimeperiodPeer::retrieveByPK($values[$field]['value']);
        if ($timeperiod) {
            print "<strong>" . $label . "</strong>: ";
            print $timeperiod->getName();
            if ($values[$field]['inherited']) {
                ?>
<strong> - Inherited From <em><?php 
                echo $values[$field]['source']['name'];
                ?>
</em></strong><?php 
            }
            print "<br />";
        }
    }
}
예제 #23
0
 private function importHost($hostData)
 {
     $job = $this->getEngine()->getJob();
     // check to see if we have a host by that name
     if (NagiosHostPeer::getByName($hostData['host_name'])) {
         $job->addNotice("Fruity Host Importer: Host " . $hostData['host_name'] . " already exists.  Aborting it's import.");
         return true;
     }
     $newHost = new NagiosHost();
     $newHost->setName($hostData['host_name']);
     // Check to see if we need the template
     if (!empty($hostData['use_template_id'])) {
         $name = $this->getHostTemplateNameById($hostData['use_template_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Importer:  Could not find template with id: " . $hostData['use_template_id'] . ". Aborting it's import.");
             return false;
         } else {
             // Okay, we got the name, does this template exist?
             $template = NagiosHostTemplatePeer::getByName($name);
             if (!$template) {
                 $job->addNotice("Fruity Host Importer: Could not find a template in the system with the name of: " . $name . ". Aborting it's import.");
                 return false;
             } else {
                 // Create a new inheritance relationship
                 $inheritance = new NagiosHostTemplateInheritance();
                 $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
                 $inheritance->setNagiosHost($newHost);
                 try {
                     $inheritance->save();
                 } catch (Exception $e) {
                     $job->addNotice("Fruity Host Importer:  Cannot add inheritance from " . $template->getName() . " to " . $newHost->getName());
                 }
             }
         }
     }
     // Okay, start 'er up!
     foreach ($hostData as $key => $val) {
         unset($name);
         if ($key == "host_id" || $key == "use_template_id" || $key == "host_name") {
             continue;
         }
         if ($key == "parents") {
             // we're gonna do parents after this
             continue;
         }
         if ($key == "notification_options_down") {
             $key = "notification_on_down";
         }
         if ($key == "notification_options_unreachable") {
             $key = "notification_on_unreachable";
         }
         if ($key == "notification_options_recovery") {
             $key = "notification_on_recovery";
         }
         if ($key == "notification_options_flapping") {
             $key = "notification_on_flapping";
         }
         if ($key == "stalking_options_up") {
             $key = "stalking_on_up";
         }
         if ($key == "stalking_options_down") {
             $key = "stalking_on_down";
         }
         if ($key == "stalking_options_unreachable") {
             $key = "stalking_on_unreachable";
         }
         if ($key == "max_check_attempts") {
             $key = "maximum_check_attempts";
         }
         if ($key == "retry_check_interval") {
             $key = "retry_interval";
         }
         if ($key == "check_command") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newHost->setCheckCommand($command->getId());
                 }
             }
             continue;
         }
         if ($key == "check_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newHost->setCheckPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         if ($key == "event_handler") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newHost->setEventHandler($command->getId());
                 }
             }
             continue;
         }
         if ($key == "notification_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newHost->setNotificationPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         try {
             $name = NagiosHostPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Fruity Host Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $newHost->{$method}($val);
         }
     }
     $newHost->save();
     $job->addNotice("FruityHostImporter: Imported new host: " . $newHost->getName());
     $this->totalImported++;
     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;
 }
예제 #25
0
 /**
  * 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;
 }
예제 #26
0
파일: search.php 프로젝트: Evolix/lilac
 private function search_text($text)
 {
     // LOTS of places to check...
     // Hosts: name, alias, addresses
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosHostPeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(nagiosHostPeer::ALIAS, "%" . $text . "%", Criteria::LIKE);
     $c3 = $c->getNewCriterion(nagiosHostPeer::ADDRESS, "%" . $text . "%", Criteria::LIKE);
     $c2->addOr($c3);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosHostPeer::NAME);
     $matchedHosts = NagiosHostPeer::doSelect($c);
     if (count($matchedHosts)) {
         foreach ($matchedHosts as $host) {
             $this->searchResults['hosts'][$host->getId()] = $host;
             $this->searchCount++;
         }
     }
     // Hostgroups: name, alias
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosHostgroupPeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(nagiosHostgroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosHostgroupPeer::NAME);
     $matchedHostgroups = NagiosHostgroupPeer::doSelect($c);
     if (count($matchedHostgroups)) {
         foreach ($matchedHostgroups as $hostgroup) {
             $this->searchResults['hostgroups'][$hostgroup->getId()] = $hostgroup;
             $this->searchCount++;
         }
     }
     // Host Templates: name, description
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosHostTemplatePeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(NagiosHostTemplatePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosHostTemplatePeer::NAME);
     $matchedTemplates = NagiosHostTemplatePeer::doSelect($c);
     if (count($matchedTemplates)) {
         foreach ($matchedTemplates as $template) {
             $this->searchResults['host_templates'][$template->getId()] = $template;
             $this->searchCount++;
         }
     }
     // Services: description
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosServicePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosServicePeer::DESCRIPTION);
     $matchedServices = NagiosServicePeer::doSelect($c);
     if (count($matchedServices)) {
         foreach ($matchedServices as $service) {
             $this->searchResults['services'][$service->getId()] = $service;
             $this->searchCount++;
         }
     }
     // Servicegroups: name, alias
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosServiceGroupPeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(NagiosServiceGroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosServiceGroupPeer::NAME);
     $matchedServicegroups = NagiosServiceGroupPeer::doSelect($c);
     if (count($matchedServicegroups)) {
         foreach ($matchedServicegroups as $servicegroup) {
             $this->searchResults['servicegroups'][$servicegroup->getId()] = $servicegroup;
             $this->searchCount++;
         }
     }
     // Service Templates: name, description
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosServiceTemplatePeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(NagiosServiceTemplatePeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosServiceTemplatePeer::NAME);
     $matchedTemplates = NagiosServiceTemplatePeer::doSelect($c);
     if (count($matchedTemplates)) {
         foreach ($matchedTemplates as $template) {
             $this->searchResults['service_templates'][$template->getId()] = $template;
             $this->searchCount++;
         }
     }
     // Service Templates: name, description
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosContactPeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(NagiosContactPeer::ALIAS, "%" . $text . "%", Criteria::LIKE);
     $c3 = $c->getNewCriterion(NagiosContactPeer::EMAIL, "%" . $text . "%", Criteria::LIKE);
     $c2->addOr($c3);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosContactPeer::NAME);
     $matchedContacts = NagiosContactPeer::doSelect($c);
     if (count($matchedContacts)) {
         foreach ($matchedContacts as $contact) {
             $this->searchResults['contacts'][$contact->getId()] = $contact;
             $this->searchCount++;
         }
     }
     // ContactGroups: name, alias
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosContactGroupPeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(NagiosContactGroupPeer::ALIAS, "%" . $text . "%", Criteria::LIKE);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosContactGroupPeer::NAME);
     $matchedContactgroups = NagiosContactGroupPeer::doSelect($c);
     if (count($matchedContactgroups)) {
         foreach ($matchedContactgroups as $contactgroup) {
             $this->searchResults['contactgroups'][$contactgroup->getId()] = $contactgroup;
             $this->searchCount++;
         }
     }
     // Timeperiod: name, alias
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosTimeperiodPeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(NagiosTimeperiodPeer::ALIAS, "%" . $text . "%", Criteria::LIKE);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosTimeperiodPeer::NAME);
     $matchedPeriods = NagiosTimeperiodPeer::doSelect($c);
     if (count($matchedPeriods)) {
         foreach ($matchedPeriods as $period) {
             $this->searchResults['timeperiods'][$period->getId()] = $period;
             $this->searchCount++;
         }
     }
     // Command: name, description
     $c = new Criteria();
     $c1 = $c->getNewCriterion(NagiosCommandPeer::NAME, "%" . $text . "%", Criteria::LIKE);
     $c2 = $c->getNewCriterion(NagiosCommandPeer::DESCRIPTION, "%" . $text . "%", Criteria::LIKE);
     $c1->addOr($c2);
     $c->add($c1);
     $c->setIgnoreCase(true);
     $c->addAscendingOrderByColumn(NagiosCommandPeer::NAME);
     $matchedCommands = NagiosCommandPeer::doSelect($c);
     if (count($matchedCommands)) {
         foreach ($matchedCommands as $command) {
             $this->searchResults['commands'][$command->getId()] = $command;
             $this->searchCount++;
         }
     }
 }
예제 #27
0
 /**
  * Selects a collection of NagiosEscalation objects pre-filled with all related objects except NagiosHostgroup.
  *
  * @param      Criteria  $c
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of NagiosEscalation objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptNagiosHostgroup(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     // $c->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     NagiosEscalationPeer::addSelectColumns($c);
     $startcol2 = NagiosEscalationPeer::NUM_COLUMNS - NagiosEscalationPeer::NUM_LAZY_LOAD_COLUMNS;
     NagiosHostTemplatePeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (NagiosHostTemplatePeer::NUM_COLUMNS - NagiosHostTemplatePeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosHostPeer::addSelectColumns($c);
     $startcol4 = $startcol3 + (NagiosHostPeer::NUM_COLUMNS - NagiosHostPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosServiceTemplatePeer::addSelectColumns($c);
     $startcol5 = $startcol4 + (NagiosServiceTemplatePeer::NUM_COLUMNS - NagiosServiceTemplatePeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosServicePeer::addSelectColumns($c);
     $startcol6 = $startcol5 + (NagiosServicePeer::NUM_COLUMNS - NagiosServicePeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosTimeperiodPeer::addSelectColumns($c);
     $startcol7 = $startcol6 + (NagiosTimeperiodPeer::NUM_COLUMNS - NagiosTimeperiodPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(NagiosEscalationPeer::HOST_TEMPLATE), array(NagiosHostTemplatePeer::ID), $join_behavior);
     $c->addJoin(array(NagiosEscalationPeer::HOST), array(NagiosHostPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosEscalationPeer::SERVICE_TEMPLATE), array(NagiosServiceTemplatePeer::ID), $join_behavior);
     $c->addJoin(array(NagiosEscalationPeer::SERVICE), array(NagiosServicePeer::ID), $join_behavior);
     $c->addJoin(array(NagiosEscalationPeer::ESCALATION_PERIOD), array(NagiosTimeperiodPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = NagiosEscalationPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = NagiosEscalationPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $omClass = NagiosEscalationPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             NagiosEscalationPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined NagiosHostTemplate rows
         $key2 = NagiosHostTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = NagiosHostTemplatePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = NagiosHostTemplatePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 NagiosHostTemplatePeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (NagiosEscalation) to the collection in $obj2 (NagiosHostTemplate)
             $obj2->addNagiosEscalation($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosHost rows
         $key3 = NagiosHostPeer::getPrimaryKeyHashFromRow($row, $startcol3);
         if ($key3 !== null) {
             $obj3 = NagiosHostPeer::getInstanceFromPool($key3);
             if (!$obj3) {
                 $omClass = NagiosHostPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj3 = new $cls();
                 $obj3->hydrate($row, $startcol3);
                 NagiosHostPeer::addInstanceToPool($obj3, $key3);
             }
             // if $obj3 already loaded
             // Add the $obj1 (NagiosEscalation) to the collection in $obj3 (NagiosHost)
             $obj3->addNagiosEscalation($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosServiceTemplate rows
         $key4 = NagiosServiceTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol4);
         if ($key4 !== null) {
             $obj4 = NagiosServiceTemplatePeer::getInstanceFromPool($key4);
             if (!$obj4) {
                 $omClass = NagiosServiceTemplatePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj4 = new $cls();
                 $obj4->hydrate($row, $startcol4);
                 NagiosServiceTemplatePeer::addInstanceToPool($obj4, $key4);
             }
             // if $obj4 already loaded
             // Add the $obj1 (NagiosEscalation) to the collection in $obj4 (NagiosServiceTemplate)
             $obj4->addNagiosEscalation($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosService rows
         $key5 = NagiosServicePeer::getPrimaryKeyHashFromRow($row, $startcol5);
         if ($key5 !== null) {
             $obj5 = NagiosServicePeer::getInstanceFromPool($key5);
             if (!$obj5) {
                 $omClass = NagiosServicePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj5 = new $cls();
                 $obj5->hydrate($row, $startcol5);
                 NagiosServicePeer::addInstanceToPool($obj5, $key5);
             }
             // if $obj5 already loaded
             // Add the $obj1 (NagiosEscalation) to the collection in $obj5 (NagiosService)
             $obj5->addNagiosEscalation($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosTimeperiod rows
         $key6 = NagiosTimeperiodPeer::getPrimaryKeyHashFromRow($row, $startcol6);
         if ($key6 !== null) {
             $obj6 = NagiosTimeperiodPeer::getInstanceFromPool($key6);
             if (!$obj6) {
                 $omClass = NagiosTimeperiodPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj6 = new $cls();
                 $obj6->hydrate($row, $startcol6);
                 NagiosTimeperiodPeer::addInstanceToPool($obj6, $key6);
             }
             // if $obj6 already loaded
             // Add the $obj1 (NagiosEscalation) to the collection in $obj6 (NagiosTimeperiod)
             $obj6->addNagiosEscalation($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
예제 #28
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;
 }
예제 #29
0
 /**
  * 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(NagiosTimeperiodPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosTimeperiodPeer::DATABASE_NAME);
         $criteria->add(NagiosTimeperiodPeer::ID, $pks, Criteria::IN);
         $objs = NagiosTimeperiodPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #30
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityTimeperiodImporter beginning to import Timeperiod Configuration.");
     // Timeperiods
     foreach ($this->dbConn->query("SELECT * FROM nagios_timeperiods", PDO::FETCH_ASSOC) as $timeperiod) {
         // Check for existing timeperiod
         if (NagiosTimeperiodPeer::getByName($timeperiod['timeperiod_name'])) {
             $job->addNotice("Fruity Timeperiod Importer:  The timeperiod " . $timeperiod['timeperiod_name'] . " already exists.  Aborting it's import.");
             continue;
         }
         $newTimeperiod = new NagiosTimeperiod();
         $newTimeperiod->setName($timeperiod['timeperiod_name']);
         $newTimeperiod->setAlias($timeperiod['alias']);
         $newTimeperiod->save();
         if (!empty($timeperiod['sunday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('sunday');
             $entry->setValue($timeperiod['sunday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['monday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('monday');
             $entry->setValue($timeperiod['monday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['tuesday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('tuesday');
             $entry->setValue($timeperiod['tuesday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['wednesday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('wednesday');
             $entry->setValue($timeperiod['wednesday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['thursday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('thursday');
             $entry->setValue($timeperiod['thursday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['friday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('friday');
             $entry->setValue($timeperiod['friday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
         if (!empty($timeperiod['saturday'])) {
             $entry = new NagiosTimeperiodEntry();
             $entry->setEntry('saturday');
             $entry->setValue($timeperiod['saturday']);
             $entry->setNagiosTimeperiod($newTimeperiod);
             $entry->save();
         }
     }
     $job->addNotice("FruityTimeperiodImporter finished importing Timeperiod Configuration.");
 }