2014-03-24 Miguel de Dios <miguel.dedios@artica.es>

* godmode/massive/massive_edit_agents.php,
	godmode/massive/massive_delete_agents.php,
	godmode/groups/group_list.php, include/functions_agents.php,
	include/javascript/jquery.pandora.controls.js,
	operation/agentes/ver_agente.php,
	operation/agentes/estado_monitores.php: added the feature to filter
	by agent status in the massive operations into
	"massive agent deletion" and "massive agent edition".
	
	Incident: #669




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@9639 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2014-03-24 11:41:54 +00:00
parent 147d81bcd5
commit 7e4a2ba7a9
8 changed files with 144 additions and 41 deletions

View File

@ -1,3 +1,16 @@
2014-03-24 Miguel de Dios <miguel.dedios@artica.es>
* godmode/massive/massive_edit_agents.php,
godmode/massive/massive_delete_agents.php,
godmode/groups/group_list.php, include/functions_agents.php,
include/javascript/jquery.pandora.controls.js,
operation/agentes/ver_agente.php,
operation/agentes/estado_monitores.php: added the feature to filter
by agent status in the massive operations into
"massive agent deletion" and "massive agent edition".
Incident: #669
2014-03-21 Miguel de Dios <miguel.dedios@artica.es> 2014-03-21 Miguel de Dios <miguel.dedios@artica.es>
* include/constants.php: added lost constant for * include/constants.php: added lost constant for

View File

