コード例 #1
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
     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;
 }