예제 #1
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      NagiosEscalation $value A NagiosEscalation object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(NagiosEscalation $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
예제 #2
0
 /**
  * Declares an association between this object and a NagiosEscalation object.
  *
  * @param      NagiosEscalation $v
  * @return     NagiosEscalationContact The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setNagiosEscalation(NagiosEscalation $v = null)
 {
     if ($v === null) {
         $this->setEscalation(NULL);
     } else {
         $this->setEscalation($v->getId());
     }
     $this->aNagiosEscalation = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the NagiosEscalation object, it will not be re-added.
     if ($v !== null) {
         $v->addNagiosEscalationContact($this);
     }
     return $this;
 }
 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 service escalation template: " . $values['name'][0]['value']);
         NagiosServiceEscalationImporter::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();
             $service = NagiosServicePeer::getByHostAndDescription($host_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             $escalation->setNagiosService($service);
             $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();
             $escalation->clearAllReferences(true);
             $service->clearAllReferences(true);
             $job->addNotice("NagiosServiceEscalationImporter finished importing Service Escalation for " . $host_name);
         }
     }
     if (isset($values['hostgroup_name'])) {
         $hostgroup_names = explode(",", $values['hostgroup_name'][0]['value']);
         foreach ($hostgroup_names as $hostgroup_name) {
             $escalation = new NagiosEscalation();
             $service = NagiosServicePeer::getByHostgroupAndDescription($hostgroup_name, $values['service_description'][0]['value']);
             if (!$service) {
                 return false;
             }
             $escalation->setNagiosService($service);
             $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();
             $escalation->clearAllReferences(true);
             $service->clearAllReferences(true);
             $job->addNotice("NagiosServiceEscalationImporter finished importing Service Escalation for hostgroup " . $hostgroup_name);
         }
     }
     return true;
 }
예제 #4
0
                    if (!$tempSource) {
                        header("Location: welcome.php");
                    }
                    $type = "service";
                    $title = "Service";
                }
            }
        }
    }
}
if (isset($_POST['request']) && $_POST['request'] == 'add_escalation') {
    // Check to see what kind of escalation we've got
    if (trim($_POST['escalation_description']) == '') {
        $errorMsg = "Description cannot be blank.";
    } else {
        $escalation = new NagiosEscalation();
        if ($type == "host") {
            $escalation->setHost($tempSource->getId());
        }
        if ($type == "hostgroup") {
            $escalation->setHostgroup($tempSource->getId());
        } else {
            if ($type == "hosttemplate") {
                $escalation->setHostTemplate($tempSource->getId());
            } else {
                if ($type == "service") {
                    $escalation->setService($tempSource->getId());
                } else {
                    if ($type == "servicetemplate") {
                        $escalation->setServiceTemplate($tempSource->getId());
                    }
예제 #5
0
 /**
  * Enter description here...
  *
  * @param NagiosEscalation $escalation
  * @param unknown_type $type
  * @param unknown_type $targetObj
  * @param unknown_type $subObj
  */
 private function _exportEscalation($escalation, $type, $targetObj, $subObj = null)
 {
     global $lilac;
     $fp = $this->getOutputFile();
     if ($type == "host") {
         $host = $targetObj;
         fputs($fp, "define hostescalation {\n");
         fputs($fp, "\thost_name\t" . $host->getName() . "\n");
     } else {
         if ($type == 'service') {
             $host = $subObj;
             $service = $targetObj;
             fputs($fp, "define serviceescalation {\n");
             fputs($fp, "\thost_name\t" . $host->getName() . "\n");
             fputs($fp, "\tservice_description\t" . $service->getDescription() . "\n");
         } else {
             if ($type == "hostgroup") {
                 $hostgroup = $targetObj;
                 fputs($fp, "define hostescalation {\n");
                 fputs($fp, "\thostgroup_name\t" . $hostgroup->getName() . "\n");
             }
         }
     }
     // Get contacts
     $contacts = $escalation->getNagiosEscalationContacts();
     if (count($contacts)) {
         fputs($fp, "\tcontacts\t");
         $first = true;
         foreach ($contacts as $membership) {
             $contact = $membership->getNagiosContact();
             if (!$first) {
                 fputs($fp, ",");
             } else {
                 $first = false;
             }
             fputs($fp, $contact->getName());
         }
         fputs($fp, "\n");
     }
     // Get contact groups
     $contactGroups = $escalation->getNagiosEscalationContactgroups();
     if (count($contactGroups)) {
         fputs($fp, "\tcontact_groups\t");
         $first = true;
         foreach ($contactGroups as $membership) {
             $contactGroup = $membership->getNagiosContactGroup();
             if (!$first) {
                 fputs($fp, ",");
             } else {
                 $first = false;
             }
             fputs($fp, $contactGroup->getName());
         }
         fputs($fp, "\n");
     }
     if ($escalation->getEscalationPeriod()) {
         fputs($fp, "\tescalation_period\t");
         $timePeriod = NagiosTimeperiodPeer::retrieveByPK($escalation->getEscalationPeriod());
         fputs($fp, $timePeriod->getName() . "\n");
     }
     if ($escalation->getFirstNotification()) {
         fputs($fp, "\tfirst_notification\t" . $escalation->getFirstNotification() . "\n");
     }
     if ($escalation->getLastNotification()) {
         fputs($fp, "\tlast_notification\t" . $escalation->getLastNotification() . "\n");
     }
     if ($escalation->getNotificationInterval()) {
         fputs($fp, "\tnotification_interval\t" . $escalation->getNotificationInterval() . "\n");
     }
     if ($escalation->getEscalationOptionsUp() != null || $escalation->getEscalationOptionsDown() != null || $escalation->getEscalationOptionsUnreachable() != null || $escalation->getEscalationOptionsOk() != null || $escalation->getEscalationOptionsWarning() != null || $escalation->getEscalationOptionsUnknown() != null || $escalation->getEscalationOptionsCritical() != null) {
         fputs($fp, "\tescalation_options\t");
         if ($escalation->getEscalationOptionsUp()) {
             fputs($fp, "r");
             if ($escalation->getEscalationOptionsDown() || $escalation->getEscalationOptionsUnreachable() || $escalation->getEscalationOptionsOk() || $escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsDown()) {
             fputs($fp, "d");
             if ($escalation->getEscalationOptionsUnreachable() || $escalation->getEscalationOptionsOk() || $escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsUnreachable()) {
             fputs($fp, "u");
             if ($escalation->getEscalationOptionsOk() || $escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsOk()) {
             fputs($fp, "o");
             if ($escalation->getEscalationOptionsWarning() || $escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsWarning()) {
             fputs($fp, "w");
             if ($escalation->getEscalationOptionsUnknown() || $escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsUnknown()) {
             fputs($fp, "u");
             if ($escalation->getEscalationOptionsCritical()) {
                 fputs($fp, ",");
             }
         }
         if ($escalation->getEscalationOptionsCritical()) {
             fputs($fp, "c");
         }
         fputs($fp, "\n");
     }
     fputs($fp, "}\n");
     fputs($fp, "\n");
 }
예제 #6
0
 public function import()
 {
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityEscalationImporter beginning to import Dependency Configuration.");
     foreach ($this->dbConn->query("SELECT * FROM nagios_escalations", PDO::FETCH_ASSOC) as $escalation) {
         $newEscalation = new NagiosEscalation();
         if (!empty($escalation['service_id'])) {
             // This is a service escalation
             $lilacService = $this->getLilacServiceById($escalation['service_id']);
             if (!$lilacService) {
                 $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service with an id matching: " . $escalation['service_id']);
                 return true;
             }
             $newEscalation->setService($lilacService->getId());
         } else {
             if (!empty($escalation['host_id'])) {
                 // This is a host escalation
                 $hostName = $this->getHostNameById($escalation['host_id']);
                 $host = NagiosHostPeer::getByName($hostName);
                 if (!$host) {
                     $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host with an name matching: " . $hostName);
                     return true;
                 }
                 $newEscalation->setHost($host->getId());
             } else {
                 if (!empty($escalation['service_template_id'])) {
                     // This is a service template escalation
                     $templateName = $this->getServiceTemplateNameById($escalation['service_template_id']);
                     $template = NagiosServiceTemplatePeer::getByName($templateName);
                     if (!$template) {
                         $job->addNotice("Fruity Escalation Importer: Failed to get Lilac service template with  name matching: " . $templateName);
                         return true;
                     }
                     $newEscalation->setServiceTemplate($template->getId());
                 } else {
                     if (!empty($escalation['host_template_id'])) {
                         // This is for a host template escalation
                         $templateName = $this->getHostTemplateNameById($escalation['host_template_id']);
                         $template = NagiosHostTemplatePeer::getByName($templateName);
                         if (!$template) {
                             $job->addNotice("Fruity Escalation Importer: Failed to get Lilac host template with  name matching: " . $templateName);
                             return true;
                         }
                         $newEscalation->setHostTemplate($template->getId());
                     }
                 }
             }
         }
         foreach ($escalation as $key => $val) {
             unset($name);
             if ($key == "escalation_id" || $key == "host_id" || $key == "host_template_id" || $key == "service_template_id" || $key == "service_id") {
                 continue;
             }
             if ($key == "escalation_description") {
                 $key = "description";
             }
             if ($key == "escalation_period") {
                 $escalationName = $this->getTimeperiodNameById($id);
                 if ($escalationName) {
                     $newEscalation->setEscalationPeriodByName($escalationName);
                 }
                 continue;
             }
             try {
                 $name = NagiosEscalationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Fruity Escalation Importer: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newEscalation->{$method}($val);
             }
         }
         $newEscalation->save();
         // Handle escalation contact groups.
         foreach ($this->dbConn->query("SELECT * FROM nagios_escalation_contactgroups WHERE escalation_id = " . $escalation['escalation_id'], PDO::FETCH_ASSOC) as $contactgroup) {
             $contactgroupName = $this->getContactGroupNameById($contactgroup['contactgroup_id']);
             if ($contactgroupName) {
                 $lilacContactGroup = NagiosContactGroupPeer::getByName($contactgroupName);
                 if ($lilacContactGroup) {
                     $newContactGroup = new NagiosEscalationContactgroup();
                     $newContactGroup->setEscalation($newEscalation->getId());
                     $newContactGroup->setContactgroup($lilacContactGroup->getId());
                     $newContactGroup->save();
                 }
             }
         }
     }
     $job->addNotice("FruityEscalationImporter finished importing Escalation Configuration.");
 }