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
 public function getByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosCommandPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $command = NagiosCommandPeer::doSelectOne($c);
     if (!$command) {
         return false;
     }
     return $command;
 }
Example #3
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $command = new NagiosCommand();
     $segment = $this->getSegment();
     // First check if we have a use
     $useTemplate = $segment->get("use");
     if ($useTemplate) {
         // Okay, we need to check to see if we have an existing dependency
         $val = $useTemplate[0]['value'];
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $dependant = NagiosCommandPeer::doSelectOne($c);
         if ($dependant) {
             $command->setLine($dependant->getLine());
         }
         $dependant->clearAllReferences(true);
     }
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     $commandLine = array();
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 if ($key == "command_line") {
                     // Combine into our line array
                     $commandLine[] = $value;
                     continue;
                 }
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($command, $this->fieldMethods[$key])) {
                     $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName);
                     if (!$config->getVar('continue_error')) {
                         return false;
                     }
                 } else {
                     call_user_method($this->fieldMethods[$key], $command, $value);
                 }
             }
         }
     }
     // re-assemble command
     $commandLine = implode(',', $commandLine);
     $command->setLine($commandLine);
     $command->save();
     $command->clearAllReferences(true);
     $job->addNotice("NagiosCommandImporter finished importing command: " . $command->getName());
     return true;
 }
Example #4
0
 public function addHostNotificationCommandByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosCommandPeer::NAME, $name);
     $command = NagiosCommandPeer::doSelectOne($c);
     if (!empty($command)) {
         $notificationCommand = new NagiosContactNotificationCommand();
         $notificationCommand->setType("host");
         $notificationCommand->setNagiosContact($this);
         $notificationCommand->setNagiosCommand($command);
         $notificationCommand->save();
         return true;
     }
     return false;
 }
Example #5
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosCommandExporter attempting to export command configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosCommandExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $commands = NagiosCommandPeer::doSelect(new Criteria());
     foreach ($commands as $command) {
         fputs($fp, "define command {\n");
         $finalArray = array();
         $values = $command->toArray(BasePeer::TYPE_FIELDNAME);
         foreach ($values as $key => $value) {
             if ($key == 'id' || $key == 'description') {
                 continue;
             }
             if ($value === null) {
                 continue;
             }
             if ($value === false) {
                 $value = '0';
             }
             if ($key == "name") {
                 $key = "command_name";
             }
             if ($key == "line") {
                 $key = "command_line";
             }
             $finalArray[$key] = $value;
         }
         foreach ($finalArray as $key => $val) {
             fputs($fp, "\t" . $key . "\t" . $val . "\n");
         }
         fputs($fp, "}\n");
         fputs($fp, "\n");
     }
     $job->addNotice("NagiosCommandExporter complete.");
     return true;
 }
Example #6
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityCommandImporter beginning to import Command Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_commands", PDO::FETCH_ASSOC) as $command) {
         $newCommand = new NagiosCommand();
         foreach ($command as $key => $val) {
             unset($name);
             if ($key == "command_id" || $key == "network_id") {
                 continue;
             }
             if ($key == "command_name") {
                 $key = "name";
             }
             if ($key == "command_line") {
                 $key = "line";
             }
             if ($key == "command_desc") {
                 $key = "description";
             }
             try {
                 $name = NagiosCommandPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Command Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newCommand->{$method}($val);
             }
         }
         // Check to see if the command already exists
         if (NagiosCommandPeer::getByName($newCommand->getName())) {
             $job->addNotice("Fruity Command Importer: The command " . $newCommand->getName() . " already exists.  Aborting it's import.");
         } else {
             $newCommand->save();
         }
     }
     $job->addNotice("FruityCommandImporter finished importing Command Configuration.");
 }
Example #7
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;
 }
Example #8
0
 function setEventHandlerByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosCommandPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $command = NagiosCommandPeer::doSelectOne($c);
     if (!$command) {
         return false;
     }
     $this->setNagiosCommandRelatedByEventHandler($command);
     $this->save();
     return true;
 }
Example #9
0
 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++;
         }
     }
 }
Example #10
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;
 }
Example #11
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;
 }
