Example #1
0
 private function importHost($hostData)
 {
     $job = $this->getEngine()->getJob();
     // check to see if we have a host by that name
     if (NagiosHostPeer::getByName($hostData['host_name'])) {
         $job->addNotice("Fruity Host Importer: Host " . $hostData['host_name'] . " already exists.  Aborting it's import.");
         return true;
     }
     $newHost = new NagiosHost();
     $newHost->setName($hostData['host_name']);
     // Check to see if we need the template
     if (!empty($hostData['use_template_id'])) {
         $name = $this->getHostTemplateNameById($hostData['use_template_id'], $this->dbConn);
         if (!$name) {
             $job->addNotice("Fruity Host Importer:  Could not find template with id: " . $hostData['use_template_id'] . ". Aborting it's import.");
             return false;
         } else {
             // Okay, we got the name, does this template exist?
             $template = NagiosHostTemplatePeer::getByName($name);
             if (!$template) {
                 $job->addNotice("Fruity Host Importer: Could not find a template in the system with the name of: " . $name . ". Aborting it's import.");
                 return false;
             } else {
                 // Create a new inheritance relationship
                 $inheritance = new NagiosHostTemplateInheritance();
                 $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
                 $inheritance->setNagiosHost($newHost);
                 try {
                     $inheritance->save();
                 } catch (Exception $e) {
                     $job->addNotice("Fruity Host Importer:  Cannot add inheritance from " . $template->getName() . " to " . $newHost->getName());
                 }
             }
         }
     }
     // Okay, start 'er up!
     foreach ($hostData as $key => $val) {
         unset($name);
         if ($key == "host_id" || $key == "use_template_id" || $key == "host_name") {
             continue;
         }
         if ($key == "parents") {
             // we're gonna do parents after this
             continue;
         }
         if ($key == "notification_options_down") {
             $key = "notification_on_down";
         }
         if ($key == "notification_options_unreachable") {
             $key = "notification_on_unreachable";
         }
         if ($key == "notification_options_recovery") {
             $key = "notification_on_recovery";
         }
         if ($key == "notification_options_flapping") {
             $key = "notification_on_flapping";
         }
         if ($key == "stalking_options_up") {
             $key = "stalking_on_up";
         }
         if ($key == "stalking_options_down") {
             $key = "stalking_on_down";
         }
         if ($key == "stalking_options_unreachable") {
             $key = "stalking_on_unreachable";
         }
         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) {
                     $newHost->setCheckCommand($command->getId());
                 }
             }
             continue;
         }
         if ($key == "check_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newHost->setCheckPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         if ($key == "event_handler") {
             $name = $this->getCommandNameById($val);
             if ($name) {
                 $command = NagiosCommandPeer::getByName($name);
                 if ($command) {
                     $newHost->setEventHandler($command->getId());
                 }
             }
             continue;
         }
         if ($key == "notification_period") {
             $name = $this->getTimeperiodNameById($val);
             if ($name) {
                 $timeperiod = NagiosTimeperiodPeer::getByName($name);
                 if ($timeperiod) {
                     $newHost->setNotificationPeriod($timeperiod->getId());
                 }
             }
             continue;
         }
         try {
             $name = NagiosHostPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Fruity Host Importer: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $newHost->{$method}($val);
         }
     }
     $newHost->save();
     $job->addNotice("FruityHostImporter: Imported new host: " . $newHost->getName());
     $this->totalImported++;
     return true;
 }
Example #2
0
 // Check for pre-existing host template with same name
 if ($lilac->host_exists($_POST['host_manage']['host_name'])) {
     $error = "A host with that name already exists!";
 } else {
     // Field Error Checking
     if (count($_POST['host_manage'])) {
         foreach ($_POST['host_manage'] as $tempVariable) {
             $tempVariable = trim($tempVariable);
         }
     }
     if ($_POST['host_manage']['host_name'] == '' || $_POST['host_manage']['alias'] == '' || $_POST['host_manage']['address'] == '') {
         $error = "Fields shown are required and cannot be left blank.";
     } else {
         // All is well for error checking, add the host into the db.
         $tempHost = new NagiosHost();
         $tempHost->setName($_POST['host_manage']['host_name']);
         $tempHost->setAlias($_POST['host_manage']['alias']);
         if (isset($_GET['parent_id'])) {
             // Get the host by that parent_id
             $host = NagiosHostPeer::retrieveByPk($_GET['parent_id']);
             if ($host) {
                 // valid host, add parent
                 $tempHost->addParentByName($host->getName());
             }
         }
         $tempHost->setAddress($_POST['host_manage']['address']);
         if (isset($_POST['host_manage']['display_name'])) {
             $tempHost->setDisplayName($_POST['host_manage']['display_name']);
         }
         $tempHost->save();
         header("Location: hosts.php?id=" . $tempHost->getId());
Example #3
0
         if ($host->getId() == $device->getId()) {
             unset($host);
         }
     }
     if (!empty($host)) {
         $error = "A host already exists with the name of " . $device->getName() . ".  Change the device's name before importing.";
     }
 }
 if (empty($error)) {
     $totalSuccess = 0;
     // Okay, no errors, let's create our hosts!
     foreach ($_POST['selectedDevices'] as $deviceId) {
         $device = AutodiscoveryDevicePeer::retrieveByPK($deviceId);
         $tempHost = new NagiosHost();
         $tempHost->setAddress($device->getAddress());
         $tempHost->setName($device->getName());
         $tempHost->setAlias($device->getDescription());
         $tempHost->save();
         // Now assign a template, if wanted
         $template = $device->getNagiosHostTemplate();
         if (!empty($template)) {
             $inheritance = new NagiosHostTemplateInheritance();
             $inheritance->setNagiosHost($tempHost);
             $inheritance->setNagiosHostTemplateRelatedByTargetTemplate($template);
             $inheritance->save();
         }
         // Now parent
         $parent = $device->getNagiosHost();
         if (!empty($parent)) {
             $parentRelationship = new NagiosHostParent();
             $parentRelationship->setNagiosHostRelatedByChildHost($tempHost);