Merge branch '1688-Error-en-API-al-habilitar-alertas' into 'develop'

Add new function enable alert by alias - #1688

See merge request artica/pandorafms!1177
This commit is contained in:
vgilc 2018-01-29 13:25:54 +01:00
commit 61ce7237c3
1 changed files with 45 additions and 3 deletions

View File

@ -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