Example #12
0
 /**
  * Get the associated NagiosCommand object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     NagiosCommand The associated NagiosCommand object.
  * @throws     PropelException
  */
 public function getNagiosCommandRelatedByEventHandler(PropelPDO $con = null)
 {
     if ($this->aNagiosCommandRelatedByEventHandler === null && $this->event_handler !== null) {
         $c = new Criteria(NagiosCommandPeer::DATABASE_NAME);
         $c->add(NagiosCommandPeer::ID, $this->event_handler);
         $this->aNagiosCommandRelatedByEventHandler = NagiosCommandPeer::doSelectOne($c, $con);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aNagiosCommandRelatedByEventHandler->addNagiosHostsRelatedByEventHandler($this);
         		 */
     }
     return $this->aNagiosCommandRelatedByEventHandler;
 }
Example #13
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 = NagiosCommandPeer::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->setLine($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setDescription($arr[$keys[3]]);
     }
 }
Example #14
0
echo LILAC_VERSION;
?>
</h2>
Lilac Configurator is part of the Lilac Platform.  The community site is available at <a href="http://www.lilacplatform.com">www.lilacplatform.com</a>.  Lilac Configurator is a project developed by <a href="http://www.lilacnetworks.com">Lilac Networks</a>.
</p>
<p>
<h2>Services & Support</h2>
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());
?>
Example #15
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 #16
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityContactImporter beginning to import Contact Configuration.");
     // Contacts
     foreach ($this->dbConn->query("SELECT * FROM nagios_contacts", PDO::FETCH_ASSOC) as $contact) {
         // Check for existing
         if (NagiosContactPeer::getByName($contact['contact_name'])) {
             $job->addNotice("Fruity Contact Importer: Contact " . $contact['contact_name'] . " already exists.  Aborting it's import.");
             continue;
         }
         $newContact = new NagiosContact();
         foreach ($contact as $key => $val) {
             unset($name);
             if ($key == "contact_id") {
                 continue;
             }
             if ($key == "contact_name") {
                 $key = "name";
             }
             if ($key == "host_notification_options_down") {
                 $key = "host_notification_on_down";
             }
             if ($key == "host_notification_options_unreachable") {
                 $key = "host_notification_on_unreachable";
             }
             if ($key == "host_notification_options_recovery") {
                 $key = "host_notification_on_recovery";
             }
             if ($key == "host_notification_options_flapping") {
                 $key = "host_notification_on_flapping";
             }
             if ($key == "service_notification_options_warning") {
                 $key = "service_notification_on_warning";
             }
             if ($key == "service_notification_options_unknown") {
                 $key = "service_notification_on_unknown";
             }
             if ($key == "service_notification_options_critical") {
                 $key = "service_notification_on_critical";
             }
             if ($key == "service_notification_options_recovery") {
                 $key = "service_notification_on_recovery";
             }
             if ($key == "service_notification_options_flapping") {
                 $key = "service_notification_on_flapping";
             }
             if ($key == "host_notification_period") {
                 $name = $this->getTimeperiodNameById($val, $this->dbConn);
                 if ($name) {
                     $newContact->setHostNotificationPeriodByName($name);
                 }
                 continue;
             }
             if ($key == "service_notification_period") {
                 $name = $this->getTimeperiodNameById($val, $this->dbConn);
                 if ($name) {
                     $newContact->setServiceNotificationPeriodByName($name);
                 }
                 continue;
             }
             try {
                 $name = NagiosContactPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Contact Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newContact->{$method}($val);
             }
         }
         $newContact->save();
     }
     // Contact Addresses
     foreach ($this->dbConn->query("SELECT * FROM nagios_contact_addresses", PDO::FETCH_ASSOC) as $address) {
         // Check for required contact
         $name = $this->getContactNameById($address['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Address Importer: Could not find contact with id: " . $address['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Address Importer: Could not find contact with name: " . $name);
             continue;
         }
         $newContactAddress = new NagiosContactAddress();
         $newContactAddress->setNagiosContact($contact);
         $newContactAddress->setAddress($address['address']);
         $newContactAddress->save();
     }
     // Contact Notification Commands
     foreach ($this->dbConn->query("SELECT * FROM nagios_contacts_notification_commands", PDO::FETCH_ASSOC) as $notificationCommand) {
         // Check for required contact
         $name = $this->getContactNameById($notificationCommand['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find contact with id: " . $notificationCommand['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find contact with name: " . $name);
             continue;
         }
         // Okay, now get the required command
         $name = $this->getCommandNameById($notificationCommand['command_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Crontact Notification Command Importer: Could not find command with id: " . $notificationCommand['contact_id']);
             continue;
         }
         $command = NagiosCommandPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Notification Command Importer: Could not find command with name: " . $name);
             continue;
         }
         $newNotificationCommand = new NagiosContactNotificationCommand();
         $newNotificationCommand->setNagiosContact($contact);
         $newNotificationCommand->setNagiosCommand($command);
         $newNotificationCommand->setType($notificationCommand['notification_type']);
         $newNotificationCommand->save();
     }
     // Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_contactgroups", PDO::FETCH_ASSOC) as $contactGroup) {
         if (NagiosContactGroupPeer::getByName($contactGroup['contactgroup_name'])) {
             $job->addNotice("Fruity Contact Group Importer: Group " . $contactGroup['contactgroup_name'] . "already exists.  Aborting it's import.");
             continue;
         }
         $newContactGroup = new NagiosContactGroup();
         $newContactGroup->setName($contactGroup['contactgroup_name']);
         $newContactGroup->setAlias($contactGroup['alias']);
         $newContactGroup->save();
     }
     // Contact Group Members
     foreach ($this->dbConn->query("SELECT * FROM nagios_contactgroup_membership", PDO::FETCH_ASSOC) as $membership) {
         // Check for required contact
         $name = $this->getContactNameById($membership['contact_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact with id: " . $membership['contact_id']);
             continue;
         }
         $contact = NagiosContactPeer::getByName($name);
         if (!$contact) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact with name: " . $name);
             continue;
         }
         // Okay, now get the required contact group
         $name = $this->getContactGroupNameById($membership['contactgroup_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact group with id: " . $membership['contactgroup_id']);
             continue;
         }
         $contactgroup = NagiosContactGroupPeer::getByName($name);
         if (!$contactgroup) {
             $job->addNotice("Fruity Contact Group Membership Importer: Could not find contact group with name: " . $name);
             continue;
         }
         $newMembership = new NagiosContactGroupMember();
         $newMembership->setNagiosContact($contact);
         $newMembership->setNagiosContactGroup($contactgroup);
         $newMembership->save();
     }
     $job->addNotice("FruityContactImporter finished importing Contact Configuration.");
 }
Example #17
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 #18
0
 public function import()
 {
     global $lilac;
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityMainImporter beginning to import Main Configuration.");
     $res = $this->dbConn->query("SELECT * FROM nagios_main");
     // Fruity has just one record in the main, if we get it, import
     // it.
     $row = $res->fetch(PDO::FETCH_ASSOC);
     // Get our main obj.
     $mainConfig = $lilac->get_main_conf();
     foreach ($row as $key => $val) {
         unset($name);
         if ($key == "id" || $key == "p1_file" || $key == "comment_file" || $key == "downtime_file" || $key == "aggregate_status_updates") {
             continue;
         }
         if ($key == "service_perfdata_template") {
             $key = "service_perfdata_file_template";
         }
         if ($key == "host_perfdata_template") {
             $key = "host_perfdata_file_template";
         }
         if ($key == "global_host_event_handler") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "global_service_event_handler") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "ocsp_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "ochp_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "host_perfdata_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "service_perfdata_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "host_perfdata_file_processing_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "service_perfdata_file_processing_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         try {
             $name = NagiosMainConfigurationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Main Configuration: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $mainConfig->{$method}($val);
         }
     }
     $mainConfig->save();
     // Save main configuration
     // Broker modules
     foreach ($this->dbConn->query("SELECT * FROM nagios_broker_modules", PDO::FETCH_ASSOC) as $brokerModule) {
         $newModule = new NagiosBrokerModule();
         foreach ($brokerModule as $key => $val) {
             unset($name);
             if ($key == "module_id") {
                 continue;
             }
             if ($key == "module_line") {
                 $key = "line";
             }
             try {
                 $name = NagiosBrokerModulePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Broker Module: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newModule->{$method}($val);
             }
         }
         $newModule->save();
     }
     $job->addNotice("FruityMainImporter finished importing Main Configuration.");
 }
