From e4cc09e09ce23109ee508f0f4e357368156cb73f Mon Sep 17 00:00:00 2001 From: enriquecd Date: Wed, 13 Dec 2017 13:57:38 +0100 Subject: [PATCH] Add new function enable alert by alias - #1688 --- pandora_console/include/functions_api.php | 48 +++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index c1c7c9ca50..893479c5bf 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -8613,12 +8613,54 @@ function api_set_enable_alert ($agent_name, $module_name, $template_name, $thras $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent, 'nombre' => $module_name)); $id_template = db_get_value_filter('id', 'talert_templates', array('name' => $template_name["data"])); - db_process_sql("UPDATE talert_template_modules + $result = db_process_sql("UPDATE talert_template_modules SET disabled = 0 WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template"); - returnData('string', array('type' => 'string', 'data' => "Correct alert enable")); -} + if ($result) { + returnData('string', array('type' => 'string', 'data' => "Correct alert enable")); + } else { + returnData('string', array('type' => 'string', 'data' => __('Error alert enable'))); + } + } + + /** + * Enable an alert with alias + * + * @param string $agent_alias Alias of agent (for example "myagent") + * @param string $module_name Name of the module (for example "Host alive") + * @param string $template_name Name of the alert template (for example, "Warning event") + * @param $thrash4 Don't use. + + // http://localhost/pandora_console/include/api.php?op=set&op2=enable_alert_alias&id=garfio&id2=Status&other=Warning%20condition + */ + + function api_set_enable_alert_alias ($agent_alias, $module_name, $template_name, $thrash4) { + if (defined ('METACONSOLE')) { + return; + } + + $agent_id = agents_get_agent_id_by_alias($agent_alias); + $result = false; + foreach ($agent_id as $key => $id_agent) { + $id_agent_module = db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('id_agente' => $id_agent['id_agente'], 'nombre' => $module_name)); + $id_template = db_get_value_filter('id', 'talert_templates', array('name' => $template_name["data"])); + + $result = db_process_sql("UPDATE talert_template_modules + SET disabled = 0 + WHERE id_agent_module = $id_agent_module AND id_alert_template = $id_template"); + + if ($result) { + returnData('string', array('type' => 'string', 'data' => "Correct alert enable")); + return; + } + } + + if(!$result){ + returnData('string', array('type' => 'string', 'data' => __('Error alert enable'))); + } + } + /** * Disable all the alerts of one module