Esempio n. 1
0
 public function addMembersByServiceGroup($name)
 {
     // First get servicegroup
     $servicegroup = NagiosServiceGroupPeer::getByName($name);
     if (!$servicegroup) {
         return false;
     }
     // Get the members
     $memberships = $servicegroup->getNagiosServiceGroupMembers();
     foreach ($memberships as $membership) {
         $service = $membership->getNagiosService();
         // Check to see if we already have this in our member list
         $id = $this->getId();
         if (!empty($id)) {
             $c = new Criteria();
             $c->add(NagiosServiceGroupMemberPeer::SERVICE_GROUP, $this->getId());
             $c->add(NagiosServiceGroupMemberPeer::SERVICE, $service->getId());
             $relationship = NagiosServiceGroupMemberPeer::doSelectOne($c);
             if ($relationship) {
                 continue;
             }
         }
         // Create new relationship
         $relationship = new NagiosServiceGroupMember();
         $relationship->setNagiosService($service);
         $relationship->setNagiosServiceGroup($this);
         $relationship->save();
     }
     return true;
 }
Esempio n. 2
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityServiceImporter beginning to import Service Configuration.");
     // Services
     foreach ($this->dbConn->query("SELECT * FROM nagios_services", PDO::FETCH_ASSOC) as $service) {
         $this->importService($service);
     }
     // Service template check commands
     $job->addNotice("FruityServiceImporter now processing Service Check Commands.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_services_check_command_parameters WHERE service_id IS NOT NULL", PDO::FETCH_ASSOC) as $commandParameterInfo) {
         $service = $this->getLilacServiceById($commandParameterInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id: " . $commandParameterInfo['service_id']);
             continue;
         }
         $newParameter = new NagiosServiceCheckCommandParameter();
         $newParameter->setService($service->getId());
         $newParameter->setParameter($commandParameterInfo['parameter']);
         $newParameter->save();
     }
     // Service extended information
     $job->addNotice("FruityServiceImporter now processing Service Extended Information.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_services_extended_info", PDO::FETCH_ASSOC) as $extInfo) {
         $service = $this->getLilacServiceById($extInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $extInfo['service_id']);
             continue;
         }
         // Go through the extended info, and set it on the template.
         $service->setNotes($extInfo['notes']);
         $service->setNotesUrl($extInfo['notes_url']);
         $service->setActionUrl($extInfo['action_url']);
         $service->setIconImage($extInfo['icon_image']);
         $service->setIconImageAlt($extInfo['icon_image_alt']);
         $service->save();
     }
     // Service contact group memberships
     $job->addNotice("FruityServiceImporter now processing Service Contact Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_service_contactgroups", PDO::FETCH_ASSOC) as $membershipInfo) {
         $service = $this->getLilacServiceById($membershipInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $membershipInfo['service_id']);
             continue;
         }
         // Now get Contact Group Name
         $contactGroupName = $this->getContactGroupNameById($membershipInfo['contactgroup_id']);
         if (!$contactGroupName) {
             $job->addNotice("Fruity Service Contact Group Importer: Could not find contact group with id: " . $membershipInfo['contactgroup_id']);
             continue;
         }
         $contactGroup = NagiosContactGroupPeer::getByName($contactGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Contact Group Importer: Could not find contact group with name: " . $contactGroupName);
             continue;
         }
         $membership = new NagiosServiceContactGroupMember();
         $membership->setService($service->getId());
         $membership->setNagiosContactGroup($contactGroup);
         $membership->save();
     }
     // Service service group memberships
     $job->addNotice("FruityServiceImporter now processing Service Service Group Memberships.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_servicegroup_membership", PDO::FETCH_ASSOC) as $membershipInfo) {
         $service = $this->getLilacServiceById($membershipInfo['service_id']);
         if (!$service) {
             $job->addNotice("Fruity Service Check Command Parameter Importer: Could not find service with id " . $membershipInfo['service_id']);
             continue;
         }
         // Now get Contact Group Name
         $serviceGroupName = $this->getServiceGroupNameById($membershipInfo['servicegroup_id']);
         if (!$serviceGroupName) {
             $job->addNotice("Fruity Service Service Group Importer: Could not find service group with id: " . $membershipInfo['servicegroup_id']);
             continue;
         }
         $serviceGroup = NagiosServiceGroupPeer::getByName($serviceGroupName);
         if (!$contactGroup) {
             $job->addNotice("Fruity Service Service Group Importer: Could not find service group with name: " . $serviceGroupName);
             continue;
         }
         $membership = new NagiosServiceGroupMember();
         $membership->setService($service->getId());
         $membership->setNagiosServiceGroup($serviceGroup);
         $membership->save();
     }
     $job->addNotice("FruityServiceImporter finished importing Service Group Configuration.");
     $job->addNotice("FruityServiceImporter imported a total of " . $this->totalImported . " services.");
 }
Esempio n. 3
0
 function addServicegroupByName($name)
 {
     $c = new Criteria();
     $c->add(NagiosServiceGroupPeer::NAME, $name);
     $c->setIgnoreCase(true);
     $servicegroup = NagiosServiceGroupPeer::doSelectOne($c);
     if (!$servicegroup) {
         return false;
     }
     // Okay, servicegroup is valid, check for relationship
     $id = $this->getId();
     if (!empty($id)) {
         $c = new Criteria();
         $c->add(NagiosServiceGroupMemberPeer::TEMPLATE, $this->getId());
         $c->add(NagiosServiceGroupMemberPeer::SERVICE_GROUP, $servicegroup->getId());
         $relationship = NagiosServiceGroupMemberPeer::doSelectOne($c);
         if ($relationship) {
             return false;
         }
     }
     $relationship = new NagiosServiceGroupMember();
     $relationship->setNagiosServiceTemplate($this);
     $relationship->setNagiosServiceGroup($servicegroup);
     $relationship->save();
     return true;
 }