コード例 #1
0
 public function __addTargets($dependency)
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     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;
             }
         }
     }
     if (isset($values['host_name'])) {
         $host_names = explode(",", $values['host_name'][0]['value']);
         foreach ($host_names as $host_name) {
             $service = NagiosServicePeer::getByHostAndDescription($host_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             // Create target
             $target = new NagiosDependencyTarget();
             $target->setNagiosDependency($dependency);
             $target->setNagiosHost($service->getNagiosHost());
             $target->setNagiosService($service);
             $target->save();
             $target->clearAllReferences(true);
             $service->clearAllReferences(true);
         }
     }
     if (isset($values['hostgroup_name'])) {
         $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']);
         foreach ($hostgroup_names as $hostgroup_name) {
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             // Create target
             $target = new NagiosDependencyTarget();
             $target->setNagiosDependency($dependency);
             $target->setNagiosHostgroup($service->getNagiosHostgroup());
             $target->setNagiosService($service);
             $target->save();
             $target->clearAllReferences(true);
             $service->clearAllReferences(true);
         }
     }
     return true;
 }
コード例 #2
0
ファイル: dependency.php プロジェクト: Evolix/lilac
             $tempHostgroup = NagiosHostgroupPeer::doSelectOne($c);
             if (!$tempHostgroup) {
                 $error = "The hostgroup specified by name " . $_POST['name'] . " was not found.";
             } else {
                 // Check for target existence
                 $c = new Criteria();
                 $c->add(NagiosDependencyTargetPeer::DEPENDENCY, $dependency->getId());
                 $c->add(NagiosDependencyTargetPeer::TARGET_HOSTGROUP, $tempHostgroup->getId());
                 $target = NagiosDependencyTargetPeer::doSelectOne($c);
                 if ($target) {
                     $error = "That target already exists.";
                 } else {
                     // Add the target.
                     $target = new NagiosDependencyTarget();
                     $target->setNagiosDependency($dependency);
                     $target->setNagiosHostgroup($tempHostgroup);
                     $target->save();
                     $success = "Created target.";
                 }
             }
         }
     }
 } else {
     // Get the host
     $c = new Criteria();
     $c->add(NagiosHostPeer::NAME, $_POST['hostname']);
     $c->setIgnoreCase(true);
     $host = NagiosHostPeer::doSelectOne($c);
     if (!$host) {
         $error = "The host specified by name " . $_POST['hostname'] . " was not found.";
     } else {