/** 
  * Generate modules configuration files
  * @param array $filesList
  * @param int $pollerId
  * @param string $path
  * @param object $event
  * @return value
  */
 public function generate(&$filesList, $pollerId, $path, $event)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     $modules = array();
     /* Retrieve broker modules */
     $events = Di::getDefault()->get('events');
     $moduleEvent = new BrokerModuleEvent($pollerId);
     $events->emit('centreon-configuration.broker.module', array($moduleEvent));
     $brokerModules = $moduleEvent->getModules();
     foreach ($brokerModules as $brokerModule) {
         $modules[]['broker_module'] = $brokerModule;
     }
     /* External command module */
     $moduleDir = Engine::getParameters($pollerId, 'module_dir');
     $modules[]['broker_module'] = rtrim($moduleDir['module_dir'], '/') . '/externalcmd.so';
     /* Write modules configuration files */
     foreach ($modules as $module) {
         $filename = preg_match('/\\/?(\\w+)\\.so/', $module['broker_module'], $matches);
         if (!empty($matches[1])) {
             WriteConfigFile::writeParamsFile($module, $path . $pollerId . "/conf.d/" . $matches[1] . '.cfg', $filesList, $user = "******");
         }
     }
 }
Exemple #2
0
 public static function generate(&$filesList, $poller_id, $path, $filename)
 {
     $content = '';
     /* Write Check-Command configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/objects.d/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /**
  * Method for generating Main configuration file
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  * @param int $testing
  */
 public static function generate(&$filesList, $poller_id, $path, $filename, $testing = 0)
 {
     static::$path = rtrim($path, '/');
     /* Get Content */
     $content = static::getContent($poller_id, $filesList, $testing);
     /* Write Check-Command configuration file */
     WriteConfigFile::writeParamsFile($content, $path . $poller_id . "/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /** 
  * Generate Resources.cfg
  * @param array $filesList
  * @param int $pollerId
  * @param string $path
  * @param string $filename
  * @return value
  */
 public function generate(&$filesList, $pollerId, $path, $filename)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     /* Init Content Array */
     $content = array();
     /* Get information into the database. */
     $query = "SELECT resource_name, resource_line \n                  FROM cfg_resources r, cfg_resources_instances_relations rr \n                  WHERE r.resource_id = rr.resource_id \n                  AND r.resource_activate = '1' \n                  AND rr.instance_id = ? \n                  ORDER BY resource_name";
     $stmt = $dbconn->prepare($query);
     $stmt->execute(array($pollerId));
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $content[$row["resource_name"]] = $row["resource_line"];
     }
     /* Write Check-Command configuration file */
     WriteConfigFile::writeParamsFile($content, $path . $pollerId . "/conf.d/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  */
 public function generate(&$filesList, $poller_id, $path, $filename)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     $enableField = array("tp_id" => 1);
     /* Init Content Array */
     $content = array();
     /* Get information into the database. */
     $queryDowntimePeriods = 'SELECT dt_id, dtp_id, dtp_start_time, dtp_end_time, dtp_duration, dtp_day_of_week, dtp_day_of_month' . ' FROM cfg_downtimes_periods' . ' ORDER BY dt_id,dtp_id';
     $stmtDowntimePeriods = $dbconn->prepare($queryDowntimePeriods);
     $stmtDowntimePeriods->execute();
     $result = $stmtDowntimePeriods->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_ASSOC);
     foreach ($result as $key => $value) {
         $tmp = array("type" => "timeperiod");
         foreach ($value as $subvalue) {
             $tmpData = array();
             $tmpData['timeperiod_name'] = 'downtime_' . $key . '_' . $subvalue['dtp_id'];
             $subvalue['dtp_start_time'] = preg_replace('/(\\d+:\\d+):\\d+/', '$1', $subvalue['dtp_start_time']);
             $subvalue['dtp_end_time'] = preg_replace('/(\\d+:\\d+):\\d+/', '$1', $subvalue['dtp_end_time']);
             if (isset($subvalue['dtp_day_of_week'])) {
                 $dayOfWeek = explode(',', $subvalue['dtp_day_of_week']);
                 foreach ($dayOfWeek as $day) {
                     $tmpData[static::$week[$day]] = $subvalue['dtp_start_time'] . ',' . $subvalue['dtp_end_time'];
                 }
             }
             if (isset($subvalue['dtp_day_of_month']) && preg_match('/\\d$/', $subvalue['dtp_day_of_month'])) {
                 $tmpData['day' . ' ' . $subvalue['dtp_day_of_month']] = $subvalue['dtp_start_time'] . ',' . $subvalue['dtp_end_time'];
             } else {
                 if (isset($subvalue['dtp_day_of_month'])) {
                     $daysOfMonth = json_decode($subvalue['dtp_day_of_month'], true);
                     foreach ($daysOfMonth as $dayOfMonth) {
                         $tmpData[static::$week[$dayOfMonth['wday']] . ' ' . $dayOfMonth['nthDay']] = $subvalue['dtp_start_time'] . ',' . $subvalue['dtp_end_time'];
                     }
                 }
             }
             $tmp["content"] = $tmpData;
             $content[] = $tmp;
         }
     }
     /* Write Check-Command configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  */
 public function generate(&$filesList, $poller_id, $path, $filename)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     /* Init Content Array */
     $content = array();
     /* Get information into the database. */
     $query = "SELECT name AS connector_name, command_line AS connector_line " . "FROM cfg_connectors WHERE enabled = 1 " . "ORDER BY name";
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $tmp = array("type" => "connector");
         $tmpData = array();
         foreach ($row as $key => $value) {
             $tmpData[$key] = $value;
         }
         $tmp["content"] = $tmpData;
         $content[] = $tmp;
     }
     /* Write Check-Command configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/objects.d/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  * @param CentreonEngine\Events\GetMacroHost $hostMacroEvent
  */
 public static function generate(&$filesList, $poller_id, $path, $filename, $hostMacroEvent)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     /* Get disfield */
     $disableFields = static::getTripleChoice();
     /* Init Content Array */
     $content = array();
     /* Get information into the database. */
     $fields = static::getFields();
     $query = "SELECT {$fields}\n            FROM cfg_hosts \n            WHERE host_activate = '1' \n            AND host_register = ? \n            ORDER BY host_name";
     $stmt = $dbconn->prepare($query);
     $stmt->execute(array(static::$register));
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $tmp = array("type" => "host");
         $tmpData = array();
         $args = "";
         $host_id = null;
         foreach ($row as $key => $value) {
             if ($key == "host_id") {
                 $host_id = $row["host_id"];
             } elseif ($key == "host_snmp_community" && $value != "") {
                 $tmpData["_SNMPCOMMUNITY"] = $value;
             } elseif ($key == "host_snmp_version" && $value != "") {
                 $tmpData["_SNMPVERSION"] = $value;
             } elseif (isset($disableField[$key]) && $value != 2 && $value != "") {
                 $key = str_replace("host_", "", $key);
                 $tmpData[$key] = $value;
             } elseif (!isset($disableField[$key]) && $value != "") {
                 $key = str_replace("host_", "", $key);
                 if ($key == 'command_command_id_arg1' || $key == 'command_command_id_arg2') {
                     $args = $value;
                 } else {
                     if ($key == 'check_command' || $key == 'event_handler') {
                         $value = CommandConfigurationRepository::getCommandName($value) . $args;
                         $args = "";
                     } else {
                         if ($key == 'check_period') {
                             $value = TimePeriodConfigurationRepository::getPeriodName($value);
                         }
                     }
                 }
                 $tmpData[$key] = $value;
             }
         }
         if (!is_null($host_id)) {
             $templates = HostTemplateConfigurationRepository::getTemplates($host_id);
             if ($templates != "") {
                 $tmpData['use'] = $templates;
             }
         }
         /* Generate macro */
         $macros = CustomMacroRepository::loadHostCustomMacro($host_id);
         if (is_array($macros) && count($macros)) {
             foreach ($macros as $macro) {
                 if (preg_match('/^\\$_HOST(.+)\\$$/', $macro['macro_name'], $m)) {
                     $name = "_{$m[1]}";
                     $tmpData[$name] = $macro['macro_value'];
                 }
             }
         }
         /* Macros that can be generated from other modules */
         $extraMacros = $hostMacroEvent->getMacro($host_id);
         foreach ($extraMacros as $macroName => $macroValue) {
             $macroName = "_{$macroName}";
             $tmpData[$macroName] = $macroValue;
         }
         $tmpData['register'] = 0;
         $tmp["content"] = $tmpData;
         $content[] = $tmp;
     }
     /* Write Check-Command configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/objects.d/" . $filename, $filesList, "API");
     unset($content);
 }
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  */
 private function generateMiscCommand(&$filesList, $poller_id, $path, $filename)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     /* Init Content Array */
     $content = array();
     /* Filter column that we want to include into the files */
     $enableField = array("command_name" => 1, "command_line" => 1, "command_example" => 1);
     $commentField = array("command_example" => 1);
     /* Get information into the database. */
     $query = "SELECT * FROM cfg_commands WHERE command_type = 1 ORDER BY command_name";
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $tmp = array("type" => "command");
         $tmpData = array();
         foreach ($row as $key => $value) {
             if (isset($enableField[$key])) {
                 if (isset($commentField[$key])) {
                     $key = "#" . $key;
                 }
                 if ($key == "command_line" && $row['enable_shell'] == 1) {
                     $value = "/bin/sh -c " . escapeshellarg($value);
                 }
                 if ($key == "command_line") {
                     /* TODO : get the real mailer */
                     $value = str_replace("@MAILER@", "/bin/mail", $value);
                 }
                 $tmpData[$key] = $value;
             }
         }
         $tmp["content"] = $tmpData;
         $content[] = $tmp;
         unset($tmp);
         unset($tmpData);
         unset($row);
     }
     /* Write Check-Command configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/objects.d/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  * @param CentreonEngine\Events\GetMacroService $serviceMacroEvent
  */
 public static function generate(&$filesList, $poller_id, $path, $filename, $serviceMacroEvent)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     /* Field to not display */
     $disableField = static::getTripleChoice();
     $field = "service_id, service_description, service_alias, service_template_model_stm_id, " . "command_command_id_arg, command_command_id AS check_command, timeperiod_tp_id AS check_period, " . "command_command_id_arg2, command_command_id2 AS event_handler, service_is_volatile, " . "service_max_check_attempts, service_normal_check_interval, service_retry_check_interval, " . "service_active_checks_enabled, service_passive_checks_enabled, initial_state, " . "service_obsess_over_service, service_check_freshness, " . "service_freshness_threshold, service_event_handler_enabled, service_low_flap_threshold, " . "service_high_flap_threshold, service_flap_detection_enabled, service_check_timeout ";
     /* Init Content Array */
     $content = array();
     /* Get information into the database. */
     $query = "SELECT {$field} " . "FROM cfg_services " . "WHERE service_activate = '1' " . "AND service_register = '0' " . "ORDER BY service_description";
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $tmp = array("type" => "service");
         $tmpData = array();
         $args = "";
         foreach ($row as $key => $value) {
             if ($key == "service_id") {
                 $service_id = $row["service_id"];
             } elseif (isset($disableField[$key]) && $value != 2 && $value != "") {
                 $key = str_replace("service_", "", $key);
                 $tmpData[$key] = $value;
             } elseif (!isset($disableField[$key]) && $value != "") {
                 $writeParam = 1;
                 $key = str_replace("service_", "", $key);
                 if ($key == 'description') {
                     $key = "name";
                 } else {
                     if ($key == 'alias') {
                         $key = "service_description";
                     } else {
                         if ($key == 'normal_check_interval') {
                             $key = "check_interval";
                         } else {
                             if ($key == 'retry_check_interval') {
                                 $key = "retry_interval";
                             } else {
                                 if ($key == 'command_command_id_arg' || $key == 'command_command_id_arg2') {
                                     $args = $value;
                                     $writeParam = 0;
                                 } else {
                                     if ($key == 'check_command' || $key == 'event_handler') {
                                         $value = CommandConfigurationRepository::getCommandName($value) . html_entity_decode($args);
                                         $args = "";
                                     } else {
                                         if ($key == 'check_period') {
                                             $value = TimePeriodConfigurationRepository::getPeriodName($value);
                                         } else {
                                             if ($key == "template_model_stm_id") {
                                                 $key = "use";
                                                 $value = ServicetemplateConfigurationRepository::getTemplateName($value);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($writeParam == 1) {
                     $tmpData[$key] = $value;
                 }
             }
         }
         /* Generate macro */
         $macros = CustomMacroRepository::loadServiceCustomMacro($service_id);
         if (is_array($macros) && count($macros)) {
             foreach ($macros as $macro) {
                 if (preg_match('/^\\$_SERVICE(.+)\\$$/', $macro['macro_name'], $m)) {
                     $name = "_{$m[1]}";
                     $tmpData[$name] = $macro['macro_value'];
                 }
             }
         }
         /* Macros that can be generated from other modules */
         $extraMacros = $serviceMacroEvent->getMacro($service_id);
         foreach ($extraMacros as $macroName => $macroValue) {
             $macroName = "_{$macroName}";
             $tmpData[$macroName] = $macroValue;
         }
         $tmpData['register'] = 0;
         $tmp["content"] = $tmpData;
         $content[] = $tmp;
     }
     /* Write Check-Command configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/objects.d/" . $filename, $filesList, $user = "******");
     unset($content);
 }
Exemple #10
0
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  */
 public function generate(&$filesList, $poller_id, $path, $filename)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     $enableField = array("tp_id" => 1);
     /* Init Content Array */
     $content = array();
     $timeperiodContent = array();
     $downtimes = array();
     /* Generate host downtimes */
     $query = 'SELECT d.dt_id, d.dt_name, dp.dtp_id, dp.dtp_fixed, dp.dtp_duration, dhr.host_host_id' . ' FROM cfg_downtimes d, cfg_downtimes_periods dp, cfg_downtimes_hosts_relations dhr' . ' WHERE d.dt_id=dhr.dt_id AND d.dt_id=dp.dt_id' . ' ORDER BY dt_id, dtp_id';
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     $downtimes = array_merge($downtimes, $stmt->fetchAll(\PDO::FETCH_ASSOC));
     /* Generate host tag downtimes */
     $query = 'SELECT d.dt_id, d.dt_name, dp.dtp_id, dp.dtp_fixed, dp.dtp_duration, th.resource_id as host_host_id' . ' FROM cfg_downtimes d, cfg_downtimes_periods dp, cfg_downtimes_hosttags_relations dhr, cfg_tags_hosts th' . ' WHERE d.dt_id=dhr.dt_id AND d.dt_id=dp.dt_id AND dhr.host_tag_id=th.tag_id AND th.template_id=0' . ' ORDER BY dt_id, dtp_id';
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     $downtimes = array_merge($downtimes, $stmt->fetchAll(\PDO::FETCH_ASSOC));
     /* Generate service downtimes */
     $query = 'SELECT d.dt_id, d.dt_name, dp.dtp_id, dp.dtp_fixed, dp.dtp_duration, hsr.host_host_id, dsr.service_service_id' . ' FROM cfg_downtimes d, cfg_downtimes_periods dp, cfg_downtimes_services_relations dsr, cfg_hosts_services_relations hsr' . ' WHERE d.dt_id=dsr.dt_id AND dsr.service_service_id=hsr.service_service_id AND d.dt_id=dp.dt_id' . ' ORDER BY dt_id, dtp_id';
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     $downtimes = array_merge($downtimes, $stmt->fetchAll(\PDO::FETCH_ASSOC));
     /* Generate service tag downtimes */
     $query = 'SELECT d.dt_id, d.dt_name, dp.dtp_id, dp.dtp_fixed, dp.dtp_duration, hsr.host_host_id, hsr.service_service_id' . ' FROM cfg_downtimes d, cfg_downtimes_periods dp, cfg_downtimes_servicetags_relations dsr, cfg_tags_services ts, cfg_hosts_services_relations hsr' . ' WHERE d.dt_id=dsr.dt_id AND d.dt_id=dp.dt_id AND dsr.service_tag_id=ts.tag_id AND ts.template_id=0 AND ts.resource_id=hsr.service_service_id' . ' ORDER BY dt_id, dtp_id';
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     $downtimes = array_merge($downtimes, $stmt->fetchAll(\PDO::FETCH_ASSOC));
     foreach ($downtimes as $downtime) {
         $tmp = array("type" => "downtime");
         $tmpData = array();
         $tmpData['host_id'] = $downtime['host_host_id'];
         if (isset($downtime['service_service_id'])) {
             $tmpData['service_id'] = $downtime['service_service_id'];
         }
         $tmpData['recurring_period'] = 'downtime_' . $downtime['dt_id'] . '_' . $downtime['dtp_id'];
         $tmpData['fixed'] = $downtime['dtp_fixed'];
         if ($downtime['dtp_fixed'] == 0) {
             $tmpData['duration'] = $downtime['dtp_duration'];
         }
         $tmp["content"] = $tmpData;
         $content[] = $tmp;
     }
     /* Write configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  */
 public function generate(&$filesList, $poller_id, $path, $filename)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     $enableField = array("tp_id" => 1);
     /* Init Content Array */
     $content = array();
     /* Get information into the database. */
     $query = "SELECT * FROM cfg_timeperiods ORDER BY tp_name";
     $stmt = $dbconn->prepare($query);
     $stmt->execute();
     /* Get timeperiod exclusions */
     $queryExclusions = "SELECT ter.timeperiod_id, t.tp_name FROM cfg_timeperiods_exclude_relations ter, cfg_timeperiods t WHERE ter.timeperiod_exclude_id=t.tp_id";
     $stmtExclusions = $dbconn->prepare($queryExclusions);
     $stmtExclusions->execute();
     $timeperiodExclusions = $stmtExclusions->fetchAll(\PDO::FETCH_ASSOC);
     /* Get timeperiod inclusions */
     $queryInclusions = "SELECT tir.timeperiod_id, t.tp_name FROM cfg_timeperiods_include_relations tir, cfg_timeperiods t WHERE tir.timeperiod_include_id=t.tp_id";
     $stmtInclusions = $dbconn->prepare($queryInclusions);
     $stmtInclusions->execute();
     $timeperiodInclusions = $stmtInclusions->fetchAll(\PDO::FETCH_ASSOC);
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         $tmp = array("type" => "timeperiod");
         $tmpData = array();
         foreach ($row as $key => $value) {
             if ($key == 'organization_id' || $key == 'tp_slug') {
                 continue;
             }
             if ($key == 'tp_name') {
                 $key = "timeperiod_name";
             }
             if (!isset($enableField[$key]) && $value != "") {
                 $key = str_replace("tp_", "", $key);
                 $tmpData[$key] = $value;
             }
         }
         /* Generate exclude parameter */
         $exclusions = array();
         foreach ($timeperiodExclusions as $timeperiodExclusion) {
             if ($row['tp_id'] == $timeperiodExclusion['timeperiod_id']) {
                 $exclusions[] = $timeperiodExclusion['tp_name'];
             }
         }
         if (count($exclusions)) {
             $tmpData['exclude'] = implode(',', $exclusions);
         }
         /* Generate include parameter */
         /*$inclusions = array();
           foreach ($timeperiodInclusions as $timeperiodInclusion) {
               if ($row['tp_id'] == $timeperiodInclusion['timeperiod_id']) {
                   $inclusions[] = $timeperiodInclusion['tp_name'];
               }
           }
           if (count($inclusions)) {
               $tmpData['include'] = implode(',', $inclusions);
           }*/
         $tmp["content"] = $tmpData;
         $content[] = $tmp;
     }
     /* Write Check-Command configuration file */
     WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/objects.d/" . $filename, $filesList, $user = "******");
     unset($content);
 }
 /**
  * 
  * @param array $filesList
  * @param int $poller_id
  * @param string $path
  * @param string $filename
  * @param CentreonEngine\Events\GetMacroHost $hostMacroEvent
  * @param CentreonEngine\Events\GetMacroService $serviceMacroEvent
  */
 public static function generate(&$filesList, $poller_id, $path, $filename, $hostMacroEvent, $serviceMacroEvent)
 {
     $di = Di::getDefault();
     /* Get Database Connexion */
     $dbconn = $di->get('db_centreon');
     /* Get disabled fields */
     $disableField = static::getTripleChoice();
     /* Init Content Array */
     $content = array();
     /* Get information into the database. */
     $fields = static::getFields();
     $query = "SELECT {$fields} \n            FROM cfg_hosts \n            WHERE host_activate = '1' \n            AND (host_register = '1' \n            OR host_register = '2') \n            AND poller_id = ?\n            ORDER BY host_name";
     $stmt = $dbconn->prepare($query);
     $stmt->execute(array($poller_id));
     $hostList = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $event = $di->get('events');
     $addHostEvent = new AddHostEvent($poller_id, $hostList);
     $event->emit('centreon-engine.add.host', array($addHostEvent));
     $hostList = $addHostEvent->getHostList();
     foreach ($hostList as $host) {
         $content = array();
         $tmp = array("type" => "host");
         $tmpData = array();
         $args = "";
         $host_id = null;
         /* Write Host Properties */
         foreach ($host as $key => $value) {
             if ($key == "host_id") {
                 $host_id = $host["host_id"];
                 /* Add host_id macro for broker - This is mandatory*/
                 $tmpData["_HOST_ID"] = $host_id;
                 $host_name = "";
             } elseif ($key == "host_snmp_community" && $value != "") {
                 $tmpData["_SNMPCOMMUNITY"] = $value;
             } elseif ($key == "host_snmp_version" && $value != "") {
                 $tmpData["_SNMPVERSION"] = $value;
             } elseif (isset($disableField[$key]) && $value != 2 && $value != "") {
                 $key = str_replace("host_", "", $key);
                 $tmpData[$key] = $value;
             } elseif (!isset($disableField[$key]) && $value != "") {
                 if ($key != 'host_name') {
                     $key = str_replace("host_", "", $key);
                 } else {
                     $host_name = $value;
                 }
                 if ($key == 'command_command_id_arg1' || $key == 'command_command_id_arg2') {
                     $args = $value;
                 } else {
                     if ($key == 'check_command' || $key == 'event_handler') {
                         $value = CommandConfigurationRepository::getCommandName($value) . $args;
                         $args = "";
                     } else {
                         if ($key == 'check_period') {
                             $value = TimeperiodConfigurationRepository::getPeriodName($value);
                         } else {
                             if ($key == 'timezone_id') {
                                 $key = 'timezone';
                                 if ($value != 'NULL') {
                                     $tName = \CentreonAdministration\Models\Timezone::getParameters($value, array('name'));
                                     $value = ':' . $tName['name'];
                                 }
                             }
                         }
                     }
                 }
                 $tmpData[$key] = $value;
             }
         }
         if (!is_null($host_id)) {
             $templates = HostTemplateConfigurationRepository::getTemplates($host_id);
             if ($templates != "") {
                 $tmpData['use'] = $templates;
             }
         }
         /* Generate macro */
         $macros = CustomMacroRepository::loadHostCustomMacro($host_id);
         if (is_array($macros) && count($macros)) {
             foreach ($macros as $macro) {
                 if (preg_match('/^\\$_HOST(.+)\\$$/', $macro['macro_name'], $m)) {
                     $name = "_{$m[1]}";
                     $tmpData[$name] = $macro['macro_value'];
                 }
             }
         }
         /* Macros that can be generated from other modules */
         $extraMacros = $hostMacroEvent->getMacro($host_id);
         foreach ($extraMacros as $macroName => $macroValue) {
             $macroName = "_{$macroName}";
             $tmpData[$macroName] = $macroValue;
         }
         $tmpData['register'] = 1;
         $tmp["content"] = $tmpData;
         $content[] = $tmp;
         /* Write Service Properties */
         $services = ServiceRepository::generate($host_id, $serviceMacroEvent);
         foreach ($services as $contentService) {
             $content[] = $contentService;
         }
         WriteConfigFile::writeObjectFile($content, $path . $poller_id . "/objects.d/" . $filename . $host_name . "-" . $host_id . ".cfg", $filesList, "API");
     }
     unset($content);
 }