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 contact template: " . $values['name'][0]['value']); NagiosContactImporter::saveTemplate($values['name'][0]['value'], $segment); return true; } $contact = new NagiosContact(); // 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; } } } foreach ($values as $key => $entries) { foreach ($entries as $entry) { // Skips $value = $entry['value']; $lineNum = $entry['line']; if ($key == 'use' || $key == 'name' || $key == 'register') { continue; } // Address if (strpos($key, "address") === 0) { $contact->addAddress($value); continue; } if ($key == 'service_notification_options') { $options = explode(",", $entry['value']); foreach ($options as $option) { switch (strtolower(trim($option))) { case 'w': $contact->setServiceNotificationOnWarning(true); break; case 'u': $contact->setServiceNotificationOnUnknown(true); break; case 'c': $contact->setServiceNotificationOnCritical(true); break; case 'r': $contact->setServiceNotificationOnRecovery(true); break; case 'f': $contact->setServiceNotificationOnFlapping(true); break; } } continue; } if ($key == 'host_notification_options') { $options = explode(",", $entry['value']); foreach ($options as $option) { switch (strtolower(trim($option))) { case 'd': $contact->setHostNotificationOnDown(true); break; case 'u': $contact->setHostNotificationOnUnreachable(true); break; case 'r': $contact->setHostNotificationOnRecovery(true); break; case 'f': $contact->setHostNotificationOnFlapping(true); break; case 's': $contact->setHostNotificationOnScheduledDowntime(true); break; } } continue; } // Okay, let's check that the method DOES exist if (!method_exists($contact, $this->fieldMethods[$key])) { $job->addError("Method " . $this->fieldMethods[$key] . " does not exist for variable: " . $key . " on line " . $lineNum . " in file " . $fileName); if (!$config->getVar('continue_error')) { return false; } } else { call_user_method($this->fieldMethods[$key], $contact, $value); } } } $contact->save(); $contact->clearAllReferences(true); $job->addNotice("NagiosContactImporter finished importing contact: " . $contact->getName()); return true; }