@ -71,6 +71,7 @@ if (is_ajax ()) {
$keys_prefix = (string) get_parameter ('keys_prefix', ''); $keys_prefix = (string) get_parameter ('keys_prefix', '');
// Ids of agents to be include in the SQL clause as id_agent IN () // Ids of agents to be include in the SQL clause as id_agent IN ()
$filter_agents_json = (string) get_parameter ('filter_agents_json', ''); $filter_agents_json = (string) get_parameter ('filter_agents_json', '');
$status_agents = (int)get_parameter('status_agents', AGENT_STATUS_ALL);
if (! check_acl ($config['id_user'], $id_group, "AR")) { if (! check_acl ($config['id_user'], $id_group, "AR")) {
db_pandora_audit("ACL Violation", db_pandora_audit("ACL Violation",
@ -89,7 +90,11 @@ if (is_ajax ()) {
$filter['string'] = $search; $filter['string'] = $search;
} }
$agents = agents_get_group_agents ($id_group, $filter, "none", false, $recursion); if ($status_agents != AGENT_STATUS_ALL) {
$filter['status'] = $status_agents;
}
$agents = agents_get_group_agents($id_group, $filter, "none", false, $recursion);
// Add keys prefix // Add keys prefix
if ($keys_prefix !== "") { if ($keys_prefix !== "") {

View File

@ -102,16 +102,29 @@ $table->size[3] = '35%';
$table->data = array (); $table->data = array ();
$table->data[0][0] = __('Group'); $table->data[0][0] = __('Group');
$table->data[0][1] = html_print_select_groups(false, "AR", true, 'id_group', $id_group, $table->data[0][1] = html_print_select_groups(false, "AR", true,
false, '', '', true); 'id_group', $id_group, false, '', '', true);
$table->data[0][2] = __('Group recursion'); $table->data[0][2] = __('Group recursion');
$table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false); $table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion,
true, false);
$table->data[1][0] = __('Agents'); $status_list = array ();
$table->data[1][0] .= '<span id="agent_loading" class="invisible">'; $status_list[AGENT_STATUS_NORMAL] = __('Normal');
$table->data[1][0] .= html_print_image('images/spinner.png', true); $status_list[AGENT_STATUS_WARNING] = __('Warning');
$table->data[1][0] .= '</span>'; $status_list[AGENT_STATUS_CRITICAL] = __('Critical');
$table->data[1][1] = html_print_select (agents_get_group_agents ($id_group, false, "none"), $status_list[AGENT_STATUS_UNKNOWN] = __('Unknown');
$status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal');
$status_list[AGENT_STATUS_NOT_INIT] = __('Not init');
$table->data[1][0] = __('Status');
$table->data[1][1] = html_print_select($status_list, 'status_agents', 'selected',
'', __('All'), AGENT_STATUS_ALL, true);
$table->data[2][0] = __('Agents');
$table->data[2][0] .= '<span id="agent_loading" class="invisible">';
$table->data[2][0] .= html_print_image('images/spinner.png', true);
$table->data[2][0] .= '</span>';
$table->data[2][1] = html_print_select(
agents_get_group_agents($id_group, false, "none"),
'id_agents[]', 0, false, '', '', true, true); 'id_agents[]', 0, false, '', '', true, true);
echo '<form method="post" id="form_agents" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_agents">'; echo '<form method="post" id="form_agents" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=delete_agents">';
@ -130,15 +143,27 @@ ui_require_jquery_file ('pandora.controls');
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready (function () { $(document).ready (function () {
var recursion; var recursion;
$("#checkbox-recursion").click(function () {
recursion = this.checked ? 1 : 0; $("#checkbox-recursion").click(function () {
$("#id_group").trigger("change"); recursion = this.checked ? 1 : 0;
$("#id_group").trigger("change");
});
$("#id_group").pandoraSelectGroupAgent ({
status_agents: function () {
return $("#status_agents").val();
},
agentSelect: "select#id_agents",
recursion: function() {
return recursion;
}
});
$("#status_agents").change(function() {
$("#id_group").trigger("change");
});
}); });
$("#id_group").pandoraSelectGroupAgent ({
agentSelect: "select#id_agents",
recursion: function() {return recursion}
});
});
</script> </script>

View File

@ -198,14 +198,26 @@ $table->data[0][1] = html_print_select_groups(false, "AR", true, 'id_group', $id
$table->data[0][2] = __('Group recursion'); $table->data[0][2] = __('Group recursion');
$table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false); $table->data[0][3] = html_print_checkbox ("recursion", 1, $recursion, true, false);
$table->data[1][0] = __('Agents');
$table->data[1][0] .= '<span id="agent_loading" class="invisible">'; $status_list = array ();
$table->data[1][0] .= html_print_image('images/spinner.png', true); $status_list[AGENT_STATUS_NORMAL] = __('Normal');
$table->data[1][0] .= '</span>'; $status_list[AGENT_STATUS_WARNING] = __('Warning');
$status_list[AGENT_STATUS_CRITICAL] = __('Critical');
$status_list[AGENT_STATUS_UNKNOWN] = __('Unknown');
$status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal');
$status_list[AGENT_STATUS_NOT_INIT] = __('Not init');
$table->data[1][0] = __('Status');
$table->data[1][1] = html_print_select($status_list, 'status_agents', 'selected',
'', __('All'), AGENT_STATUS_ALL, true);
$table->data[2][0] = __('Agents');
$table->data[2][0] .= '<span id="agent_loading" class="invisible">';
$table->data[2][0] .= html_print_image('images/spinner.png', true);
$table->data[2][0] .= '</span>';
$enabled_agents = agents_get_group_agents ($id_group, array('disabled' => 0), "none"); $enabled_agents = agents_get_group_agents ($id_group, array('disabled' => 0), "none");
$all_agents = agents_get_group_agents ($id_group, array('disabled' => 1), "none") + $enabled_agents; $all_agents = agents_get_group_agents ($id_group, array('disabled' => 1), "none") + $enabled_agents;
$table->data[1][1] = html_print_select ($all_agents, $table->data[2][1] = html_print_select ($all_agents,
'id_agents[]', 0, false, '', '', true, true); 'id_agents[]', 0, false, '', '', true, true);
echo '<form method="post" id="form_agent" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=edit_agents">'; echo '<form method="post" id="form_agent" action="index.php?sec=gmassive&sec2=godmode/massive/massive_operations&option=edit_agents">';
@ -463,9 +475,16 @@ $(document).ready (function () {
$("#id_group").pandoraSelectGroupAgent ({ $("#id_group").pandoraSelectGroupAgent ({
agentSelect: "select#id_agents", agentSelect: "select#id_agents",
status_agents: function () {
return $("#status_agents").val();
},
recursion: function() {return recursion} recursion: function() {return recursion}
}); });
$("#status_agents").change(function() {
$("#id_group").trigger("change");
});
$("#id_group").pandoraSelectGroupAgentDisabled ({ $("#id_group").pandoraSelectGroupAgentDisabled ({
agentSelect: "select#id_agents", agentSelect: "select#id_agents",
recursion: function() {return recursion} recursion: function() {return recursion}

View File

@ -820,6 +820,36 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower
unset ($search["name"]); unset ($search["name"]);
} }
if (isset($search['status'])) {
switch ($search['status']) {
case AGENT_STATUS_NORMAL:
$search_sql .=
" AND normal_count = total_count";
break;
case AGENT_STATUS_WARNING:
$search_sql .=
" AND critical_count = 0 AND warning_count > 0";
break;
case AGENT_STATUS_CRITICAL:
$search_sql .=
" AND critical_count > 0";
break;
case AGENT_STATUS_UNKNOWN:
$search_sql .=
" AND critical_count = 0 AND warning_count = 0
AND unknown_count > 0";
break;
case AGENT_STATUS_NOT_NORMAL:
$search_sql .= " AND normal_count <> total_count";
break;
case AGENT_STATUS_NOT_INIT:
$search_sql .= " AND notinit_count = total_count";
break;
}
unset($search['status']);
}
if (! empty ($search)) { if (! empty ($search)) {
$search_sql .= ' AND '.db_format_array_where_clause_sql ($search); $search_sql .= ' AND '.db_format_array_where_clause_sql ($search);
} }

View File

@ -2,12 +2,13 @@
var dummyFunc = function () { var dummyFunc = function () {
return true; return true;
}; };
var _pandoraSelectGroupAgent = function (disabled) { var _pandoraSelectGroupAgent = function (disabled) {
var that = this; var that = this;
this.defaults = { this.defaults = {
agentSelect: "select#id_agent", agentSelect: "select#id_agent",
status_agents: -1,
recursion: 0, recursion: 0,
filter_agents_json: "", filter_agents_json: "",
loading: "#agent_loading", loading: "#agent_loading",
@ -18,22 +19,22 @@
debug: false, debug: false,
disabled: disabled || false, disabled: disabled || false,
}; };
/* public methods */ /* public methods */
this.construct = function (settings) { this.construct = function (settings) {
return this.each (function() { return this.each (function() {
this.config = {}; this.config = {};
this.config = $.extend (this.config, that.defaults, settings); this.config = $.extend (this.config, that.defaults, settings);
var config = this.config; var config = this.config;
$(this).change (function () { $(this).change (function () {
var $select = $(config.agentSelect).disable (); var $select = $(config.agentSelect).disable ();
$(config.loading).show (); $(config.loading).show ();
$("option[value!=0]", $select).remove (); $("option[value!=0]", $select).remove ();
if (! config.callbackBefore (this)) if (! config.callbackBefore (this))
return; return;
var opts = { var opts = {
"page" : "godmode/groups/group_list", "page" : "godmode/groups/group_list",
"get_group_agents" : 1, "get_group_agents" : 1,
@ -41,17 +42,18 @@
"recursion" : config.recursion, "recursion" : config.recursion,
"filter_agents_json" : config.filter_agents_json, "filter_agents_json" : config.filter_agents_json,
"disabled" : config.disabled ? 1 : 0, "disabled" : config.disabled ? 1 : 0,
"status_agents" : config.status_agents,
// Add a key prefix to avoid auto sorting in js object conversion // Add a key prefix to avoid auto sorting in js object conversion
"keys_prefix" : "_" "keys_prefix" : "_"
}; };
jQuery.post ("ajax.php", jQuery.post ("ajax.php",
opts, opts,
function (data, status) { function (data, status) {
jQuery.each (data, function (id, value) { jQuery.each (data, function (id, value) {
// Remove keys_prefix from the index // Remove keys_prefix from the index
id = id.substring(1); id = id.substring(1);
if (id !== 'keycount'){ if (id !== 'keycount') {
config.callbackPre (); config.callbackPre ();
option = $("<option></option>") option = $("<option></option>")
.attr ("value", id) .attr ("value", id)
@ -137,7 +139,7 @@
); );
}); });
}); });
}; };
} }
}); });
@ -162,7 +164,7 @@
this.config = $.extend (this.config, $.pandoraSelectAgentAlert.defaults, settings); this.config = $.extend (this.config, $.pandoraSelectAgentAlert.defaults, settings);
var config = this.config; var config = this.config;
$(this).change (function () { $(this).change (function () {
var $select = $(config.alertSelect).disable (); var $select = $(config.alertSelect).disable ();
$(config.loading).show (); $(config.loading).show ();
@ -212,7 +214,7 @@
this.config = $.extend (this.config, $.pandoraSelectOS.defaults, settings); this.config = $.extend (this.config, $.pandoraSelectOS.defaults, settings);
var config = this.config; var config = this.config;
$(this).change (function () { $(this).change (function () {
var id_os = this.value; var id_os = this.value;
@ -259,7 +261,7 @@
this.config = $.extend (this.config, $.pandoraSelectGroupIcon.defaults, settings); this.config = $.extend (this.config, $.pandoraSelectGroupIcon.defaults, settings);
var config = this.config; var config = this.config;
$(this).change (function () { $(this).change (function () {
var id_group = this.value; var id_group = this.value;

View File

@ -383,7 +383,13 @@ foreach ($modules as $module) {
$data = array (); $data = array ();
if (($module["id_modulo"] != 1) && ($module["id_tipo_modulo"] != 100)) { if (($module["id_modulo"] != 1) && ($module["id_tipo_modulo"] != 100)) {
if ($module["flag"] == 0) { if ($module["flag"] == 0) {
$data[0] = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente='.$id_agente.'&amp;id_agente_modulo='.$module["id_agente_modulo"].'&amp;flag=1&amp;refr=60">' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . '</a>'; $data[0] = '<a href="index.php?' .
'sec=estado&amp;' .
'sec2=operation/agentes/ver_agente&amp;' .
'id_agente=' . $id_agente . '&amp;' .
'id_agente_modulo=' . $module["id_agente_modulo"] . '&amp;' .
'flag=1&amp;' .
'refr=60">' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . '</a>';
} }
else { else {
$data[0] = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente='.$id_agente.'&amp;id_agente_modulo='.$module["id_agente_modulo"].'&amp;refr=60">' . html_print_image("images/refresh.png", true, array("border" => "0", "title" => __("Refresh"))) . '</a>'; $data[0] = '<a href="index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente='.$id_agente.'&amp;id_agente_modulo='.$module["id_agente_modulo"].'&amp;refr=60">' . html_print_image("images/refresh.png", true, array("border" => "0", "title" => __("Refresh"))) . '</a>';

View File

@ -52,7 +52,8 @@ if (is_ajax ()) {
if ($id_group > 0) { if ($id_group > 0) {
$groups = array($id_group); $groups = array($id_group);
if ($recursion) { if ($recursion) {
$groups = array_merge($groups, groups_get_id_recursive($id_group, true)); $groups = array_merge($groups,
groups_get_id_recursive($id_group, true));
} }
} }
else { else {
@ -61,13 +62,14 @@ if (is_ajax ()) {
$groups = array_keys($groups_orig); $groups = array_keys($groups_orig);
} }
$filter = " WHERE id_grupo IN (". implode(',', $groups) .") ORDER BY nombre ASC"; $filter = " WHERE id_grupo IN (" . implode(',', $groups) . ")
ORDER BY nombre ASC";
$agents = db_get_all_rows_sql("SELECT id_agente, nombre $agents = db_get_all_rows_sql("SELECT id_agente, nombre
FROM tagente" . $filter); FROM tagente" . $filter);
// Add keys prefix // Add keys prefix
if ($keys_prefix !== "") { if ($keys_prefix !== "") {
foreach($agents as $k => $v) { foreach ($agents as $k => $v) {
$agents[$keys_prefix . $k] = $v; $agents[$keys_prefix . $k] = $v;
unset($agents[$k]); unset($agents[$k]);
} }
@ -689,7 +691,8 @@ if ($flag !== '') {
if ($flag == 1 && check_acl ($config['id_user'], $id_grupo, "AW")) { if ($flag == 1 && check_acl ($config['id_user'], $id_grupo, "AW")) {
$id_agent_module = get_parameter('id_agente_modulo'); $id_agent_module = get_parameter('id_agente_modulo');
db_process_sql_update('tagente_modulo', array('flag' => 1), array('id_agente_modulo' => $id_agent_module)); db_process_sql_update('tagente_modulo',
array('flag' => 1), array('id_agente_modulo' => $id_agent_module));
} }
} }
// Check for Network FLAG change request // Check for Network FLAG change request