Exemple #1
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosMainExporter attempting to export main configuration.");
     // Grab our main config
     $mainConfig = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     if (!$mainConfig) {
         $job->addError("Unable to get Main Configuration object.  Your Lilac database is corrupt.");
         return false;
     }
     $finalArray = array();
     $commandLookupArray = array('global_host_event_handler', 'global_service_event_handler', 'ocsp_command', 'ochp_command', 'host_perfdata_command', 'service_perfdata_command', 'host_perfdata_file_processing_command', 'service_perfdata_command', 'service_perfdata_file_processing_command');
     $values = $mainConfig->toArray(BasePeer::TYPE_FIELDNAME);
     foreach ($values as $key => $value) {
         if ($key == 'id' || $key == 'config_dir') {
             continue;
         }
         if ($value === null) {
             continue;
         }
         if ($value === false) {
             $value = '0';
         }
         if (in_array($key, $commandLookupArray)) {
             $command = NagiosCommandPeer::retrieveByPK($value);
             if (!$command) {
                 $job->addError("Unable to find command with id:" . $value . " for " . $key);
                 return false;
             } else {
                 $value = $command->getName();
             }
         }
         $finalArray[$key] = $value;
     }
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosMainExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     foreach ($finalArray as $key => $val) {
         fputs($fp, $key . "=" . $val . "\n");
     }
     // Get list of broker modules
     $modules = NagiosBrokerModulePeer::doSelect(new Criteria());
     foreach ($modules as $mod) {
         fputs($fp, "broker_module=" . $mod->getLine() . "\n");
     }
     if (!empty($this->configDir)) {
         fputs($fp, "resource_file=" . $this->configDir . "/resource.cfg\n");
     } else {
         fputs($fp, "resource_file=" . $mainConfig->getConfigDir() . "/resource.cfg\n");
     }
     if (!empty($this->configDir)) {
         fputs($fp, "cfg_dir=" . $this->configDir . "/objects\n");
     } else {
         fputs($fp, "cfg_dir=" . $mainConfig->getConfigDir() . "/objects\n");
     }
     $job->addNotice("NagiosMainExporter complete.");
     return true;
 }
 public function getValues()
 {
     $values = array();
     $fieldNames = NagiosMainConfigurationPeer::getFieldNames(BasePeer::TYPE_FIELDNAME);
     foreach ($fieldNames as $fieldName) {
         $method = "get" . NagiosMainConfigurationPeer::translateFieldName($fieldName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         $val = $this->{$method}();
         if ($val !== null) {
             $values[$fieldName] = array();
             $values[$fieldName]['value'] = $val;
             $values[$fieldName]['source']['id'] = null;
             $values[$fieldName]['inherited'] = false;
         }
     }
     return $values;
 }
Exemple #3
0
 public function export()
 {
     // Grab our export job
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("NagiosCgiExporter attempting to export cgi configuration.");
     // Grab our cgi config
     $cgiConfig = NagiosCgiConfigurationPeer::doSelectOne(new Criteria());
     if (!$cgiConfig) {
         $job->addError("Unable to get CGI Configuration object.  Your Lilac database is corrupt.");
         return false;
     }
     $finalArray = array();
     $values = $cgiConfig->toArray(BasePeer::TYPE_FIELDNAME);
     foreach ($values as $key => $value) {
         if ($key == 'id') {
             continue;
         }
         if ($value === null) {
             continue;
         }
         if ($value === false) {
             $value = '0';
         }
         $finalArray[$key] = $value;
     }
     // get our main config
     $mainConfig = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     $configdir = $mainConfig->getConfigDir();
     $finalArray['main_config_file'] = $configdir . "/nagios.cfg";
     $fp = $this->getOutputFile();
     fputs($fp, "# Written by NagiosCgiExporter from " . LILAC_NAME . " " . LILAC_VERSION . " on " . date("F j, Y, g:i a") . "\n\n");
     foreach ($finalArray as $key => $val) {
         fputs($fp, $key . "=" . $val . "\n");
     }
     /*    Added by Romain Dessort (Evolix) on 08/02/2011:
      *
      *  nagios_check_command directive is required by Nagios, but
      *  Lilac does not allow to change this parameter in the web
      *  interface. I set it here.
      */
     fputs($fp, "nagios_check_command=/usr/lib/nagios/plugins/check_nagios /var/cache/nagios3/status.dat 5 '/usr/sbin/nagios3'\n");
     $job->addNotice("NagiosCgiExporter complete.");
     return true;
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(NagiosMainConfigurationPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $criteria->add(NagiosMainConfigurationPeer::ID, $pks, Criteria::IN);
         $objs = NagiosMainConfigurationPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Exemple #5
0
 public function export()
 {
     $job = $this->getJob();
     $job->addNotice("NagiosExportEngine beginning export...");
     $config = $this->getConfig();
     // Main Configuration
     $fp = @fopen($this->exportDir . "/nagios.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/nagios.cfg for writing.");
         return false;
     }
     $exporter = new NagiosMainExporter($this, $fp);
     $exporter->setConfigDir($this->exportDir);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Main exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Main Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // CGI Configuration
     $fp = @fopen($this->exportDir . "/cgi.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/cgi.cfg for writing.");
         return false;
     }
     $exporter = new NagiosCgiExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up CGI exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("CGI Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Resource Configuration
     $fp = @fopen($this->exportDir . "/resource.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/resource.cfg for writing.");
         return false;
     }
     $exporter = new NagiosResourceExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Resource exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Resource Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Command Configuration
     $fp = @fopen($this->exportDir . "/objects/commands.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/commands.cfg for writing.");
         return false;
     }
     $exporter = new NagiosCommandExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Command exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Command Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Timeperiod Configuration
     $fp = @fopen($this->exportDir . "/objects/timeperiods.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/timeperiods.cfg for writing.");
         return false;
     }
     $exporter = new NagiosTimePeriodExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Timeperiod exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Time Period Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Contact Configuration
     $fp = @fopen($this->exportDir . "/objects/contacts.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/contacts.cfg for writing.");
         return false;
     }
     $exporter = new NagiosContactExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Contact exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Contact Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Contact Group Configuration
     $fp = @fopen($this->exportDir . "/objects/contactgroups.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/contactgroups.cfg for writing.");
         return false;
     }
     $exporter = new NagiosContactGroupExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Contact Group exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Contact Group Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Host Group Configuration
     $fp = @fopen($this->exportDir . "/objects/hostgroups.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/hostgroups.cfg for writing.");
         return false;
     }
     $exporter = new NagiosHostGroupExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Host Group exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Host Group Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Service Group Configuration
     $fp = @fopen($this->exportDir . "/objects/servicegroups.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/servicegroups.cfg for writing.");
         return false;
     }
     $exporter = new NagiosServiceGroupExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Service Group exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Service Group Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Host Configuration
     $fp = @fopen($this->exportDir . "/objects/hosts.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/hosts.cfg for writing.");
         return false;
     }
     $exporter = new NagiosHostExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Host exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Host Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Service Configuration
     $fp = @fopen($this->exportDir . "/objects/services.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/services.cfg for writing.");
         return false;
     }
     $exporter = new NagiosServiceExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Service exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Service Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Dependency Configuration
     $fp = @fopen($this->exportDir . "/objects/dependencies.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/dependencies.cfg for writing.");
         return false;
     }
     $exporter = new NagiosDependencyExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Dependency exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Dependency Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Escalation Configuration
     $fp = @fopen($this->exportDir . "/objects/escalations.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/objects/escalations.cfg for writing.");
         return false;
     }
     $exporter = new NagiosEscalationExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Escalation exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Escalation Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     $job->addNotice("Finished exporting objects.");
     // Finished exporting, let's check if we need to do the preflight
     if ($config->getVar("preflight_check")) {
         exec($this->verifyCmd . " -v " . $this->exportDir . "/nagios.cfg", $output, $retVal);
         if ($retVal != 0) {
             if ($retVal == 127) {
                 $job->addError("The command to verify your configuration: " . $this->verifyCmd . " was not found (127).");
             } else {
                 $job->addError("Nagios Sanity Check Failed.  Did not write configuration files to production.  Output is as follows:");
                 foreach ($output as $outputLine) {
                     $job->addError($outputLine);
                 }
             }
             $job->addError("Export failed.");
             return false;
         } else {
             $job->addNotice("Nagios Sanity Check Passed.");
         }
     }
     // Now need to re-export main configuration file, so config dir's point
     // to right location
     $fp = @fopen($this->exportDir . "/nagios.cfg", "w");
     if (!$fp) {
         $job->addError("Unable to open " . $this->exportDir . "/nagios.cfg for writing.");
         return false;
     }
     $exporter = new NagiosMainExporter($this, $fp);
     $exporter->init();
     if (!$exporter->valid()) {
         $this->addQueuedExporter($exporter);
         $job->addNotice("NagiosImportEngine queueing up Main exporter until dependencies are valid.");
     } else {
         if (!$exporter->export()) {
             $job->addError("Main Exporter failed export.  Bailing out of job...");
             return false;
         }
     }
     // Move the configuration files to the appropriate place.
     $mainConfiguration = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     if (!$this->dir_copy($this->exportDir, $mainConfiguration->getConfigDir())) {
         $job->addError("Unable to copy configuration files to : " . $mainConfiguration->getConfigDir());
         $job->addError("Export failed.");
         return false;
     }
     // Check if we have to restart
     if ($config->getVar("restart_nagios")) {
         $output = null;
         exec($this->restartCmd, $output, $retVal);
         if ($retVal != 0) {
             if ($retVal == 127) {
                 $job->addError("The command to restart Nagios: " . $this->restartCmd . " was not found (127).");
             } else {
                 $job->addError("Nagios Restart Failed.  You need to manually restart Nagios");
                 foreach ($output as $outputLine) {
                     $job->addError($outputLine);
                 }
             }
             $job->addError("Restart failed.");
             return false;
         }
         $job->addNotice("Nagios Restarted Successfully.");
     }
     return true;
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = NagiosMainConfigurationPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setConfigDir($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setLogFile($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setTempFile($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setStatusFile($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setStatusUpdateInterval($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setNagiosUser($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setNagiosGroup($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setEnableNotifications($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setExecuteServiceChecks($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setAcceptPassiveServiceChecks($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setEnableEventHandlers($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setLogRotationMethod($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setLogArchivePath($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setCheckExternalCommands($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setCommandCheckInterval($arr[$keys[15]]);
     }
     if (array_key_exists($keys[16], $arr)) {
         $this->setCommandFile($arr[$keys[16]]);
     }
     if (array_key_exists($keys[17], $arr)) {
         $this->setLockFile($arr[$keys[17]]);
     }
     if (array_key_exists($keys[18], $arr)) {
         $this->setRetainStateInformation($arr[$keys[18]]);
     }
     if (array_key_exists($keys[19], $arr)) {
         $this->setStateRetentionFile($arr[$keys[19]]);
     }
     if (array_key_exists($keys[20], $arr)) {
         $this->setRetentionUpdateInterval($arr[$keys[20]]);
     }
     if (array_key_exists($keys[21], $arr)) {
         $this->setUseRetainedProgramState($arr[$keys[21]]);
     }
     if (array_key_exists($keys[22], $arr)) {
         $this->setUseSyslog($arr[$keys[22]]);
     }
     if (array_key_exists($keys[23], $arr)) {
         $this->setLogNotifications($arr[$keys[23]]);
     }
     if (array_key_exists($keys[24], $arr)) {
         $this->setLogServiceRetries($arr[$keys[24]]);
     }
     if (array_key_exists($keys[25], $arr)) {
         $this->setLogHostRetries($arr[$keys[25]]);
     }
     if (array_key_exists($keys[26], $arr)) {
         $this->setLogEventHandlers($arr[$keys[26]]);
     }
     if (array_key_exists($keys[27], $arr)) {
         $this->setLogInitialStates($arr[$keys[27]]);
     }
     if (array_key_exists($keys[28], $arr)) {
         $this->setLogExternalCommands($arr[$keys[28]]);
     }
     if (array_key_exists($keys[29], $arr)) {
         $this->setLogPassiveChecks($arr[$keys[29]]);
     }
     if (array_key_exists($keys[30], $arr)) {
         $this->setGlobalHostEventHandler($arr[$keys[30]]);
     }
     if (array_key_exists($keys[31], $arr)) {
         $this->setGlobalServiceEventHandler($arr[$keys[31]]);
     }
     if (array_key_exists($keys[32], $arr)) {
         $this->setExternalCommandBufferSlots($arr[$keys[32]]);
     }
     if (array_key_exists($keys[33], $arr)) {
         $this->setSleepTime($arr[$keys[33]]);
     }
     if (array_key_exists($keys[34], $arr)) {
         $this->setServiceInterleaveFactor($arr[$keys[34]]);
     }
     if (array_key_exists($keys[35], $arr)) {
         $this->setMaxConcurrentChecks($arr[$keys[35]]);
     }
     if (array_key_exists($keys[36], $arr)) {
         $this->setServiceReaperFrequency($arr[$keys[36]]);
     }
     if (array_key_exists($keys[37], $arr)) {
         $this->setIntervalLength($arr[$keys[37]]);
     }
     if (array_key_exists($keys[38], $arr)) {
         $this->setUseAggressiveHostChecking($arr[$keys[38]]);
     }
     if (array_key_exists($keys[39], $arr)) {
         $this->setEnableFlapDetection($arr[$keys[39]]);
     }
     if (array_key_exists($keys[40], $arr)) {
         $this->setLowServiceFlapThreshold($arr[$keys[40]]);
     }
     if (array_key_exists($keys[41], $arr)) {
         $this->setHighServiceFlapThreshold($arr[$keys[41]]);
     }
     if (array_key_exists($keys[42], $arr)) {
         $this->setLowHostFlapThreshold($arr[$keys[42]]);
     }
     if (array_key_exists($keys[43], $arr)) {
         $this->setHighHostFlapThreshold($arr[$keys[43]]);
     }
     if (array_key_exists($keys[44], $arr)) {
         $this->setSoftStateDependencies($arr[$keys[44]]);
     }
     if (array_key_exists($keys[45], $arr)) {
         $this->setServiceCheckTimeout($arr[$keys[45]]);
     }
     if (array_key_exists($keys[46], $arr)) {
         $this->setHostCheckTimeout($arr[$keys[46]]);
     }
     if (array_key_exists($keys[47], $arr)) {
         $this->setEventHandlerTimeout($arr[$keys[47]]);
     }
     if (array_key_exists($keys[48], $arr)) {
         $this->setNotificationTimeout($arr[$keys[48]]);
     }
     if (array_key_exists($keys[49], $arr)) {
         $this->setOcspTimeout($arr[$keys[49]]);
     }
     if (array_key_exists($keys[50], $arr)) {
         $this->setOhcpTimeout($arr[$keys[50]]);
     }
     if (array_key_exists($keys[51], $arr)) {
         $this->setPerfdataTimeout($arr[$keys[51]]);
     }
     if (array_key_exists($keys[52], $arr)) {
         $this->setObsessOverServices($arr[$keys[52]]);
     }
     if (array_key_exists($keys[53], $arr)) {
         $this->setOcspCommand($arr[$keys[53]]);
     }
     if (array_key_exists($keys[54], $arr)) {
         $this->setProcessPerformanceData($arr[$keys[54]]);
     }
     if (array_key_exists($keys[55], $arr)) {
         $this->setCheckForOrphanedServices($arr[$keys[55]]);
     }
     if (array_key_exists($keys[56], $arr)) {
         $this->setCheckServiceFreshness($arr[$keys[56]]);
     }
     if (array_key_exists($keys[57], $arr)) {
         $this->setFreshnessCheckInterval($arr[$keys[57]]);
     }
     if (array_key_exists($keys[58], $arr)) {
         $this->setDateFormat($arr[$keys[58]]);
     }
     if (array_key_exists($keys[59], $arr)) {
         $this->setIllegalObjectNameChars($arr[$keys[59]]);
     }
     if (array_key_exists($keys[60], $arr)) {
         $this->setIllegalMacroOutputChars($arr[$keys[60]]);
     }
     if (array_key_exists($keys[61], $arr)) {
         $this->setAdminEmail($arr[$keys[61]]);
     }
     if (array_key_exists($keys[62], $arr)) {
         $this->setAdminPager($arr[$keys[62]]);
     }
     if (array_key_exists($keys[63], $arr)) {
         $this->setExecuteHostChecks($arr[$keys[63]]);
     }
     if (array_key_exists($keys[64], $arr)) {
         $this->setServiceInterCheckDelayMethod($arr[$keys[64]]);
     }
     if (array_key_exists($keys[65], $arr)) {
         $this->setUseRetainedSchedulingInfo($arr[$keys[65]]);
     }
     if (array_key_exists($keys[66], $arr)) {
         $this->setAcceptPassiveHostChecks($arr[$keys[66]]);
     }
     if (array_key_exists($keys[67], $arr)) {
         $this->setMaxServiceCheckSpread($arr[$keys[67]]);
     }
     if (array_key_exists($keys[68], $arr)) {
         $this->setHostInterCheckDelayMethod($arr[$keys[68]]);
     }
     if (array_key_exists($keys[69], $arr)) {
         $this->setMaxHostCheckSpread($arr[$keys[69]]);
     }
     if (array_key_exists($keys[70], $arr)) {
         $this->setAutoRescheduleChecks($arr[$keys[70]]);
     }
     if (array_key_exists($keys[71], $arr)) {
         $this->setAutoReschedulingInterval($arr[$keys[71]]);
     }
     if (array_key_exists($keys[72], $arr)) {
         $this->setAutoReschedulingWindow($arr[$keys[72]]);
     }
     if (array_key_exists($keys[73], $arr)) {
         $this->setOchpTimeout($arr[$keys[73]]);
     }
     if (array_key_exists($keys[74], $arr)) {
         $this->setObsessOverHosts($arr[$keys[74]]);
     }
     if (array_key_exists($keys[75], $arr)) {
         $this->setOchpCommand($arr[$keys[75]]);
     }
     if (array_key_exists($keys[76], $arr)) {
         $this->setCheckHostFreshness($arr[$keys[76]]);
     }
     if (array_key_exists($keys[77], $arr)) {
         $this->setHostFreshnessCheckInterval($arr[$keys[77]]);
     }
     if (array_key_exists($keys[78], $arr)) {
         $this->setServiceFreshnessCheckInterval($arr[$keys[78]]);
     }
     if (array_key_exists($keys[79], $arr)) {
         $this->setUseRegexpMatching($arr[$keys[79]]);
     }
     if (array_key_exists($keys[80], $arr)) {
         $this->setUseTrueRegexpMatching($arr[$keys[80]]);
     }
     if (array_key_exists($keys[81], $arr)) {
         $this->setEventBrokerOptions($arr[$keys[81]]);
     }
     if (array_key_exists($keys[82], $arr)) {
         $this->setDaemonDumpsCore($arr[$keys[82]]);
     }
     if (array_key_exists($keys[83], $arr)) {
         $this->setHostPerfdataCommand($arr[$keys[83]]);
     }
     if (array_key_exists($keys[84], $arr)) {
         $this->setServicePerfdataCommand($arr[$keys[84]]);
     }
     if (array_key_exists($keys[85], $arr)) {
         $this->setHostPerfdataFile($arr[$keys[85]]);
     }
     if (array_key_exists($keys[86], $arr)) {
         $this->setHostPerfdataFileTemplate($arr[$keys[86]]);
     }
     if (array_key_exists($keys[87], $arr)) {
         $this->setServicePerfdataFile($arr[$keys[87]]);
     }
     if (array_key_exists($keys[88], $arr)) {
         $this->setServicePerfdataFileTemplate($arr[$keys[88]]);
     }
     if (array_key_exists($keys[89], $arr)) {
         $this->setHostPerfdataFileMode($arr[$keys[89]]);
     }
     if (array_key_exists($keys[90], $arr)) {
         $this->setServicePerfdataFileMode($arr[$keys[90]]);
     }
     if (array_key_exists($keys[91], $arr)) {
         $this->setHostPerfdataFileProcessingCommand($arr[$keys[91]]);
     }
     if (array_key_exists($keys[92], $arr)) {
         $this->setServicePerfdataFileProcessingCommand($arr[$keys[92]]);
     }
     if (array_key_exists($keys[93], $arr)) {
         $this->setHostPerfdataFileProcessingInterval($arr[$keys[93]]);
     }
     if (array_key_exists($keys[94], $arr)) {
         $this->setServicePerfdataFileProcessingInterval($arr[$keys[94]]);
     }
     if (array_key_exists($keys[95], $arr)) {
         $this->setObjectCacheFile($arr[$keys[95]]);
     }
     if (array_key_exists($keys[96], $arr)) {
         $this->setPrecachedObjectFile($arr[$keys[96]]);
     }
     if (array_key_exists($keys[97], $arr)) {
         $this->setRetainedHostAttributeMask($arr[$keys[97]]);
     }
     if (array_key_exists($keys[98], $arr)) {
         $this->setRetainedServiceAttributeMask($arr[$keys[98]]);
     }
     if (array_key_exists($keys[99], $arr)) {
         $this->setRetainedProcessHostAttributeMask($arr[$keys[99]]);
     }
     if (array_key_exists($keys[100], $arr)) {
         $this->setRetainedProcessServiceAttributeMask($arr[$keys[100]]);
     }
     if (array_key_exists($keys[101], $arr)) {
         $this->setRetainedContactHostAttributeMask($arr[$keys[101]]);
     }
     if (array_key_exists($keys[102], $arr)) {
         $this->setRetainedContactServiceAttributeMask($arr[$keys[102]]);
     }
     if (array_key_exists($keys[103], $arr)) {
         $this->setCheckResultReaperFrequency($arr[$keys[103]]);
     }
     if (array_key_exists($keys[104], $arr)) {
         $this->setMaxCheckResultReaperTime($arr[$keys[104]]);
     }
     if (array_key_exists($keys[105], $arr)) {
         $this->setCheckResultPath($arr[$keys[105]]);
     }
     if (array_key_exists($keys[106], $arr)) {
         $this->setMaxCheckResultFileAge($arr[$keys[106]]);
     }
     if (array_key_exists($keys[107], $arr)) {
         $this->setTranslatePassiveHostChecks($arr[$keys[107]]);
     }
     if (array_key_exists($keys[108], $arr)) {
         $this->setPassiveHostChecksAreSoft($arr[$keys[108]]);
     }
     if (array_key_exists($keys[109], $arr)) {
         $this->setEnablePredictiveHostDependencyChecks($arr[$keys[109]]);
     }
     if (array_key_exists($keys[110], $arr)) {
         $this->setEnablePredictiveServiceDependencyChecks($arr[$keys[110]]);
     }
     if (array_key_exists($keys[111], $arr)) {
         $this->setCachedHostCheckHorizon($arr[$keys[111]]);
     }
     if (array_key_exists($keys[112], $arr)) {
         $this->setCachedServiceCheckHorizon($arr[$keys[112]]);
     }
     if (array_key_exists($keys[113], $arr)) {
         $this->setUseLargeInstallationTweaks($arr[$keys[113]]);
     }
     if (array_key_exists($keys[114], $arr)) {
         $this->setFreeChildProcessMemory($arr[$keys[114]]);
     }
     if (array_key_exists($keys[115], $arr)) {
         $this->setChildProcessesForkTwice($arr[$keys[115]]);
     }
     if (array_key_exists($keys[116], $arr)) {
         $this->setEnableEnvironmentMacros($arr[$keys[116]]);
     }
     if (array_key_exists($keys[117], $arr)) {
         $this->setAdditionalFreshnessLatency($arr[$keys[117]]);
     }
     if (array_key_exists($keys[118], $arr)) {
         $this->setEnableEmbeddedPerl($arr[$keys[118]]);
     }
     if (array_key_exists($keys[119], $arr)) {
         $this->setUseEmbeddedPerlImplicitly($arr[$keys[119]]);
     }
     if (array_key_exists($keys[120], $arr)) {
         $this->setP1File($arr[$keys[120]]);
     }
     if (array_key_exists($keys[121], $arr)) {
         $this->setUseTimezone($arr[$keys[121]]);
     }
     if (array_key_exists($keys[122], $arr)) {
         $this->setDebugFile($arr[$keys[122]]);
     }
     if (array_key_exists($keys[123], $arr)) {
         $this->setDebugLevel($arr[$keys[123]]);
     }
     if (array_key_exists($keys[124], $arr)) {
         $this->setDebugVerbosity($arr[$keys[124]]);
     }
     if (array_key_exists($keys[125], $arr)) {
         $this->setMaxDebugFileSize($arr[$keys[125]]);
     }
 }
Exemple #7
0
 public function import()
 {
     $job = $this->getEngine()->getJob();
     $config = $this->getEngine()->getConfig();
     $mainCfg = new NagiosMainConfiguration();
     $segment = $this->getSegment();
     $values = $segment->getValues();
     $fileName = $segment->getFilename();
     // Setup the configuration directory for the new config file to match the file we imported
     $mainCfg->setConfigDir(dirname(realpath($fileName)));
     foreach ($values as $key => $entries) {
         foreach ($entries as $entry) {
             $value = $entry['value'];
             $lineNum = $entry['line'];
             if (key_exists($key, $this->fieldMethods) && $this->fieldMethods[$key] != '') {
                 // Okay, let's check that the method DOES exist
                 if (!method_exists($mainCfg, $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], $mainCfg, $value);
                 }
             }
         }
     }
     // If we got here, it's safe to delete the existing main config and save the new one
     $oldConfig = NagiosMainConfigurationPeer::doSelectOne(new Criteria());
     if ($oldConfig) {
         $oldConfig->delete();
     }
     $mainCfg->save();
     $mainCfg->clearAllReferences(true);
     $job->addNotice("NagiosMainImporter finished importing main configuration.");
     return true;
 }
Exemple #8
0
 public function import()
 {
     global $lilac;
     $engine = $this->getEngine();
     $job = $engine->getJob();
     $job->addNotice("FruityMainImporter beginning to import Main Configuration.");
     $res = $this->dbConn->query("SELECT * FROM nagios_main");
     // Fruity has just one record in the main, if we get it, import
     // it.
     $row = $res->fetch(PDO::FETCH_ASSOC);
     // Get our main obj.
     $mainConfig = $lilac->get_main_conf();
     foreach ($row as $key => $val) {
         unset($name);
         if ($key == "id" || $key == "p1_file" || $key == "comment_file" || $key == "downtime_file" || $key == "aggregate_status_updates") {
             continue;
         }
         if ($key == "service_perfdata_template") {
             $key = "service_perfdata_file_template";
         }
         if ($key == "host_perfdata_template") {
             $key = "host_perfdata_file_template";
         }
         if ($key == "global_host_event_handler") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "global_service_event_handler") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "ocsp_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "ochp_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "host_perfdata_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "service_perfdata_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "host_perfdata_file_processing_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         if ($key == "service_perfdata_file_processing_command") {
             $commandName = $this->getCommandNameById($val);
             $command = NagiosCommandPeer::getByName($commandName);
             if ($command) {
                 $val = $command->getId();
             } else {
                 $val = null;
             }
         }
         try {
             $name = NagiosMainConfigurationPeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
         } catch (Exception $e) {
             $job->addNotice("Main Configuration: Was unable to store unsupported value: " . $key);
         }
         if (!empty($name)) {
             $method = "set" . $name;
             $mainConfig->{$method}($val);
         }
     }
     $mainConfig->save();
     // Save main configuration
     // Broker modules
     foreach ($this->dbConn->query("SELECT * FROM nagios_broker_modules", PDO::FETCH_ASSOC) as $brokerModule) {
         $newModule = new NagiosBrokerModule();
         foreach ($brokerModule as $key => $val) {
             unset($name);
             if ($key == "module_id") {
                 continue;
             }
             if ($key == "module_line") {
                 $key = "line";
             }
             try {
                 $name = NagiosBrokerModulePeer::translateFieldName($key, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME);
             } catch (Exception $e) {
                 $job->addNotice("Broker Module: Was unable to store unsupported value: " . $key);
             }
             if (!empty($name)) {
                 $method = "set" . $name;
                 $newModule->{$method}($val);
             }
         }
         $newModule->save();
     }
     $job->addNotice("FruityMainImporter finished importing Main Configuration.");
 }
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return     int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = NagiosCommandPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related NagiosContactNotificationCommand objects
         $c = new Criteria(NagiosContactNotificationCommandPeer::DATABASE_NAME);
         $c->add(NagiosContactNotificationCommandPeer::COMMAND, $obj->getId());
         $affectedRows += NagiosContactNotificationCommandPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::OCSP_COMMAND, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::OCHP_COMMAND, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::HOST_PERFDATA_COMMAND, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::SERVICE_PERFDATA_COMMAND, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::HOST_PERFDATA_FILE_PROCESSING_COMMAND, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::SERVICE_PERFDATA_FILE_PROCESSING_COMMAND, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::GLOBAL_SERVICE_EVENT_HANDLER, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
         // delete related NagiosMainConfiguration objects
         $c = new Criteria(NagiosMainConfigurationPeer::DATABASE_NAME);
         $c->add(NagiosMainConfigurationPeer::GLOBAL_HOST_EVENT_HANDLER, $obj->getId());
         $affectedRows += NagiosMainConfigurationPeer::doDelete($c, $con);
     }
     return $affectedRows;
 }
Exemple #10
0
 /**
  * Returns the number of related NagiosMainConfiguration objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related NagiosMainConfiguration objects.
  * @throws     PropelException
  */
 public function countNagiosMainConfigurationsRelatedByGlobalHostEventHandler(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(NagiosCommandPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collNagiosMainConfigurationsRelatedByGlobalHostEventHandler === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(NagiosMainConfigurationPeer::GLOBAL_HOST_EVENT_HANDLER, $this->id);
             $count = NagiosMainConfigurationPeer::doCount($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(NagiosMainConfigurationPeer::GLOBAL_HOST_EVENT_HANDLER, $this->id);
             if (!isset($this->lastNagiosMainConfigurationRelatedByGlobalHostEventHandlerCriteria) || !$this->lastNagiosMainConfigurationRelatedByGlobalHostEventHandlerCriteria->equals($criteria)) {
                 $count = NagiosMainConfigurationPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collNagiosMainConfigurationsRelatedByGlobalHostEventHandler);
             }
         } else {
             $count = count($this->collNagiosMainConfigurationsRelatedByGlobalHostEventHandler);
         }
     }
     return $count;
 }
Exemple #11
0
 public function import()
 {
     $job = $this->getJob();
     $job->addNotice("FruityImportEngine beginning import...");
     $config = $this->getConfig();
     $job->addNotice("Removing existing Nagios objects.");
     NagiosTimeperiodPeer::doDeleteAll();
     NagiosCommandPeer::doDeleteAll();
     NagiosContactPeer::doDeleteAll();
     NagiosContactGroupPeer::doDeleteAll();
     NagiosHostTemplatePeer::doDeleteAll();
     NagiosHostPeer::doDeleteAll();
     NagiosHostgroupPeer::doDeleteAll();
     NagiosServiceGroupPeer::doDeleteAll();
     NagiosServiceTemplatePeer::doDeleteAll();
     NagiosServicePeer::doDeleteAll();
     NagiosDependencyPeer::doDeleteAll();
     NagiosDependencyTargetPeer::doDeleteAll();
     NagiosEscalationPeer::doDeleteAll();
     NagiosBrokerModulePeer::doDeleteAll();
     NagiosMainConfigurationPeer::doDeleteAll();
     NagiosCgiConfigurationPeer::doDeleteAll();
     $importer = new FruityResourceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCgiImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityCommandImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityTimeperiodImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityContactImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostTemplateImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostGroupImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityHostImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityServiceImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityDependencyImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityEscalationImporter($this, $this->dbConn);
     $importer->import();
     $importer = new FruityMainImporter($this, $this->dbConn);
     $importer->import();
     $job->addNotice("FruityImportEngine completed job.");
     return true;
 }