Esempio n. 1
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosHostGroupExporter attempting to export host group configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosHostGroupExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria());
     foreach ($hostgroups as $hostgroup) {
         fputs($fp, "define hostgroup {\n");
         $finalArray = array();
         $values = $hostgroup->toArray(BasePeer::TYPE_FIELDNAME);
         foreach ($values as $key => $value) {
             if ($key == 'id') {
                 continue;
             }
             if ($value === null) {
                 continue;
             }
             if ($value === false) {
                 $value = '0';
             }
             if ($key == "name") {
                 $key = "hostgroup_name";
             }
             $finalArray[$key] = $value;
         }
         foreach ($finalArray as $key => $val) {
             fputs($fp, "\t" . $key . "\t" . $val . "\n");
         }
         fputs($fp, "}\n");
         fputs($fp, "\n");
     }
     $job->addNotice("NagiosHostGroupExporter complete.");
     return true;
 }
Esempio n. 2
0
 public function export()
 {
     global $lilac;
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosServiceExporter attempting to export service configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosServiceExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $hosts = NagiosHostPeer::doSelect(new Criteria());
     foreach ($hosts as $host) {
         // Got hosts
         // Get our inherited services first
         $job->addNotice("Processing services for host: " . $host->getName());
         $inheritedServices = $host->getInheritedServices();
         foreach ($inheritedServices as $service) {
             $job->addNotice("Processing service " . $service->getDescription());
             $this->_exportService($service, "host", $host);
         }
         $services = $host->getNagiosServices();
         foreach ($services as $service) {
             $job->addNotice("Processing service " . $service->getDescription());
             $this->_exportService($service, "host", $host);
         }
         $job->addNotice("Completed services export for host: " . $host->getName());
     }
     $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria());
     foreach ($hostgroups as $hostgroup) {
         $job->addNotice("Processing services for hostgroup: " . $hostgroup->getName());
         $services = $hostgroup->getNagiosServices();
         foreach ($services as $service) {
             $job->addNotice("Processing service " . $service->getDescription());
             $this->_exportService($service, "hostgroup", $hostgroup);
         }
     }
     $job->addNotice("NagiosServiceExporter complete.");
     return true;
 }
Esempio n. 3
0
 private function getAppliedHosts($hostValues, $hostgroupValues)
 {
     $appliedHosts = array();
     foreach ($hostValues as $val) {
         $val = $val['value'];
         if ($val == "*") {
             // Get all hosts
             $tempHosts = NagiosHostPeer::doSelect(new Criteria());
             foreach ($tempHosts as $tempHost) {
                 if (!array_key_exists($tempHost->getName(), $appliedHosts)) {
                     $appliedHosts[] = $tempHost;
                 }
             }
         } else {
             if (preg_match("/^!/", $val)) {
                 continue;
             } else {
                 $host = NagiosHostPeer::getByName($val);
                 if (!$host) {
                     // Give error
                     $values = $this->getSegment()->getValues();
                     $job = $this->getEngine()->getJob();
                     $job->addError("The host specified by name: " . $val . " was not found.  Setting this host ext info as queued.");
                     return false;
                 } else {
                     if (!array_key_exists($host->getName(), $appliedHosts)) {
                         $appliedHosts[] = $host;
                     }
                 }
             }
         }
     }
     foreach ($hostgroupValues as $val) {
         $val = $val['value'];
         // First check for *
         // then check for each hostgroup existence, then
         // each additional hostgroup
         if ($val == "*") {
             // Get all hostgroups
             $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria());
             foreach ($hostgroups as $hg) {
                 $hosts = $hostgroup->getNagiosHosts();
                 foreach ($hosts as $tempHost) {
                     if (!array_key_exists($tempHost->getName(), $appliedHosts)) {
                         $appliedHosts[] = $tempHost;
                     }
                 }
             }
         } else {
             if (preg_match("/^!/", $val)) {
                 continue;
             } else {
                 $hg = NagiosHostgroupPeer::getByName($val);
                 if (!$hg) {
                     // Give error
                     $values = $this->getSegment()->getValues();
                     $job = $this->getEngine()->getJob();
                     $job->addError("The hostgroup specified by name: " . $val . " was not found.  Setting this host ext info as queued.");
                     return false;
                 } else {
                     $hosts = $hg->getMembers();
                     foreach ($hosts as $tempHost) {
                         if (!array_key_exists($tempHost->getName(), $appliedHosts)) {
                             $appliedHosts[] = $tempHost;
                         }
                     }
                 }
             }
         }
     }
     // Okay, do exclusions
     foreach ($hostValues as $val) {
         $val = $val['value'];
         if (preg_match("/^!/", $val)) {
             unset($appliedHosts[$val]);
         }
     }
     foreach ($hostgroupValues as $val) {
         $val = $val['value'];
         if (preg_match("/^!/", $val)) {
             $hg = NagiosHostgroupPeer::getByName($val);
             if (!$hg) {
                 // Do nothing
             } else {
                 $hosts = $hg->getMembers();
                 foreach ($hosts as $tempHost) {
                     unset($appliedHosts[$tempHost->getName()]);
                 }
             }
         }
     }
     return $appliedHosts;
 }