Example #19
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(NagiosCommandPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosCommandPeer::DATABASE_NAME);
         $criteria->add(NagiosCommandPeer::ID, $pks, Criteria::IN);
         $objs = NagiosCommandPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Example #20
0
 public function setServicePerfdataFileProcessingCommandByName($command_name)
 {
     $c = new Criteria();
     $c->add(NagiosCommandPeer::NAME);
     $c->setIgnoreCase(true);
     $command = NagiosCommandPeer::doSelectOne($c);
     if ($command) {
         $this->setServicePerfdataFileProcessingCommand($command->getId());
         return true;
     }
     return false;
 }
 /**
  * Selects a collection of NagiosContactNotificationCommand objects pre-filled with all related objects except NagiosContact.
  *
  * @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 NagiosContactNotificationCommand objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptNagiosContact(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);
     }
     NagiosContactNotificationCommandPeer::addSelectColumns($c);
     $startcol2 = NagiosContactNotificationCommandPeer::NUM_COLUMNS - NagiosContactNotificationCommandPeer::NUM_LAZY_LOAD_COLUMNS;
     NagiosCommandPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(NagiosContactNotificationCommandPeer::COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = NagiosContactNotificationCommandPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = NagiosContactNotificationCommandPeer::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 = NagiosContactNotificationCommandPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             NagiosContactNotificationCommandPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined NagiosCommand rows
         $key2 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = NagiosCommandPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 NagiosCommandPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (NagiosContactNotificationCommand) to the collection in $obj2 (NagiosCommand)
             $obj2->addNagiosContactNotificationCommand($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #22
0
                $_GET['command_add'] = 1;
            } else {
                // All is well for error checking, add the command into the db.
                $lilac->add_command($_POST['command_manage']);
                // Remove session data
                unset($command);
                $success = "Command added.";
            }
        }
    } else {
        if ($_POST['request'] == 'modify_command') {
            $c = new Criteria();
            $c->add(NagiosCommandPeer::NAME, $_POST['command_manage']['command_name']);
            $c->setIgnoreCase(true);
            $c->add(NagiosCommandPeer::ID, $command->getId(), "!=");
            $duplicate = NagiosCommandPeer::doSelectOne($c);
            if ($duplicate && $command->getId() != $duplicate->getId()) {
                $error = "A command with that name already exists!";
            } else {
                // All is well for error checking, modify the command.
                $command->updateFromArray($_POST['command_manage']);
                $command->save();
                $success = "Command modified.";
                unset($command);
            }
        }
    }
}
// Get list of commands
$lilac->return_command_list($command_list);
$numOfCommands = count($command_list);
Example #23
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 #24
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 #25
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;
 }
Example #26
0
 /**
  * Selects a collection of NagiosService objects pre-filled with all related objects except NagiosTimeperiodRelatedByNotificationPeriod.
  *
  * @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 NagiosService objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptNagiosTimeperiodRelatedByNotificationPeriod(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);
     }
     NagiosServicePeer::addSelectColumns($c);
     $startcol2 = NagiosServicePeer::NUM_COLUMNS - NagiosServicePeer::NUM_LAZY_LOAD_COLUMNS;
     NagiosHostPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (NagiosHostPeer::NUM_COLUMNS - NagiosHostPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosHostTemplatePeer::addSelectColumns($c);
     $startcol4 = $startcol3 + (NagiosHostTemplatePeer::NUM_COLUMNS - NagiosHostTemplatePeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosHostgroupPeer::addSelectColumns($c);
     $startcol5 = $startcol4 + (NagiosHostgroupPeer::NUM_COLUMNS - NagiosHostgroupPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol6 = $startcol5 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol7 = $startcol6 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(NagiosServicePeer::HOST), array(NagiosHostPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosServicePeer::HOST_TEMPLATE), array(NagiosHostTemplatePeer::ID), $join_behavior);
     $c->addJoin(array(NagiosServicePeer::HOSTGROUP), array(NagiosHostgroupPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosServicePeer::CHECK_COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosServicePeer::EVENT_HANDLER), array(NagiosCommandPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = NagiosServicePeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = NagiosServicePeer::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 = NagiosServicePeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             NagiosServicePeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined NagiosHost rows
         $key2 = NagiosHostPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = NagiosHostPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = NagiosHostPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 NagiosHostPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (NagiosService) to the collection in $obj2 (NagiosHost)
             $obj2->addNagiosService($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosHostTemplate rows
         $key3 = NagiosHostTemplatePeer::getPrimaryKeyHashFromRow($row, $startcol3);
         if ($key3 !== null) {
             $obj3 = NagiosHostTemplatePeer::getInstanceFromPool($key3);
             if (!$obj3) {
                 $omClass = NagiosHostTemplatePeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj3 = new $cls();
                 $obj3->hydrate($row, $startcol3);
                 NagiosHostTemplatePeer::addInstanceToPool($obj3, $key3);
             }
             // if $obj3 already loaded
             // Add the $obj1 (NagiosService) to the collection in $obj3 (NagiosHostTemplate)
             $obj3->addNagiosService($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosHostgroup rows
         $key4 = NagiosHostgroupPeer::getPrimaryKeyHashFromRow($row, $startcol4);
         if ($key4 !== null) {
             $obj4 = NagiosHostgroupPeer::getInstanceFromPool($key4);
             if (!$obj4) {
                 $omClass = NagiosHostgroupPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj4 = new $cls();
                 $obj4->hydrate($row, $startcol4);
                 NagiosHostgroupPeer::addInstanceToPool($obj4, $key4);
             }
             // if $obj4 already loaded
             // Add the $obj1 (NagiosService) to the collection in $obj4 (NagiosHostgroup)
             $obj4->addNagiosService($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosCommand rows
         $key5 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol5);
         if ($key5 !== null) {
             $obj5 = NagiosCommandPeer::getInstanceFromPool($key5);
             if (!$obj5) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj5 = new $cls();
                 $obj5->hydrate($row, $startcol5);
                 NagiosCommandPeer::addInstanceToPool($obj5, $key5);
             }
             // if $obj5 already loaded
             // Add the $obj1 (NagiosService) to the collection in $obj5 (NagiosCommand)
             $obj5->addNagiosServiceRelatedByCheckCommand($obj1);
         }
         // if joined row is not null
         // Add objects for joined NagiosCommand rows
         $key6 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol6);
         if ($key6 !== null) {
             $obj6 = NagiosCommandPeer::getInstanceFromPool($key6);
             if (!$obj6) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj6 = new $cls();
                 $obj6->hydrate($row, $startcol6);
                 NagiosCommandPeer::addInstanceToPool($obj6, $key6);
             }
             // if $obj6 already loaded
             // Add the $obj1 (NagiosService) to the collection in $obj6 (NagiosCommand)
             $obj6->addNagiosServiceRelatedByEventHandler($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #27
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;
 }
Example #28
0
 public function valid()
 {
     // We need to check to see if we have dependency issues, if so, state we are invalid at this time
     $segment = $this->getSegment();
     $job = $this->getEngine()->getJob();
     $val = $segment->get("ocsp_command");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find ocsp_command command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     $val = $segment->get("ohcp_command");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find ohcp_command command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     $val = $segment->get("host_perfdata_command");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find host_perfdata_command command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     $val = $segment->get("service_perfdata_command");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find service_perfdata_command command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     $val = $segment->get("host_perfdata_file_processing_command");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find host_perfdata_file_processing_command command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     $val = $segment->get("service_perfdata_file_processing_command");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find service_perfdata_file_processing command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     $val = $segment->get("global_service_event_handler");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find global_service_event_handler command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     $val = $segment->get("global_host_event_handler");
     $val = $val[0]['value'];
     if ($val) {
         $c = new Criteria();
         $c->add(NagiosCommandPeer::NAME, $val);
         $c->setIgnoreCase(true);
         $command = NagiosCommandPeer::doSelectOne($c);
         if (!$command) {
             $job->addNotice("Main Configuration not yet valid.  Could not find global_host_event_handler command: " . $val);
             return false;
         }
         $command->clearAllReferences(true);
     }
     return true;
 }
 /**
  * Selects a collection of NagiosMainConfiguration 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 NagiosMainConfiguration 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);
     }
     NagiosMainConfigurationPeer::addSelectColumns($c);
     $startcol2 = NagiosMainConfigurationPeer::NUM_COLUMNS - NagiosMainConfigurationPeer::NUM_LAZY_LOAD_COLUMNS;
     NagiosCommandPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol4 = $startcol3 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol5 = $startcol4 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol6 = $startcol5 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol7 = $startcol6 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol8 = $startcol7 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol9 = $startcol8 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     NagiosCommandPeer::addSelectColumns($c);
     $startcol10 = $startcol9 + (NagiosCommandPeer::NUM_COLUMNS - NagiosCommandPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(NagiosMainConfigurationPeer::OCSP_COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosMainConfigurationPeer::OCHP_COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosMainConfigurationPeer::HOST_PERFDATA_COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosMainConfigurationPeer::SERVICE_PERFDATA_COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosMainConfigurationPeer::HOST_PERFDATA_FILE_PROCESSING_COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosMainConfigurationPeer::SERVICE_PERFDATA_FILE_PROCESSING_COMMAND), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosMainConfigurationPeer::GLOBAL_SERVICE_EVENT_HANDLER), array(NagiosCommandPeer::ID), $join_behavior);
     $c->addJoin(array(NagiosMainConfigurationPeer::GLOBAL_HOST_EVENT_HANDLER), array(NagiosCommandPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = NagiosMainConfigurationPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = NagiosMainConfigurationPeer::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 = NagiosMainConfigurationPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             NagiosMainConfigurationPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined NagiosCommand rows
         $key2 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = NagiosCommandPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 NagiosCommandPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj2 (NagiosCommand)
             $obj2->addNagiosMainConfigurationRelatedByOcspCommand($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosCommand rows
         $key3 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol3);
         if ($key3 !== null) {
             $obj3 = NagiosCommandPeer::getInstanceFromPool($key3);
             if (!$obj3) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj3 = new $cls();
                 $obj3->hydrate($row, $startcol3);
                 NagiosCommandPeer::addInstanceToPool($obj3, $key3);
             }
             // if obj3 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj3 (NagiosCommand)
             $obj3->addNagiosMainConfigurationRelatedByOchpCommand($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosCommand rows
         $key4 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol4);
         if ($key4 !== null) {
             $obj4 = NagiosCommandPeer::getInstanceFromPool($key4);
             if (!$obj4) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj4 = new $cls();
                 $obj4->hydrate($row, $startcol4);
                 NagiosCommandPeer::addInstanceToPool($obj4, $key4);
             }
             // if obj4 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj4 (NagiosCommand)
             $obj4->addNagiosMainConfigurationRelatedByHostPerfdataCommand($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosCommand rows
         $key5 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol5);
         if ($key5 !== null) {
             $obj5 = NagiosCommandPeer::getInstanceFromPool($key5);
             if (!$obj5) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj5 = new $cls();
                 $obj5->hydrate($row, $startcol5);
                 NagiosCommandPeer::addInstanceToPool($obj5, $key5);
             }
             // if obj5 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj5 (NagiosCommand)
             $obj5->addNagiosMainConfigurationRelatedByServicePerfdataCommand($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosCommand rows
         $key6 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol6);
         if ($key6 !== null) {
             $obj6 = NagiosCommandPeer::getInstanceFromPool($key6);
             if (!$obj6) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj6 = new $cls();
                 $obj6->hydrate($row, $startcol6);
                 NagiosCommandPeer::addInstanceToPool($obj6, $key6);
             }
             // if obj6 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj6 (NagiosCommand)
             $obj6->addNagiosMainConfigurationRelatedByHostPerfdataFileProcessingCommand($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosCommand rows
         $key7 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol7);
         if ($key7 !== null) {
             $obj7 = NagiosCommandPeer::getInstanceFromPool($key7);
             if (!$obj7) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj7 = new $cls();
                 $obj7->hydrate($row, $startcol7);
                 NagiosCommandPeer::addInstanceToPool($obj7, $key7);
             }
             // if obj7 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj7 (NagiosCommand)
             $obj7->addNagiosMainConfigurationRelatedByServicePerfdataFileProcessingCommand($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosCommand rows
         $key8 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol8);
         if ($key8 !== null) {
             $obj8 = NagiosCommandPeer::getInstanceFromPool($key8);
             if (!$obj8) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj8 = new $cls();
                 $obj8->hydrate($row, $startcol8);
                 NagiosCommandPeer::addInstanceToPool($obj8, $key8);
             }
             // if obj8 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj8 (NagiosCommand)
             $obj8->addNagiosMainConfigurationRelatedByGlobalServiceEventHandler($obj1);
         }
         // if joined row not null
         // Add objects for joined NagiosCommand rows
         $key9 = NagiosCommandPeer::getPrimaryKeyHashFromRow($row, $startcol9);
         if ($key9 !== null) {
             $obj9 = NagiosCommandPeer::getInstanceFromPool($key9);
             if (!$obj9) {
                 $omClass = NagiosCommandPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj9 = new $cls();
                 $obj9->hydrate($row, $startcol9);
                 NagiosCommandPeer::addInstanceToPool($obj9, $key9);
             }
             // if obj9 loaded
             // Add the $obj1 (NagiosMainConfiguration) to the collection in $obj9 (NagiosCommand)
             $obj9->addNagiosMainConfigurationRelatedByGlobalHostEventHandler($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #30
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;
 }