Merge branch '330-Agentes-sin-alertas-dev' into 'develop'

Added new functionality to create alerts on modules without alerts

See merge request !546
This commit is contained in:
vgilc 2017-06-20 11:16:43 +02:00
commit ab45409cf0
2 changed files with 339 additions and 147 deletions

View File

@ -60,9 +60,31 @@ function mainAgentsAlerts() {
} }
$updated_time = $updated_info; $updated_time = $updated_info;
$create_alert = (int)get_parameter ("create_alert",0);
if($create_alert){
$template2 = get_parameter("template");
$module_action_threshold = get_parameter("module_action_threshold");
$id_alert = alerts_create_alert_agent_module ($create_alert, $template2);
if ($id_alert !== false) {
$action_select = get_parameter("action_select",0);
if ($action_select != 0) {
$values = array();
$values['fires_min'] = 0;
$values['fires_max'] = 0;
$values['module_action_threshold'] =
(int)get_parameter ('module_action_threshold');
alerts_add_alert_agent_module_action ($id_alert, $action_select, $values);
}
}
}
$refr = get_parameter('refr', 30); // By default 30 seconds $refr = get_parameter('refr', 30); // By default 30 seconds
$show_modules = (bool) get_parameter ("show_modules",0);
$group_id = get_parameter('group_id', 0); $group_id = get_parameter('group_id', 0);
$offset = get_parameter('offset', 0); $offset = get_parameter('offset', 0);
$hor_offset = get_parameter('hor_offset', 0); $hor_offset = get_parameter('hor_offset', 0);
@ -70,10 +92,12 @@ function mainAgentsAlerts() {
$groups = users_get_groups (); $groups = users_get_groups ();
$filter_groups = '<form method="post" action="' . ui_get_url_refresh (array ('offset' => 0, 'hor_offset' => 0)).'">';
$filter_groups .= '<b>'.__('Group').'</b>'; $filter_groups .= '<b>'.__('Group').'</b>';
$filter_groups .= html_print_select_groups(false, "AR", true, 'group_id', $group_id, 'this.form.submit()', '', '', true, false, true, '', false , 'width: 100px; margin-right: 10px;; margin-top: 5px;'); $filter_groups .= html_print_select_groups(false, "AR", true, 'group_id', $group_id, false, '', '', true, false, true, '', false , 'width: 100px; margin-right: 10px;; margin-top: 5px;');
$filter_groups .= '</form>';
$check = '<b>'.__('Show modules without alerts').'</b>';
$check .= html_print_checkbox('slides_ids[]', $d['id'], $show_modules, true, false, '', true);
$comborefr = '<form method="post" action="' . ui_get_url_refresh (array ('offset' => 0, 'hor_offset' => 0)).'">'; $comborefr = '<form method="post" action="' . ui_get_url_refresh (array ('offset' => 0, 'hor_offset' => 0)).'">';
$comborefr .= '<b>'.__('Refresh').'</b>'; $comborefr .= '<b>'.__('Refresh').'</b>';
@ -87,12 +111,12 @@ function mainAgentsAlerts() {
$comborefr .= "</form>"; $comborefr .= "</form>";
if ($config["pure"] == 0) { if ($config["pure"] == 0) {
$fullscreen['text'] = '<a href="index.php?extension_in_menu=estado&amp;sec=extensions&amp;sec2=extensions/agents_alerts&amp;pure=1&amp;offset='.$offset.'&group_id='.$group_id.'">' $fullscreen['text'] = '<a href="'.ui_get_url_refresh(array ('pure' => 1)).'">'
. html_print_image ("images/full_screen.png", true, array ("title" => __('Full screen mode'))) . html_print_image ("images/full_screen.png", true, array ("title" => __('Full screen mode')))
. "</a>"; . "</a>";
} }
else { else {
$fullscreen['text'] = '<a href="index.php?extension_in_menu=estado&amp;sec=extensions&amp;sec2=extensions/agents_alerts&amp;refr=0&amp;offset='.$offset.'&group_id='.$group_id.'">' $fullscreen['text'] = '<a href="'.ui_get_url_refresh(array ('pure' => 0)).'">'
. html_print_image ("images/normal_screen.png", true, array ("title" => __('Back to normal mode'))) . html_print_image ("images/normal_screen.png", true, array ("title" => __('Back to normal mode')))
. "</a>"; . "</a>";
$config['refr'] = $refr; $config['refr'] = $refr;
@ -113,12 +137,135 @@ function mainAgentsAlerts() {
echo '<table class="databox filters" cellpadding="0" cellspacing="0" border="0" style="width:100%;">'; echo '<table class="databox filters" cellpadding="0" cellspacing="0" border="0" style="width:100%;">';
echo "<tr>"; echo "<tr>";
echo "<td>" . $filter_groups . "</td>"; echo "<td>" . $filter_groups . "</td>";
echo "<td>" . $check . "</td>";
if ($config['pure'] == 1) if ($config['pure'] == 1)
echo "<td>" . $comborefr . "</td>"; echo "<td>" . $comborefr . "</td>";
echo "<td> <strong>" . __("Full screen") . "</strong>" . $fullscreen['text'] . "</td>"; echo "<td> <strong>" . __("Full screen") . "</strong>" . $fullscreen['text'] . "</td>";
echo "</tr>"; echo "</tr>";
echo "</table>"; echo "</table>";
if($show_modules){
if($group_id > 0){
$grupo = " AND tagente.id_grupo = $group_id";
} else {
$grupo ='';
}
$offset_modules = get_parameter ("offset",0);
$sql_count = "SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo
INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente
WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules)
$grupo";
$count_agent_module = db_get_all_rows_sql($sql_count);
$sql = "SELECT tagente.alias, tagente_modulo.nombre,
tagente_modulo.id_agente_modulo FROM tagente_modulo
INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente
WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules)
$grupo LIMIT 20 OFFSET $offset_modules";
$agent_modules = db_get_all_rows_sql($sql);
ui_pagination ($count_agent_module[0]['COUNT(tagente_modulo.nombre)'],
ui_get_url_refresh(),0,0,false,'offset',true,'',
'',false,'alerts_modules');
$table->width = '100%';
$table->class = "databox data";
$table->id = "table_agent_module";
$table->data = array ();
$table->head[0] = __('Agents');
$table->head[1] = __('Modules');
$table->head[2] = __('Actions');
$table->style[0]= 'width: 25%;';
$table->style[1]= 'width: 33%;';
$table->style[2]= 'width: 33%;';
foreach($agent_modules as $agent_module) {
$data[0] = io_safe_output($agent_module['alias']);
$data[1] = io_safe_output($agent_module['nombre']);
$uniqid = $agent_module['id_agente_modulo'];
$data[2] = "<a title='".__('Create alert')."' href='javascript:show_add_alerts(\"$uniqid\")'>".html_print_image('images/add_mc.png', true)."</a>";
array_push ($table->data, $data);
$table2->width = '100%';
$table2->id = "table_add_alert";
$table2->class = 'databox filters';
$table2->data = array ();
// $data[0] =
$table2->data[0][0] = __('Actions');
$groups_user = users_get_groups($config["id_user"]);
if (!empty($groups_user)) {
$groups = implode(',', array_keys($groups_user));
$sql = "SELECT id, name FROM talert_actions WHERE id_group IN ($groups)";
$actions = db_get_all_rows_sql($sql);
}
$table2->data[0][1] = html_print_select(
index_array($actions, 'id', 'name'), 'action_select', '', '',
__('Default action'), '0', true, '', true, '', false,
'width: 250px;');
$table2->data[0][1] .= '<span id="advanced_action" class="advanced_actions invisible"><br>';
$table2->data[0][1] .= __('Number of alerts match from').' ';
$table2->data[0][1] .= html_print_input_text ('fires_min', '', '', 4, 10, true);
$table2->data[0][1] .= ' ' . __('to') . ' ';
$table2->data[0][1] .= html_print_input_text ('fires_max', '', '', 4, 10, true);
$table2->data[0][1] .= ui_print_help_icon ("alert-matches", true,
ui_get_full_url(false, false, false, false));
$table2->data[0][1] .= '</span>';
if (check_acl ($config['id_user'], 0, "LM")) {
$table2->data[0][1] .= '<a style="margin-left:5px;" href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_action&pure='.$pure.'">';
$table2->data[0][1] .= html_print_image ('images/add.png', true);
$table2->data[0][1] .= '<span style="margin-left:5px;vertical-align:middle;">'.__('Create Action').'</span>';
$table2->data[0][1] .= '</a>';
}
$table2->data[1][0] = __('Template');
$own_info = get_user_info ($config['id_user']);
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
$templates = alerts_get_alert_templates (false, array ('id', 'name'));
else {
$usr_groups = users_get_groups($config['id_user'], 'LW', true);
$filter_groups = '';
$filter_groups = implode(',', array_keys($usr_groups));
$templates = alerts_get_alert_templates (array ('id_group IN (' . $filter_groups . ')'), array ('id', 'name'));
}
$table2->data[1][1] = html_print_select (index_array ($templates, 'id', 'name'),
'template', '', '', __('Select'), 0, true, false, true, '', false, 'width: 250px;');
$table2->data[1][1] .= ' <a class="template_details invisible" href="#">' .
html_print_image("images/zoom.png", true, array("class" => 'img_help')) . '</a>';
if (check_acl ($config['id_user'], 0, "LM")) {
$table2->data[1][1] .= '<a href="index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&pure='.$pure.'">';
$table2->data[1][1] .= html_print_image ('images/add.png', true);
$table2->data[1][1] .= '<span style="margin-left:5px;vertical-align:middle;">'.__('Create Template').'</span>';
$table2->data[1][1] .= '</a>';
}
$table2->data[2][0] = __('Threshold');
$table2->data[2][1] = html_print_input_text ('module_action_threshold', '0', '', 5, 7, true);
$table2->data[2][1] .= ' ' . __('seconds') . ui_print_help_icon ('action_threshold', true);
$content2 = '<form class="add_alert_form" method="post">';
$content2 .= html_print_table($table2,true);
$content2 .= '<div class="action-buttons" style="width: '.$table2->width.'">';
$content2 .= html_print_submit_button (__('Add alert'), 'add', false, 'class="sub wand"',true);
$content2 .= html_print_input_hidden ('create_alert', $uniqid,true);
$content2 .= '</div></form>';
$module_name = ui_print_truncate_text(io_safe_output($agent_module['nombre']), 40, false, true, false, '&hellip;', false);
echo '<div id="add_alerts_dialog_'.$uniqid.'" title="'.__('Agent').': '.$agent_module['alias'].' / '.__('module').': '.$module_name.'" style="display:none">'.$content2.'</div>';
}
html_print_table($table);
} else {
$filter = array ('offset' => (int) $offset, $filter = array ('offset' => (int) $offset,
'limit' => (int) $config['block_size']); 'limit' => (int) $config['block_size']);
$filter_count = array(); $filter_count = array();
@ -171,7 +318,8 @@ function mainAgentsAlerts() {
} }
// Prepare pagination // Prepare pagination
ui_pagination ($nagents); ui_pagination ($nagents,false,0,0,false,'offset',true,'',
'',array('count' => '', 'offset' => 'offset_param'),'alerts_agents');
echo '<table class="databox data" cellpadding="0" cellspacing="0" border="0" width=100%>'; echo '<table class="databox data" cellpadding="0" cellspacing="0" border="0" width=100%>';
echo "<th width='140px' >".__("Agents")." / ".__("Alert templates")."</th>"; echo "<th width='140px' >".__("Agents")." / ".__("Alert templates")."</th>";
@ -270,6 +418,9 @@ function mainAgentsAlerts() {
echo '</table>'; echo '</table>';
} }
}
// Print the modal window for the summary of each alerts group // Print the modal window for the summary of each alerts group
function print_alerts_summary_modal_window($id, $alerts) { function print_alerts_summary_modal_window($id, $alerts) {
@ -366,4 +517,40 @@ ui_require_jquery_file('pandora');
} }
}); });
} }
function show_add_alerts(id) {
$("#add_alerts_dialog_"+id).dialog({
resizable: true,
draggable: true,
modal: true,
height: 235,
width: 600,
overlay: {
opacity: 0.5,
background: "black"
}
});
}
// checkbox-slides_ids
$(document).ready(function () {
$('#checkbox-slides_ids').click(function(){
if ($('#checkbox-slides_ids').prop('checked')){
var url = location.href.replace("&show_modules=true", "");
location.href = url+"&show_modules=true";
} else {
var url = location.href.replace("&show_modules=true", "");
var re = /&offset=\d*/g;
location.href = url.replace(re, "");
}
});
$('#group_id').change(function(){
var regx = /&group_id=\d*/g;
var url = location.href.replace(regx, "");
location.href = url+"&group_id="+$("#group_id").val();
});
});
</script> </script>

