Beispiel #1
0
 public function addMembersByHostgroup($name)
 {
     // First get hostgroup
     $hostgroup = NagiosHostgroupPeer::getByName($name);
     if (!$hostgroup) {
         return false;
     }
     // Get the members
     $memberships = $hostgroup->getNagiosHostgroupMemberships();
     foreach ($memberships as $membership) {
         $host = $membership->getNagiosHost();
         // Check to see if we already have this in our member list
         $id = $this->getId();
         if (!empty($id)) {
             $c = new Criteria();
             $c->add(NagiosHostgroupMembershipPeer::HOSTGROUP, $this->getId());
             $c->add(NagiosHostgroupMembershipPeer::HOST, $host->getId());
             $relationship = NagiosHostgroupMembershipPeer::doSelectOne($c);
             if ($relationship) {
                 continue;
             }
         }
         // Create new relationship
         $relationship = new NagiosHostgroupMembership();
         $relationship->setNagiosHost($host);
         $relationship->setNagiosHostgroup($this);
         $relationship->save();
     }
     return true;
 }
Beispiel #2
0
 public static function getByHostgroupAndDescription($hostgroupname, $description)
 {
     // First get hostgroup
     $hostgroup = NagiosHostgroupPeer::getByName($hostgroupname);
     if (!$hostgroup) {
         return false;
     }
     $c = new Criteria();
     $c->add(NagiosServicePeer::HOSTGROUP, $hostgroup->getId());
     $c->add(NagiosServicePeer::DESCRIPTION, $description);
     $c->setIgnoreCase(true);
     $service = NagiosServicePeer::doSelectOne($c);
     if (!$service) {
         return false;
     }
     return $service;
 }
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityHostGroupImporter beginning to import Host Group Configuration.");
     // Host groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_hostgroups", PDO::FETCH_ASSOC) as $hostgroupInfo) {
         // Check to see if hostgroup exists
         $tempHostgroup = NagiosHostgroupPeer::getByName($hostgroupInfo['hostgroup_name']);
         if ($tempHostgroup) {
             $job->addNotice("Fruity Host Group Importer: Host group " . $hostgroupInfo['hostgroup_name'] . " already exists, skipping import.");
             continue;
         }
         // Let's create a hostgroup
         $newHostgroup = new NagiosHostgroup();
         $newHostgroup->setName($hostgroupInfo['hostgroup_name']);
         $newHostgroup->setAlias($hostgroupInfo['alias']);
         $newHostgroup->save();
     }
     $job->addNotice("FruityHostGroupImporter finished importing Host Group Configuration.");
 }
 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;
 }
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // We need to determine if we are a template
     if (isset($values['name'])) {
         // We are a template
         $job->addNotice("Saving internal host escalation template: " . $values['name'][0]['value']);
         NagiosHostEscalationImporter::saveTemplate($values['name'][0]['value'], $segment);
         return true;
     }
     // Check if we need to bring in values from a template
     if (isset($values['use'])) {
         // We sure are using a template!
         // Okay, hokey multi-inheritance support for the importer
         $tempValues = $this->getTemplateValues($values['use'][0]['value']);
         // Okay, go through each
         foreach ($tempValues as $key => $val) {
             if (!isset($values[$key])) {
                 $values[$key] = $val;
             }
         }
     }
     // Okay, we first iterate through any possible dependent_host_name's
     if (isset($values['host_name'])) {
         $host_names = explode(",", $values['host_name'][0]['value']);
         foreach ($host_names as $host_name) {
             $escalation = new NagiosEscalation();
             $host = NagiosHostPeer::getByName($host_name);
             if (!$host) {
                 return false;
             }
             $escalation->setNagiosHost($host);
             $ret = $this->__process($escalation);
             if (!$ret) {
                 return false;
             }
             $ret = $this->__addContacts($escalation);
             if (!$ret) {
                 return false;
             }
             // Need to give it a temp name
             $escalation->save();
             $escalation->setDescription("Imported Escalation #" . $escalation->getId());
             $escalation->save();
             $job->addNotice("NagiosHostEscalation finished importing Host Escalation for " . $host_name);
             $host->clearAllReferences(true);
             $escalation->clearAllReferences(true);
         }
     }
     if (isset($values['hostgroup_name'])) {
         $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']);
         foreach ($hostgroup_names as $hostgroup_name) {
             $escalation = new NagiosEscalation();
             $hostgroup = NagiosHostgroupPeer::getByName($hostgroup_name);
             if (!$hostgroup) {
                 return false;
             }
             $escalation->setNagiosHostgroup($hostgroup);
             $ret = $this->__process($escalation);
             if (!$ret) {
                 return false;
             }
             $ret = $this->__addContacts($escalation);
             if (!$ret) {
                 return false;
             }
             $escalation->save();
             $escalation->setDescription("Imported Escalation #" . $escalation->getId());
             $escalation->save();
             $job->addNotice("NagiosHostEscalation finished importing Host Escalation for hostgroup " . $hostgroup_name);
             $hostgroup->clearAllReferences(true);
             $escalation->clearAllReferences(true);
         }
     }
     return true;
 }
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityHostTemplateImporter beginning to import Host Template Configuration.");
     // Host templates
     $queuedHostTemplates = array();
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_templates", PDO::FETCH_ASSOC) as $hostTemplate) {
         if (!$this->importHostTemplate($hostTemplate)) {
             $queuedHostTemplates[] = $hostTemplate;
         }
     }
     while (count($queuedHostTemplates)) {
         for ($counter = 0; $counter < count($queuedHostTemplates); $counter++) {
             if ($this->importHostTemplate($queuedHostTemplates[$counter])) {
                 unset($queuedHostTemplates[$counter]);
             }
         }
     }
     // Host Template Check Command Parameters
     foreach ($this->dbConn->query("SELECT * FROM nagios_hosts_check_command_parameters WHERE host_template_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($commandParameterInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Check Command Parameter Importer: Could not find host template with id " . $commandParameterInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Check Command Parameter Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         $newParameter = new NagiosHostCheckCommandParameter();
         $newParameter->setTemplate($hostTemplate->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Host Template Contact Groups
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_template_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($membershipInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find host template with id " . $membershipInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Host Template Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosHostContactGroup();
         $membership->setHostTemplate($hostTemplate->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Host Template Extended Information
     foreach ($this->dbConn->query("SELECT * FROM nagios_host_template_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($extInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Extended Info Importer: Could not find host template with id " . $extInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Extended Info Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $hostTemplate->setNotes($extInfo['notes']);
         $hostTemplate->setNotesUrl($extInfo['notes_url']);
         $hostTemplate->setActionUrl($extInfo['action_url']);
         $hostTemplate->setIconImage($extInfo['icon_image']);
         $hostTemplate->setIconImageAlt($extInfo['icon_image_alt']);
         $hostTemplate->setVrmlImage($extInfo['vrml_image']);
         $hostTemplate->setStatusmapImage($extInfo['statusmap_image']);
         $hostTemplate->setTwoDCoords($extInfo['two_d_coords']);
         $hostTemplate->setThreeDCoords($extInfo['three_d_coords']);
         $hostTemplate->save();
     }
     // Host group template memberships
     foreach ($this->dbConn->query("SELECT * FROM nagios_hostgroup_template_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $hostTemplateName = $this->getHostTemplateNameById($membershipInfo['host_template_id']);
         if (!$hostTemplateName) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host template with id " . $membershipInfo['host_template_id']);
             continue;
         }
         // Get the template
         $hostTemplate = NagiosHostTemplatePeer::getByName($hostTemplateName);
         if (!$hostTemplate) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host template with name " . $hostTemplateName);
             continue;
         }
         // Now get Contact Group Name
         $hostGroupName = $this->getHostGroupNameById($membershipInfo['hostgroup_id']);
         if (!$hostGroupName) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host group with id: " . $membershipInfo['hostgroup_id']);
             continue;
         }
         $hostGroup = NagiosHostgroupPeer::getByName($hostGroupName);
         if (!$hostGroup) {
             $job->addNotice("Fruity Host Template Host Group Importer: Could not find host group with name: " . $hostGroupName);
             continue;
         }
         $membership = new NagiosHostgroupMembership();
         $membership->setHostTemplate($hostTemplate->getId());
         $membership->setNagiosHostgroup($hostGroup);
         $membership->save();
     }
     $job->addNotice("FruityHostTemplateImporter finished importing Host Template Configuration.");
     $job->addNotice("FruityHostTemplateImporter: Finished importing a total of " . $this->totalImported . " host templates.");
 }
Beispiel #7
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // We need to determine if we are a template
     $isTemplate = false;
     if (isset($values['name'])) {
         // We're a template, just do a template process.
         $obj = new NagiosServiceTemplate();
         $ret = $this->__process($obj);
         if (!$ret) {
             return false;
         }
         $obj->save();
         $obj->clearAllReferences(true);
         $job->addNotice("NagiosServiceImporter finished importing service template: " . $obj->getName());
         return true;
     } else {
         // Okay, we need to create new Services for each type
         if (isset($values['host_name'])) {
             foreach ($values['host_name'] as $hostNameValues) {
                 $obj = new NagiosService();
                 $host = NagiosHostPeer::getByName($hostNameValues['value']);
                 if (!$host) {
                     return false;
                 }
                 // Okay, we got a proper host
                 $obj->setNagiosHost($host);
                 $ret = $this->__process($obj);
                 if (!$ret) {
                     return false;
                 }
                 $obj->save();
                 $host->clearAllReferences(true);
                 $job->addNotice("NagiosServiceImporter finished importing service : " . $obj->getDescription() . " for host: " . $host->getName());
             }
         }
         // Okay, now search for hostgroups
         if (isset($values['hostgroup_name'])) {
             foreach ($values['hostgroup_name'] as $hostGroupValues) {
                 $obj = new NagiosService();
                 $hostgroup = NagiosHostgroupPeer::getByName($hostGroupValues['value']);
                 if (!$hostgroup) {
                     return false;
                 }
                 // Okay, we got a proper hostgroup
                 $obj->setNagiosHostgroup($hostgroup);
                 $ret = $this->__process($obj);
                 if (!$ret) {
                     return false;
                 }
                 $obj->save();
                 $hostgroup->clearAllReferences(true);
             }
         }
         // Okay, now search for hostgroups
         if (isset($values['hostgroup'])) {
             foreach ($values['hostgroup'] as $hostGroupValues) {
                 $obj = new NagiosService();
                 $hostgroup = NagiosHostgroupPeer::getByName($hostGroupValues['value']);
                 if (!$hostgroup) {
                     return false;
                 }
                 // Okay, we got a proper hostgroup
                 $obj->setNagiosHostgroup($hostgroup);
                 $ret = $this->__process($obj);
                 if (!$ret) {
                     return false;
                 }
                 $obj->save();
                 $hostgroup->clearAllReferences(true);
             }
         }
     }
     $obj->clearAllReferences(true);
     return true;
 }