Esempio n. 4
0
include_once 'includes/config.inc';
// AJAX behavior
if (isset($_GET['request']) && $_GET['request'] == "search") {
    $results = array();
    switch ($_GET['type']) {
        case 'host':
            $c = new Criteria();
            $c->add(NagiosHostPeer::NAME, $_GET['q'] . "%", Criteria::LIKE);
            $c->setIgnoreCase(true);
            $results = NagiosHostPeer::doSelect($c);
            break;
        case 'hostgroup':
            $c = new Criteria();
            $c->add(NagiosHostgroupPeer::NAME, $_GET['q'] . "%", Criteria::LIKE);
            $c->setIgnoreCase(true);
            $results = NagiosHostgroupPeer::doSelect($c);
        case 'service':
            // Get the host
            $c = new Criteria();
            $c->add(NagiosHostPeer::NAME, $_GET['host']);
            $c->setIgnoreCase(true);
            $host = NagiosHostPeer::doSelectOne($c);
            $returnObj = array();
            if (!$host) {
                $returnObj['error'] = "Host " . $_GET['host'] . " not found.";
                print json_encode($returnObj);
                exit;
            } else {
                $returnObj['services'] = array();
                // Okay, let's get services.
                $services = $host->getNagiosServices();
Esempio n. 5
0
 public function export()
 {
     global $lilac;
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosEscalationExporter attempting to export escalation configuration.");
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosEscalationExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     $hostgroups = NagiosHostgroupPeer::doSelect(new Criteria());
     foreach ($hostgroups as $hostgroup) {
         $job->addNotice("Processing escalations for hostgroup: " . $hostgroup->getName());
         $escalations = $hostgroup->getNagiosEscalations();
         foreach ($escalations as $escalation) {
             $this->_exportEscalation($escalation, "hostgroup", $hostgroup);
         }
     }
     $hosts = NagiosHostPeer::doSelect(new Criteria());
     foreach ($hosts as $host) {
         // Got hosts
         // Get inherited escalations first
         $job->addNotice("Processing escalations for host: " . $host->getName());
         $inheritedEscalations = $host->getInheritedEscalations();
         foreach ($inheritedEscalations as $escalation) {
             $this->_exportEscalation($escalation, "host", $host);
         }
         ${$escalations} = $host->getNagiosEscalations();
         foreach (${$escalations} as $escalation) {
             $this->_exportEscalation($escalation, "host", $host);
         }
         // Get our services
         $inheritedServices = $host->getInheritedServices();
         foreach ($inheritedServices as $service) {
             $job->addNotice("Processing escalations for service: " . $service->getDescription() . " on " . $host->getName());
             $serviceInheritedEscalations = $service->getInheritedEscalations();
             foreach ($serviceInheritedEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
             $c = new Criteria();
             $c->add(NagiosEscalationPeer::HOST, $host->getId());
             $c->add(NagiosEscalationPeer::SERVICE, $service->getId());
             $serviceEscalations = NagiosEscalationPeer::doSelect($c);
             foreach ($serviceEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
         }
         $services = $host->getNagiosServices();
         foreach ($services as $service) {
             $job->addNotice("Processing escalations for service: " . $service->getDescription() . " on " . $host->getName());
             $serviceInheritedEscalations = $service->getInheritedEscalations();
             foreach ($serviceInheritedEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
             $serviceEscalations = $service->getNagiosEscalations();
             foreach ($serviceEscalations as $escalation) {
                 $this->_exportEscalation($escalation, "service", $service, $host);
             }
         }
         $job->addNotice("Completed escalations export for host: " . $host->getName());
     }
     $job->addNotice("NagiosEscalationExporter complete.");
     return true;
 }
Esempio n. 6
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(NagiosHostgroupPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosHostgroupPeer::DATABASE_NAME);
         $criteria->add(NagiosHostgroupPeer::ID, $pks, Criteria::IN);
         $objs = NagiosHostgroupPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Esempio n. 7
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++;
         }
     }
 }