View File

@ -1585,6 +1585,7 @@ function ui_process_page_body ($string, $bitfield) {
* @param bool $return Whether to return or print this * @param bool $return Whether to return or print this
* @param string $offset_name The name of parameter for the offset. * @param string $offset_name The name of parameter for the offset.
* @param bool $print_total_items Show the text with the total items. By default true. * @param bool $print_total_items Show the text with the total items. By default true.
* @param string $set_id Set id of div.
* *
* @return string The pagination div or nothing if no pagination needs to be done * @return string The pagination div or nothing if no pagination needs to be done
*/ */
@ -1592,7 +1593,7 @@ function ui_pagination ($count, $url = false, $offset = 0,
$pagination = 0, $return = false, $offset_name = 'offset', $pagination = 0, $return = false, $offset_name = 'offset',
$print_total_items = true, $other_class = '', $print_total_items = true, $other_class = '',
$script = "", $script = "",
$parameter_script = array('count' => '', 'offset' => 'offset_param')) { $parameter_script = array('count' => '', 'offset' => 'offset_param'), $set_id = '') {
global $config; global $config;
@ -1613,6 +1614,10 @@ function ui_pagination ($count, $url = false, $offset = 0,
$url = ui_get_url_refresh (array ($offset_name => false)); $url = ui_get_url_refresh (array ($offset_name => false));
} }
if(!empty($set_id)){
$set_id= " id = '$set_id'";
}
// Pagination links for users include delete, create and other params, now not use these params, and not retry the previous action when go to pagination link. // Pagination links for users include delete, create and other params, now not use these params, and not retry the previous action when go to pagination link.
$remove = array("user_del","disable_user","delete_user"); $remove = array("user_del","disable_user","delete_user");
@ -1635,7 +1640,7 @@ function ui_pagination ($count, $url = false, $offset = 0,
if ($count <= $pagination) { if ($count <= $pagination) {
if ($print_total_items) { if ($print_total_items) {
$output = "<div class='pagination $other_class'>"; $output = "<div class='pagination $other_class' $set_id>";
//Show the count of items //Show the count of items
$output .= sprintf(__('Total items: %s'), $count); $output .= sprintf(__('Total items: %s'), $count);
// End div and layout // End div and layout
@ -1659,7 +1664,7 @@ function ui_pagination ($count, $url = false, $offset = 0,
} }
$output = "<div class='pagination $other_class'>"; $output = "<div class='pagination $other_class' $set_id>";
//Show the count of items //Show the count of items
if ($print_total_items) { if ($print_total_items) {