Example #1
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosMainExporter attempting to export main configuration.");
     // Grab our main config
     $mainConfig = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     if (!$mainConfig) {
         $job->addError("Unable to get Main Configuration object.  Your Lilac database is corrupt.");
         return false;
     }
     $finalArray = array();
     $commandLookupArray = array('global_host_event_handler', 'global_service_event_handler', 'ocsp_command', 'ochp_command', 'host_perfdata_command', 'service_perfdata_command', 'host_perfdata_file_processing_command', 'service_perfdata_command', 'service_perfdata_file_processing_command');
     $values = $mainConfig->toArray(BasePeer::TYPE_FIELDNAME);
     foreach ($values as $key => $value) {
         if ($key == 'id' || $key == 'config_dir') {
             continue;
         }
         if ($value === null) {
             continue;
         }
         if ($value === false) {
             $value = '0';
         }
         if (in_array($key, $commandLookupArray)) {
             $command = NagiosCommandPeer::retrieveByPK($value);
             if (!$command) {
                 $job->addError("Unable to find command with id:" . $value . " for " . $key);
                 return false;
             } else {
                 $value = $command->getName();
             }
         }
         $finalArray[$key] = $value;
     }
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosMainExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     foreach ($finalArray as $key => $val) {
         fputs($fp, $key . "=" . $val . "\n");
     }
     // Get list of broker modules
     $modules = NagiosBrokerModulePeer::doSelect(new Criteria());
     foreach ($modules as $mod) {
         fputs($fp, "broker_module=" . $mod->getLine() . "\n");
     }
     if (!empty($this->configDir)) {
         fputs($fp, "resource_file=" . $this->configDir . "/resource.cfg\n");
     } else {
         fputs($fp, "resource_file=" . $mainConfig->getConfigDir() . "/resource.cfg\n");
     }
     if (!empty($this->configDir)) {
         fputs($fp, "cfg_dir=" . $this->configDir . "/objects\n");
     } else {
         fputs($fp, "cfg_dir=" . $mainConfig->getConfigDir() . "/objects\n");
     }
     $job->addNotice("NagiosMainExporter complete.");
     return true;
 }
Example #2
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");
 }
Example #3
0
     $host->setObsessOverHost($modifiedData['obsess_over_host']);
 } else {
     $host->setObsessOverHost(null);
 }
 if (isset($modifiedData['max_check_attempts'])) {
     $host->setCheckFreshness($modifiedData['check_freshness']);
 } else {
     $host->setCheckFreshness(null);
 }
 if (isset($modifiedData['max_check_attempts'])) {
     $host->setFreshnessThreshold($modifiedData['freshness_threshold']);
 } else {
     $host->setFreshnessThreshold(null);
 }
 if (isset($modifiedData['event_handler']) && $modifiedData['event_handler'] != 0) {
     $host->setEventHandler(NagiosCommandPeer::retrieveByPK($modifiedData['event_handler'])->getId());
 } else {
     $host->setEventHandler(null);
 }
 if (isset($modifiedData['event_handler_enabled'])) {
     $host->setEventHandlerEnabled($modifiedData['event_handler_enabled']);
 } else {
     $host->setEventHandlerEnabled(null);
 }
 if (isset($modifiedData['failure_prediction_enabled'])) {
     $host->setFailurePredictionEnabled($modifiedData['failure_prediction_enabled']);
 } else {
     $host->setFailurePredictionEnabled(null);
 }
 $host->save();
 unset($_GET['edit']);
Example #4
0
             $serviceTemplate->setCheckFreshness($modifiedData['check_freshness']);
         } else {
             $serviceTemplate->setCheckFreshness(null);
         }
         if (isset($modifiedData['freshness_threshold'])) {
             $serviceTemplate->setFreshnessThreshold($modifiedData['freshness_threshold']);
         } else {
             $serviceTemplate->setFreshnessThreshold(null);
         }
         if (isset($modifiedData['event_handler_enabled'])) {
             $serviceTemplate->setEventHandlerEnabled($modifiedData['event_handler_enabled']);
         } else {
             $serviceTemplate->setEventHandlerEnabled(null);
         }
         if (isset($modifiedData['event_handler']) && $modifiedData['event_handler'] != 0) {
             $serviceTemplate->setEventHandler(NagiosCommandPeer::retrieveByPK($modifiedData['event_handler'])->getId());
         } else {
             $serviceTemplate->setEventHandler(null);
         }
         if (isset($modifiedData['failure_prediction_enabled'])) {
             $serviceTemplate->setFailurePredictionEnabled($modifiedData['failure_prediction_enabled']);
         } else {
             $serviceTemplate->setFailurePredictionEnabled(null);
         }
         $serviceTemplate->save();
         unset($_GET['edit']);
         $success = "Service template modified";
     }
 } else {
     if ($_POST['request'] == 'service_template_modify_flapping') {
         // Field Error Checking
Example #5
0
function print_command_display_field($label, $values, $field, $sourceID = null)
{
    if (isset($values[$field])) {
        $command = NagiosCommandPeer::retrieveByPK($values[$field]['value']);
        if ($command) {
            print "<strong>" . $label . "</strong>: ";
            print $command->getName();
            if ($values[$field]['inherited']) {
                ?>
<strong> - Inherited From <em><?php 
                echo $values[$field]['source']['name'];
                ?>
</em></strong><?php 
            }
            print "<br />";
        }
    }
}
Example #6
0
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
/*
Lilac Index Page, Displays Menu, and Statistics
*/
include_once 'includes/config.inc';
if (isset($_GET['command_id'])) {
    $command = NagiosCommandPeer::retrieveByPK($_GET['command_id']);
    if (!$command) {
        header("Location: welcome.php");
        die;
    }
}
// Action Handlers
if (isset($_GET['request'])) {
    if ($_GET['request'] == "delete") {
        $command->delete();
        $success = "Command Deleted";
        unset($command);
    }
}
if (isset($_POST['request'])) {
    // Load Up The Session Data
Example #7
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;
 }