/** * Reload * * @return void */ public function reload($flagOnly = false) { $this->db->query("UPDATE acl_groups SET acl_group_changed = 1"); $this->db->query("UPDATE acl_resources SET changed = 1"); if ($flagOnly == false) { passthru('php ' . CentreonUtils::getCentreonPath() . '/cron/centAcl.php'); } }
/** * Display all commands * * @param string $parameters */ public function show($parameters = null) { $filters = array(); if (isset($parameters)) { $filters = array($this->object->getUniqueLabelField() => "%" . $parameters . "%"); } $params = array('command_id', 'command_name', 'command_type', 'command_line'); $paramString = str_replace("command_", "", implode($this->delim, $params)); echo $paramString . "\n"; $elements = $this->object->getList($params, -1, 0, null, null, $filters); foreach ($elements as $tab) { $tab['command_line'] = CentreonUtils::convertSpecialPattern(html_entity_decode($tab['command_line'])); $tab['command_type'] = $this->typeConversion[$tab['command_type']]; echo implode($this->delim, $tab) . "\n"; } }
/** * Set severity * * @param string $parameters * @throws CentreonClapiException */ public function setseverity($parameters) { $params = explode($this->delim, $parameters); if (count($params) < 3) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) { $level = (int) $params[1]; $iconId = CentreonUtils::getImageId($params[2]); if (is_null($iconId)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]); } $updateParams = array('level' => $level, 'icon_id' => $iconId); parent::setparam($objectId, $updateParams); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]); } }
/** * Export data * * @param string $parameters * @return void */ public function export() { $elements = $this->object->getList("*", -1, 0, null, null, array("contact_register" => $this->register), "AND"); foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim . $element[$param]; } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!is_null($value) && $value != "" && !in_array($parameter, $this->exportExcludedParams)) { if ($parameter == "timeperiod_tp_id") { $parameter = self::HOST_NOTIF_TP; $value = $this->tpObject->getObjectName($value); } elseif ($parameter == "timeperiod_tp_id2") { $parameter = self::SVC_NOTIF_TP; $value = $this->tpObject->getObjectName($value); } elseif ($parameter == "contact_lang") { $parameter = "locale"; } elseif ($parameter == "contact_host_notification_options") { $parameter = "hostnotifopt"; } elseif ($parameter == "contact_service_notification_options") { $parameter = "servicenotifopt"; } elseif ($parameter == "contact_template_id") { $parameter = "template"; $result = $this->object->getParameters($value, $this->object->getUniqueLabelField()); $value = $result[$this->object->getUniqueLabelField()]; } $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n"; } } $objId = $element[$this->object->getPrimaryKey()]; $this->exportNotifCommands(self::HOST_NOTIF_CMD, $objId, $element[$this->object->getUniqueLabelField()]); $this->exportNotifCommands(self::SVC_NOTIF_CMD, $objId, $element[$this->object->getUniqueLabelField()]); } }
/** * Export * * @return void */ public function export() { $hostRel = new Centreon_Object_Relation_Host_Service(); $elements = $hostRel->getMergedParameters(array("host_name"), array('*'), -1, 0, null, null, array("service_register" => $this->register), "AND"); $extendedObj = new Centreon_Object_Service_Extended(); $commandObj = new Centreon_Object_Command(); $tpObj = new Centreon_Object_Timeperiod(); $macroObj = new Centreon_Object_Service_Macro_Custom(); foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim; if ($param == "service_template_model_stm_id") { $tmp = $this->object->getParameters($element[$param], 'service_description'); if (isset($tmp) && isset($tmp['service_description']) && $tmp['service_description']) { $element[$param] = $tmp['service_description']; } if (!$element[$param]) { $element[$param] = ""; } } $addStr .= $element[$param]; } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") { if ($parameter == "timeperiod_tp_id" || $parameter == "timeperiod_tp_id2") { $tmpObj = $tpObj; } elseif ($parameter == "command_command_id" || $parameter == "command_command_id2") { $tmpObj = $commandObj; } if (isset($tmpObj)) { $tmp = $tmpObj->getParameters($value, $tmpObj->getUniqueLabelField()); if (isset($tmp) && isset($tmp[$tmpObj->getUniqueLabelField()])) { $value = $tmp[$tmpObj->getUniqueLabelField()]; } unset($tmpObj); } $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element['host_name'] . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $value . "\n"; } } $params = $extendedObj->getParameters($element[$this->object->getPrimaryKey()], array("esi_notes", "esi_notes_url", "esi_action_url", "esi_icon_image", "esi_icon_image_alt")); if (isset($params) && is_array($params)) { foreach ($params as $k => $v) { if (!is_null($v) && $v != "") { $v = CentreonUtils::convertLineBreak($v); echo $this->action . $this->delim . "setparam" . $this->delim . $element['host_name'] . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($k) . $this->delim . $v . "\n"; } } } $macros = $macroObj->getList("*", -1, 0, null, null, array('svc_svc_id' => $element[$this->object->getPrimaryKey()]), "AND"); foreach ($macros as $macro) { echo $this->action . $this->delim . "setmacro" . $this->delim . $element['host_name'] . $this->delim . $element['service_description'] . $this->delim . $this->stripMacro($macro['svc_macro_name']) . $this->delim . $macro['svc_macro_value'] . "\n"; } $cgRel = new Centreon_Object_Relation_Contact_Group_Service(); $cgelements = $cgRel->getMergedParameters(array("cg_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service_id" => $element['service_id']), "AND"); foreach ($cgelements as $cgelement) { echo $this->action . $this->delim . "addcontactgroup" . $this->delim . $element['host_name'] . $this->delim . $cgelement['service_description'] . $this->delim . $cgelement['cg_name'] . "\n"; } $contactRel = new Centreon_Object_Relation_Contact_Service(); $celements = $contactRel->getMergedParameters(array("contact_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service_id" => $element['service_id']), "AND"); foreach ($celements as $celement) { echo $this->action . $this->delim . "addcontact" . $this->delim . $element['host_name'] . $this->delim . $celement['service_description'] . $this->delim . $celement['contact_name'] . "\n"; } $trapRel = new Centreon_Object_Relation_Trap_Service(); $telements = $trapRel->getMergedParameters(array("traps_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service.service_id" => $element['service_id']), "AND"); foreach ($telements as $telement) { echo $this->action . $this->delim . "addtrap" . $this->delim . $element['host_name'] . $this->delim . $telement['service_description'] . $this->delim . $telement['traps_name'] . "\n"; } } }
/** * Insert audit log * * @param string $actionType * @param int $objId * @param string $objName * @param array $objValues */ public function addAuditLog($actionType, $objId, $objName, $objValues = array()) { $objType = strtoupper($this->action); $objectTypes = array('HTPL' => 'host', 'STPL' => 'service', 'CONTACT' => 'contact', 'SG' => 'servicegroup', 'TP' => 'timeperiod', 'SERVICE' => 'service', 'CG' => 'contactgroup', 'CMD' => 'command', 'HOST' => 'host', 'HC' => 'hostcategories', 'HG' => 'hostgroup', 'SC' => 'servicecategories'); if (!isset($objectTypes[$objType])) { return null; } $objType = $objectTypes[$objType]; $contactObj = new Centreon_Object_Contact(); $contact = $contactObj->getIdByParameter('contact_alias', CentreonUtils::getUserName()); $userId = $contact[0]; $dbstorage = Centreon_Db_Manager::factory('storage'); $query = 'INSERT INTO log_action (action_log_date, object_type, object_id, object_name, action_type, log_contact_id) VALUES (?, ?, ?, ?, ?, ?)'; $time = time(); $dbstorage->query($query, array($time, $objType, $objId, $objName, $actionType, $userId)); $query = 'SELECT MAX(action_log_id) as action_log_id FROM log_action WHERE action_log_date = ?'; $stmt = $dbstorage->query($query, array($time)); $row = $stmt->fetch(); if (false === $row) { throw new CentreonClapiException("Error while inserting log action"); } $stmt->closeCursor(); $actionId = $row['action_log_id']; $query = 'INSERT INTO log_action_modification (field_name, field_value, action_log_id) VALUES (?, ?, ?)'; foreach ($objValues as $name => $value) { try { if (is_array($value)) { $value = implode(',', $value); } if (is_null($value)) { $value = ''; } $dbstorage->query($query, array($name, $value, $actionId)); } catch (Exception $e) { throw $e; } } }
/** * Export * * @return void */ public function export() { $elements = $this->object->getList("*", -1, 0); foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD" . $this->delim . $element['config_name'] . $this->delim . $this->instanceObj->getInstanceName($element['ns_nagios_server']); echo $addStr . "\n"; echo $this->action . $this->delim . "SETPARAM" . $this->delim . $element['config_name'] . $this->delim . "filename" . $this->delim . $element['config_filename'] . "\n"; $sql = "SELECT config_key, config_value, config_group, config_group_id\n \t\tFROM cfg_centreonbroker_info\n \t\tWHERE config_id = ?\n \t\tORDER BY config_group_id"; $res = $this->db->query($sql, array($element['config_id'])); $blockId = array(); $categories = array(); $addParamStr = array(); $setParamStr = array(); $resultSet = $res->fetchAll(); unset($res); foreach ($resultSet as $row) { if ($row['config_key'] != 'name' && $row['config_key'] != 'blockId' && $row['config_key'] != 'filters' && $row['config_key'] != 'category') { if (!isset($setParamStr[$row['config_group'] . '_' . $row['config_group_id']])) { $setParamStr[$row['config_group'] . '_' . $row['config_group_id']] = ""; } $row['config_value'] = CentreonUtils::convertLineBreak($row['config_value']); $setParamStr[$row['config_group'] . '_' . $row['config_group_id']] .= $this->action . $this->delim . "SET" . strtoupper($row['config_group']) . $this->delim . $element['config_name'] . $this->delim . $row['config_group_id'] . $this->delim . $row['config_key'] . $this->delim . $row['config_value'] . "\n"; } elseif ($row['config_key'] == 'name') { $addParamStr[$row['config_group'] . '_' . $row['config_group_id']] = $this->action . $this->delim . "ADD" . strtoupper($row['config_group']) . $this->delim . $element['config_name'] . $this->delim . $row['config_value']; } elseif ($row['config_key'] == 'blockId') { $blockId[$row['config_group'] . '_' . $row['config_group_id']] = $row['config_value']; } elseif ($row['config_key'] == 'category') { $categories[$row['config_group'] . '_' . $row['config_group_id']][] = $row['config_value']; } } foreach ($addParamStr as $id => $add) { if (isset($blockId[$id]) && isset($setParamStr[$id])) { list($tag, $type) = explode('_', $blockId[$id]); $resType = $this->db->query("SELECT type_shortname FROM cb_type WHERE cb_type_id = ?", array($type)); $rowType = $resType->fetch(); if (isset($rowType['type_shortname'])) { echo $add . $this->delim . $rowType['type_shortname'] . "\n"; echo $setParamStr[$id]; } unset($resType); } if (isset($categories[$id])) { list($configGroup, $configGroupId) = explode('_', $id); echo $this->action . $this->delim . "SET" . strtoupper($configGroup) . $this->delim . $element['config_name'] . $this->delim . $configGroupId . $this->delim . 'category' . $this->delim . implode(',', $categories[$id]) . "\n"; } } } }
public static function setUserName($userName) { self::$clapiUserName = $userName; }
/** * Parse template tree * * @param array $tree * @param Centreon_Object_Service_Extended $extendedObj */ protected function parseTemplateTree($tree) { $commandObj = new Centreon_Object_Command(); $tpObj = new Centreon_Object_Timeperiod(); $extendedObj = new Centreon_Object_Service_Extended(); $macroObj = new Centreon_Object_Service_Macro_Custom(); foreach ($tree as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim; if ($param == "service_template_model_stm_id") { $tmp = $this->object->getParameters($element[$param], 'service_description'); if (isset($tmp) && isset($tmp['service_description']) && $tmp['service_description']) { $element[$param] = $tmp['service_description']; } if (!$element[$param]) { $element[$param] = ""; } } $addStr .= $element[$param]; } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") { if ($parameter == "timeperiod_tp_id" || $parameter == "timeperiod_tp_id2") { $tmpObj = $tpObj; } elseif ($parameter == "command_command_id" || $parameter == "command_command_id2") { $tmpObj = $commandObj; } if (isset($tmpObj)) { $tmp = $tmpObj->getParameters($value, $tmpObj->getUniqueLabelField()); if (isset($tmp) && isset($tmp[$tmpObj->getUniqueLabelField()])) { $value = $tmp[$tmpObj->getUniqueLabelField()]; } unset($tmpObj); } $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $value . "\n"; } } $params = $extendedObj->getParameters($element[$this->object->getPrimaryKey()], array("esi_notes", "esi_notes_url", "esi_action_url", "esi_icon_image", "esi_icon_image_alt")); if (isset($params) && is_array($params)) { foreach ($params as $k => $v) { if (!is_null($v) && $v != "") { $v = CentreonUtils::convertLineBreak($v); echo $this->action . $this->delim . "setparam" . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($k) . $this->delim . $v . "\n"; } } } $macros = $macroObj->getList("*", -1, 0, null, null, array('svc_svc_id' => $element[$this->object->getPrimaryKey()]), "AND"); foreach ($macros as $macro) { echo $this->action . $this->delim . "setmacro" . $this->delim . $element['service_description'] . $this->delim . $this->stripMacro($macro['svc_macro_name']) . $this->delim . $macro['svc_macro_value'] . "\n"; } if (count($element['children'])) { $this->parseTemplateTree($element['children'], $extendedObj); } } }
/** * Export * * @return void */ public function export() { $matchingObj = new Centreon_Object_Trap_Matching(); $elements = $this->object->getList("*", -1, 0); foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim . $element[$param]; } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if ($parameter != 'traps_id') { if (!is_null($value) && $value != "") { $value = str_replace("\n", "<br/>", $value); if ($parameter == 'manufacturer_id') { $parameter = 'vendor'; $value = $this->manufacturerObj->getName($value); } $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n"; } } } $matchingProps = $matchingObj->getList("*", -1, 0, null, null, array('trap_id' => $element['traps_id'])); foreach ($matchingProps as $prop) { echo $this->action . $this->delim . "addmatching" . $this->delim . $element['traps_name'] . $this->delim . $prop['tmo_string'] . $this->delim . $prop['tmo_regexp'] . $this->delim . $prop['tmo_status'] . "\n"; } } }
/** * Set parameters * * @param string $parameters * @return void * @throws CentreonClapiException */ public function setparam($parameters = null) { $params = explode($this->delim, $parameters); if (count($params) < self::NB_UPDATE_PARAMS) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $hgName = $params[0]; $serviceDesc = $params[1]; $relObject = new Centreon_Object_Relation_Host_Group_Service(); $elements = $relObject->getMergedParameters(array("hg_id"), array("service_id"), -1, 0, null, null, array("hg_name" => $hgName, "service_description" => $serviceDesc), "AND"); if (!count($elements)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $hgName . "/" . $serviceDesc); } $objectId = $elements[0]['service_id']; $extended = false; $commandObject = new CentreonCommand(); switch ($params[2]) { case "check_command": $params[2] = "command_command_id"; $params[3] = $commandObject->getId($params[3]); break; case "check_command_arguments": $params[2] = "command_command_id_arg"; break; case "event_handler": $params[2] = "command_command_id2"; $params[3] = $commandObject->getId($params[3]); break; case "event_handler_arguments": $params[2] = "command_command_id_arg2"; break; case "check_period": $params[2] = "timeperiod_tp_id"; $tpObj = new CentreonTimePeriod(); $params[3] = $tpObj->getTimeperiodId($params[3]); break; case "notification_period": $params[2] = "timeperiod_tp_id2"; $tpObj = new CentreonTimePeriod(); $params[3] = $tpObj->getTimeperiodId($params[3]); break; case "flap_detection_options": break; case "template": $params[2] = "service_template_model_stm_id"; $tmp = $this->object->getList($this->object->getPrimaryKey(), -1, 0, null, null, array('service_description' => $params[3], 'service_register' => '0'), "AND"); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]); } $params[3] = $tmp[0][$this->object->getPrimaryKey()]; break; case "graphtemplate": $extended = true; $graphObj = new Centreon_Object_Graph_Template(); $tmp = $graphObj->getIdByParameter($graphObj->getUniqueLabelField(), $params[3]); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]); } $params[2] = "graph_id"; $params[3] = $tmp[0]; break; case "notes": $extended = true; break; case "notes_url": $extended = true; break; case "action_url": $extended = true; break; case "icon_image": $extended = true; break; case "icon_image_alt": $extended = true; break; default: if (!preg_match("/^service_/", $params[2])) { $params[2] = "service_" . $params[2]; } break; } if ($extended == false) { $updateParams = array($params[2] => $params[3]); parent::setparam($objectId, $updateParams); } else { if ($params[2] != "graph_id") { $params[2] = "esi_" . $params[2]; if ($params[2] == "esi_icon_image") { if ($params[3]) { $id = CentreonUtils::getImageId($params[3]); if (is_null($id)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[3]); } $params[3] = $id; } else { $params[3] = null; } } } $extended = new Centreon_Object_Service_Extended(); $extended->update($objectId, array($params[2] => $params[3])); } }
/** * Export data * * @param string $parameters * @return void */ public function export() { $elements = $this->object->getList("*", -1, 0); foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim . $element[$param]; } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams)) { if (!is_null($value) && $value != "") { $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n"; } } if ($parameter == "graph_id" && !empty($value)) { $graphObject = new Centreon_Object_Graph_Template(); $tmp = $graphObject->getParameters($value, array($graphObject->getUniqueLabelField())); if (!count($tmp)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $value); } $v = $tmp[$graphObject->getUniqueLabelField()]; $v = CentreonUtils::convertLineBreak($v); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $v . "\n"; } } } }
/** * Export * * @return void */ public function export() { $elements = $this->object->getList(); foreach ($elements as $element) { $instanceIds = $this->relObj->getinstance_idFromresource_id(trim($element[$this->object->getPrimaryKey()])); /* ADD action */ $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { if ($param == 'instance_id') { $instances = array(); foreach ($instanceIds as $instanceId) { $instances[] = $this->instanceObj->getInstanceName($instanceId); } $element[$param] = implode('|', $instances); } $addStr .= $this->delim . $element[$param]; } $addStr .= "\n"; echo $addStr; /* SETPARAM action */ foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") { $parameter = str_replace("resource_", "", $parameter); $value = str_replace("\n", "<br/>", $value); $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n"; } } } }
} if ($op && isset($search) && $search != "") { $msg_req .= " AND (host_name " . CentreonUtils::operandToMysqlFormat($op) . " '" . $dbb->escape($search) . "' "; $msg_req .= " OR service_description " . CentreonUtils::operandToMysqlFormat($op) . " '" . $dbb->escape($search) . "' "; $msg_req .= " OR instance_name " . CentreonUtils::operandToMysqlFormat($op) . " '" . $dbb->escape($search) . "') "; } } // Search on output if (isset($preferences['output_search']) && $preferences['output_search'] != "") { $tab = split(" ", $preferences['output_search']); $op = $tab[0]; if (isset($tab[1])) { $outputSearch = $tab[1]; } if ($op && isset($outputSearch) && $outputSearch != "") { $msg_req .= " AND output " . CentreonUtils::operandToMysqlFormat($op) . " '" . $dbb->escape($outputSearch) . "' "; } } // Build final request $orderby = "name ASC"; if (isset($preferences['order_by']) && $preferences['order_by'] != "") { $orderby = $preferences['order_by']; } $start = time() - $preferences['log_period']; $end = time(); $query = "SELECT SQL_CALC_FOUND_ROWS * FROM logs WHERE ctime > '{$start}' AND ctime <= '{$end}' {$msg_req}"; $query .= " ORDER BY ctime DESC, host_name ASC, log_id DESC, service_description ASC"; $query .= " LIMIT " . $page * $preferences['entries'] . "," . $preferences['entries']; $res = $dbb->query($query); $nbRows = $dbb->numberRows(); $data = array();
/** * Export * * @return void */ public function export() { $elements = $this->object->getList(); $tpObj = new Centreon_Object_Timeperiod(); foreach ($elements as $element) { /* ADD action */ $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { if ($param == 'nagios_server_id') { $element[$param] = $this->instanceObj->getInstanceName($element[$param]); } $addStr .= $this->delim . $element[$param]; } $addStr .= "\n"; echo $addStr; /* SETPARAM action */ foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") { if ($parameter == 'global_host_event_handler' || $parameter == 'global_service_event_handler' || $parameter == 'host_perfdata_command' || $parameter == 'service_perfdata_command' || $parameter == 'host_perfdata_file_processing_command' || $parameter == 'service_perfdata_file_processing_command' || $parameter == 'ochp_command' || $parameter == 'ocsp_command') { $tmp = $this->commandObj->getParameters($value, $this->commandObj->getUniqueLabelField()); $value = $tmp[$this->commandObj->getUniqueLabelField()]; } else { if ($parameter == 'illegal_object_name_chars' || $parameter == 'illegal_macro_output_chars') { $value = html_entity_decode($value, ENT_QUOTES | ENT_HTML401); } } $value = str_replace("\n", "<br/>", $value); $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n"; } } $modules = $this->brokerModuleObj->getList("broker_module", -1, 0, null, "ASC", array('cfg_nagios_id' => $element[$this->object->getPrimaryKey()]), "AND"); $moduleList = array(); foreach ($modules as $module) { array_push($moduleList, $module['broker_module']); } echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . 'broker_module' . $this->delim . implode('|', $moduleList) . "\n"; } }
/** * Export * * @return void */ public function export() { $elements = $this->object->getList("*", -1, 0, null, null, array("host_register" => $this->register), "AND"); $extendedObj = new Centreon_Object_Host_Extended(); $commandObj = new Centreon_Object_Command(); $tpObj = new Centreon_Object_Timeperiod(); $macroObj = new Centreon_Object_Host_Macro_Custom(); $instanceRel = new Centreon_Object_Relation_Instance_Host(); if ($this->register) { $instElements = $instanceRel->getMergedParameters(array("name"), array("host_name"), -1, 0, null, null, array("host_register" => $this->register), "AND"); } foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim; if ($param == 'instance') { if ($this->register) { foreach ($instElements as $instElem) { if ($element['host_name'] == $instElem['host_name']) { $addStr .= $instElem['name']; } } } } if ($param != "hostgroup" && $param != "template") { $addStr .= $element[$param]; } } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") { if ($parameter == "timeperiod_tp_id" || $parameter == "timeperiod_tp_id2") { $tmpObj = $tpObj; } elseif ($parameter == "command_command_id" || $parameter == "command_command_id2") { $tmpObj = $commandObj; } if (isset($tmpObj)) { $tmp = $tmpObj->getParameters($value, $tmpObj->getUniqueLabelField()); if (isset($tmp) && isset($tmp[$tmpObj->getUniqueLabelField()])) { $value = $tmp[$tmpObj->getUniqueLabelField()]; } unset($tmpObj); } $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $value . "\n"; } } $params = $extendedObj->getParameters($element[$this->object->getPrimaryKey()], array("ehi_notes", "ehi_notes_url", "ehi_action_url", "ehi_icon_image", "ehi_icon_image_alt", "ehi_vrml_image", "ehi_statusmap_image", "ehi_2d_coords", "ehi_3d_coords")); if (isset($params) && is_array($params)) { foreach ($params as $k => $v) { if (!is_null($v) && $v != "") { $v = CentreonUtils::convertLineBreak($v); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->getClapiActionName($k) . $this->delim . $v . "\n"; } } } $macros = $macroObj->getList("*", -1, 0, null, null, array('host_host_id' => $element[$this->object->getPrimaryKey()]), "AND"); foreach ($macros as $macro) { echo $this->action . $this->delim . "setmacro" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $this->stripMacro($macro['host_macro_name']) . $this->delim . $macro['host_macro_value'] . "\n"; } } $cgRel = new Centreon_Object_Relation_Contact_Group_Host(); $elements = $cgRel->getMergedParameters(array("cg_name"), array($this->object->getUniqueLabelField()), -1, 0, null, null, array("host_register" => $this->register), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addcontactgroup" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $element['cg_name'] . "\n"; } $contactRel = new Centreon_Object_Relation_Contact_Host(); $elements = $contactRel->getMergedParameters(array("contact_name"), array($this->object->getUniqueLabelField()), -1, 0, null, null, array("host_register" => $this->register), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addcontact" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $element['contact_name'] . "\n"; } $htplRel = new Centreon_Object_Relation_Host_Template_Host(); $elements = $htplRel->getMergedParameters(array("host_name as host"), array("host_name as template"), -1, 0, "host,`order`", "ASC", array("h.host_register" => $this->register), "AND"); foreach ($elements as $element) { echo $this->action . $this->delim . "addtemplate" . $this->delim . $element['host'] . $this->delim . $element['template'] . "\n"; } }
$query .= " AND cv2.`value` IN ({$idC}) "; } if (!$centreon->user->admin) { $pearDB = $db; $aclObj = new CentreonACL($centreon->user->user_id, $centreon->user->admin); $groupList = $aclObj->getAccessGroupsString(); $query .= " AND h.host_id = acl.host_id\n\tAND acl.service_id = s.service_id\n\tAND acl.group_id IN ({$groupList})"; } if (isset($preferences['output_search']) && $preferences['output_search'] != "") { $tab = split(" ", $preferences['output_search']); $op = $tab[0]; if (isset($tab[1])) { $search = $tab[1]; } if ($op && isset($search) && $search != "") { $query = CentreonUtils::conditionBuilder($query, "s.output " . CentreonUtils::operandToMysqlFormat($op) . " '" . $dbb->escape($search) . "' "); } } if (isset($preferences['ticket_id_search']) && $preferences['ticket_id_search'] != "") { $query .= " AND (mop1.ticket_value LIKE '" . $dbb->escape($preferences['ticket_id_search']) . "' OR mop2.ticket_value LIKE '" . $dbb->escape($preferences['ticket_id_search']) . "') "; } if (isset($preferences['ticket_subject_search']) && $preferences['ticket_subject_search'] != "") { $query .= " AND (mopd1.subject LIKE '" . $dbb->escape($preferences['ticket_subject_search']) . "' OR mopd2.subject LIKE '" . $dbb->escape($preferences['ticket_subject_search']) . "') "; } $orderby = "hostname ASC , description ASC"; if (isset($preferences['order_by']) && $preferences['order_by'] != "") { $orderby = $preferences['order_by']; } $query .= "ORDER BY {$orderby}"; $query .= " LIMIT " . $page * $preferences['entries'] . "," . $preferences['entries']; $res = $dbb->query($query);
/** * Send Trap configuration files to poller * * @param int $pollerId * @return void * @throws CentreonClapiException */ public function sendTrapCfg($pollerId = null) { if (is_null($pollerId)) { throw new CentreonClapiException(self::MISSING_POLLER_ID); } $this->testPollerId($pollerId); $centreonDir = CentreonUtils::getCentreonDir(); passthru("{$centreonDir}/bin/centGenSnmpttConfFile 2>&1"); exec("echo 'SYNCTRAP:" . $pollerId . "' >> " . $this->centcore_pipe, $stdout, $return); return $return; }
/** * Will generate traps from a mib file * * @param string $parameters * @return void */ public function generatetraps($parameters = null) { $params = explode($this->delim, $parameters); if (count($params) < 2) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $vendorId = $this->getId($params[0]); $mibFile = $params[1]; $tmpMibFile = "/tmp/" . basename($mibFile); if (!is_file($mibFile)) { throw new CentreonClapiException(self::FILE_NOT_FOUND . ": " . $mibFile); } copy($mibFile, $tmpMibFile); $centreonDir = CentreonUtils::getCentreonDir(); passthru("export MIBS=ALL && {$centreonDir}/bin/snmpttconvertmib --in={$tmpMibFile} --out={$tmpMibFile}.conf"); passthru("{$centreonDir}/bin/centFillTrapDB -f {$tmpMibFile}.conf -m {$vendorId}"); unlink($tmpMibFile); unlink($tmpMibFile . ".conf"); }
$serviceStateLabels = array(0 => "Ok", 1 => "Warning", 2 => "Critical", 3 => "Unknown", 4 => "Pending"); $query = "SELECT SQL_CALC_FOUND_ROWS DISTINCT name1 as name "; $query .= "FROM {$ndoPrefix}servicegroups sg, {$ndoPrefix}objects o "; $query .= "WHERE sg.servicegroup_object_id = o.object_id "; if (isset($preferences['sg_name_search']) && $preferences['sg_name_search'] != "") { $tab = split(" ", $preferences['sg_name_search']); $op = $tab[0]; if (isset($tab[1])) { $search = $tab[1]; } if ($op && isset($search) && $search != "") { $query = CentreonUtils::conditionBuilder($query, "name1 " . CentreonUtils::operandToMysqlFormat($op) . " '" . $dbb->escape($search) . "' "); } } if (!$centreon->user->admin) { $query = CentreonUtils::conditionBuilder($query, "name1 IN (" . $aclObj->getServiceGroupsString("NAME") . ")"); } $orderby = "name ASC"; if (isset($preferences['order_by']) && $preferences['order_by'] != "") { $orderby = $preferences['order_by']; } $query .= "ORDER BY {$orderby}"; $query .= " LIMIT " . $page * $preferences['entries'] . "," . $preferences['entries']; $res = $dbb->query($query); $nbRows = $dbb->numberRows(); $data = array(); $detailMode = false; if (isset($preferences['enable_detailed_mode']) && $preferences['enable_detailed_mode']) { $detailMode = true; } while ($row = $res->fetchRow()) {
} elseif ($preferences['downtime_filter'] == "ndowntime") { $query = CentreonUtils::conditionBuilder($query, " s.scheduled_downtime_depth = 0 "); } } if (isset($preferences['state_type_filter']) && $preferences['state_type_filter']) { if ($preferences['state_type_filter'] == "hardonly") { $query = CentreonUtils::conditionBuilder($query, " s.state_type = 1 "); } elseif ($preferences['state_type_filter'] == "softonly") { $query = CentreonUtils::conditionBuilder($query, " s.state_type = 0 "); } } if (isset($preferences['hostgroup']) && $preferences['hostgroup']) { $query = CentreonUtils::conditionBuilder($query, " s.host_id IN (\n SELECT host_host_id\n FROM " . $conf_centreon['db'] . ".hostgroup_relation\n WHERE hostgroup_hg_id = " . $dbb->escape($preferences['hostgroup']) . ")"); } if (isset($preferences['servicegroup']) && $preferences['servicegroup']) { $query = CentreonUtils::conditionBuilder($query, " s.service_id IN (SELECT service_service_id\n FROM " . $conf_centreon['db'] . ".servicegroup_relation\n WHERE servicegroup_sg_id = " . $dbb->escape($preferences['servicegroup']) . "\n UNION\n SELECT sgr.service_service_id\n FROM " . $conf_centreon['db'] . ".servicegroup_relation sgr, " . $conf_centreon['db'] . ".host_service_relation hsr\n WHERE hsr.hostgroup_hg_id = sgr.hostgroup_hg_id\n AND sgr.servicegroup_sg_id = " . $dbb->escape($preferences['servicegroup']) . ") "); } if (isset($preferences["display_severities"]) && $preferences["display_severities"] && isset($preferences['criticality_filter']) && $preferences['criticality_filter'] != "") { $tab = split(",", $preferences['criticality_filter']); $labels = ""; foreach ($tab as $p) { if ($labels != '') { $labels .= ','; } $labels .= "'" . trim($p) . "'"; } $query2 = "SELECT sc_id FROM service_categories WHERE sc_name IN (" . $labels . ")"; $RES = $db->query($query2); $idC = ""; while ($d1 = $RES->fetchRow()) { if ($idC != '') {