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");
 }
 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;
 }
Exemple #3
0
             $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);
Exemple #4
0
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 />";
        }
    }
}
 /**
  * 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");
 }
Exemple #6
0
                            $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
Exemple #7
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)) {
Exemple #8
0
 public function export()
 {
     global $lilac;
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosHostExporter attempting to export host configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosHostExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $hosts = NagiosHostPeer::doSelect(new Criteria());
     foreach ($hosts as $host) {
         fputs($fp, "define host {\n");
         $finalArray = array();
         $values = $host->getValues();
         foreach ($values as $key => $valArray) {
             $value = $valArray['value'];
             if ($key == 'id' || $key == 'notification_on_down' || $key == 'notification_on_unreachable' || $key == 'notification_on_recovery' || $key == 'notification_on_flapping' || $key == 'notification_on_scheduled_downtime' || $key == 'stalking_on_up' || $key == 'stalking_on_down' || $key == 'stalking_on_unreachable' || $key == 'flap_detection_on_up' || $key == 'flap_detection_on_down' || $key == 'flap_detection_on_unreachable' || $key == '' || $key == "autodiscovery_address_filter" || $key == "autodiscovery_hostname_filter" || $key == "autodiscovery_os_family_filter" || $key == "autodiscovery_os_generation_filter" || $key == "autodiscovery_os_vendor_filter" || $key == "description") {
                 continue;
             }
             if ($key == 'name') {
                 $key = 'host_name';
             }
             if ($key == 'maximum_check_attempts') {
                 $key = 'max_check_attempts';
             }
             if ($key == 'two_d_coords') {
                 $key = '2d_coords';
             }
             if ($key == 'three_d_coords') {
                 $key = '3d_coords';
             }
             if ($value === null) {
                 continue;
             }
             if ($value === false) {
                 $value = '0';
             }
             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 = $host->getInheritedCommandWithParameters();
                     foreach ($cmdObj['parameters'] as $parameterArray) {
                         $value .= "!" . $parameterArray['parameter']->getParameter();
                     }
                 }
             }
             $finalArray[$key] = $value;
         }
         foreach ($finalArray as $key => $val) {
             fputs($fp, "\t" . $key . "\t" . $val . "\n");
         }
         // Notifications
         if (isset($values['notification_on_down']['value'])) {
             if (!$values['notification_on_down']['value'] && !$values['notification_on_unreachable']['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_down']['value']) {
                     $tempValues[] = "d";
                 }
                 if ($values['notification_on_unreachable']['value']) {
                     $tempValues[] = "u";
                 }
                 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['stalking_on_up']['value'] || $values['stalking_on_down']['value'] || $values['stalking_on_unreachable']['value']) {
             fputs($fp, "\tstalking_options\t");
             if ($values['stalking_on_up']['value']) {
                 fputs($fp, "o");
                 if ($values['stalking_on_down']['value'] || $values['stalking_on_unreachable']['value']) {
                     fputs($fp, ",");
                 }
             }
             if ($values['stalking_on_down']['value']) {
                 fputs($fp, "d");
                 if ($values['stalking_on_unreachable']['value']) {
                     fputs($fp, ",");
                 }
             }
             if ($values['stalking_on_unreachable']['value']) {
                 fputs($fp, "u");
             }
             fputs($fp, "\n");
         }
         // Flap Detection
         if ($values['flap_detection_on_up']['value'] || $values['flap_detection_on_down']['value'] || $values['flap_detection_on_unreachable']['value']) {
             fputs($fp, "\tflap_detection_options\t");
             if ($values['flap_detection_on_up']['value']) {
                 fputs($fp, "o");
                 if ($values['flap_detection_on_down']['value'] || $values['flap_detection_on_unreachable']['value']) {
                     fputs($fp, ",");
                 }
             }
             if ($values['flap_detection_on_down']['value']) {
                 fputs($fp, "d");
                 if ($values['flap_detection_on_unreachable']['value']) {
                     fputs($fp, ",");
                 }
             }
             if ($values['flap_detection_on_unreachable']['value']) {
                 fputs($fp, "u");
             }
             fputs($fp, "\n");
         }
         // Parents
         $c = new Criteria();
         $c->add(NagiosHostParentPeer::CHILD_HOST, $host->getId());
         $parents = NagiosHostParentPeer::doSelectJoinNagiosHostRelatedByParentHost($c);
         if (count($parents)) {
             fputs($fp, "\tparents\t");
             $first = true;
             foreach ($parents as $parent) {
                 if (!$first) {
                     fputs($fp, ",");
                 } else {
                     $first = false;
                 }
                 fputs($fp, $parent->getNagiosHostRelatedByParentHost()->getName());
             }
             fputs($fp, "\n");
         }
         // Contact Groups
         $groupList = array();
         $inherited_list = $host->getInheritedContactGroups();
         $lilac->return_host_contactgroups_list($host->getId(), $contactgroups_list);
         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");
         }
         // Contacts
         $contactList = array();
         $inherited_list = $host->getInheritedContacts();
         $contact_list = $host->getNagiosHostContactMembers();
         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");
         }
         // Host Groups
         $groupList = array();
         $inherited_list = $host->getInheritedHostGroups();
         $hostgroups_list = $host->getNagiosHostgroupMemberships();
         foreach ($inherited_list as $group) {
             if (!key_exists($group->getName(), $groupList)) {
                 $groupList[$group->getName()] = $group;
             }
         }
         foreach ($hostgroups_list as $group) {
             $group = $group->getNagiosHostgroup();
             if (!key_exists($group->getName(), $groupList)) {
                 $groupList[$group->getName()] = $group;
             }
         }
         if (count($groupList)) {
             fputs($fp, "\thostgroups\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");
     }
     $job->addNotice("NagiosHostExporter complete.");
     return true;
 }