コード例 #1
0
 /**
  * Declares an association between this object and a NagiosService object.
  *
  * @param      NagiosService $v
  * @return     NagiosServiceTemplateInheritance The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setNagiosService(NagiosService $v = null)
 {
     if ($v === null) {
         $this->setSourceService(NULL);
     } else {
         $this->setSourceService($v->getId());
     }
     $this->aNagiosService = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the NagiosService object, it will not be re-added.
     if ($v !== null) {
         $v->addNagiosServiceTemplateInheritance($this);
     }
     return $this;
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: add_service.php プロジェクト: Evolix/lilac
                    header("Location: service.php?id=" . $service->getId());
                    die;
                }
            } else {
                if (isset($hostgroup)) {
                    // Host logic
                    $c = new Criteria();
                    $c->add(NagiosServicePeer::DESCRIPTION, $_POST['service_description']);
                    $c->add(NagiosServicePeer::HOSTGROUP, $hostgroup->getId());
                    $c->setIgnoreCase(true);
                    $service = NagiosServicePeer::doSelectOne($c);
                    if ($service) {
                        $error = "A service with that description already exists for that hostgroup.";
                    } else {
                        // Let's add.
                        $service = new NagiosService();
                        $service->setDescription($_POST['service_description']);
                        $service->setDisplayName($_POST['display_name']);
                        $service->setHostgroup($hostgroup->getId());
                        $service->save();
                        header("Location: service.php?id=" . $service->getId());
                        die;
                    }
                }
            }
        }
    }
}
print_header("Service Editor");
// Get list of service templates
$lilac->get_service_template_list($tempList);
コード例 #4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      NagiosService $value A NagiosService object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosService $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
コード例 #5
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;
 }