Fixed error in agents bulk operations

This commit is contained in:
samucarc 2018-10-08 17:57:05 +02:00
parent 11679461cd
commit 61a82337c3
2 changed files with 68 additions and 28 deletions

View File

@ -336,32 +336,39 @@ function agents_get_agents ($filter = false, $fields = false,
if (isset($filter['status'])) { if (isset($filter['status'])) {
switch ($filter['status']) { switch ($filter['status']) {
case AGENT_STATUS_NORMAL: case AGENT_STATUS_NORMAL:
$status_sql = $status_sql = "(
"normal_count = total_count critical_count = 0
AND notinit_count <> total_count"; AND warning_count = 0
AND unknown_count = 0
AND normal_count > 0)";
break; break;
case AGENT_STATUS_WARNING: case AGENT_STATUS_WARNING:
$status_sql = $status_sql = "(
"critical_count = 0 AND warning_count > 0"; critical_count = 0
AND warning_count > 0
AND total_count > 0)";
break; break;
case AGENT_STATUS_CRITICAL: case AGENT_STATUS_CRITICAL:
$status_sql = $status_sql = "critical_count > 0";
"critical_count > 0";
break; break;
case AGENT_STATUS_UNKNOWN: case AGENT_STATUS_UNKNOWN:
$status_sql = $status_sql = "(
"critical_count = 0 AND warning_count = 0 critical_count = 0
AND unknown_count > 0"; AND warning_count = 0
AND unknown_count > 0)";
break; break;
case AGENT_STATUS_NOT_NORMAL: case AGENT_STATUS_NOT_NORMAL:
$status_sql = $status_sql = "(
"( critical_count > 0
normal_count <> total_count OR warning_count > 0
AND OR unknown_count > 0
(normal_count + notinit_count) <> total_count)"; OR total_count = 0
OR total_count = notinit_count)";
break; break;
case AGENT_STATUS_NOT_INIT: case AGENT_STATUS_NOT_INIT:
$status_sql = "notinit_count = total_count"; $status_sql = "(
total_count = 0
OR total_count = notinit_count)";
break; break;
} }
unset($filter['status']); unset($filter['status']);
@ -915,23 +922,39 @@ function agents_get_group_agents (
if (isset($search['status'])) { if (isset($search['status'])) {
switch ($search['status']) { switch ($search['status']) {
case AGENT_STATUS_NORMAL: case AGENT_STATUS_NORMAL:
$filter[] = "(normal_count = total_count AND notinit_count <> total_count)"; $filter[] = "(
critical_count = 0
AND warning_count = 0
AND unknown_count = 0
AND normal_count > 0)";
break; break;
case AGENT_STATUS_WARNING: case AGENT_STATUS_WARNING:
$filter[] = "(critical_count = 0 AND warning_count > 0)"; $filter[] = "(
critical_count = 0
AND warning_count > 0
AND total_count > 0)";
break; break;
case AGENT_STATUS_CRITICAL: case AGENT_STATUS_CRITICAL:
$filter[] = "critical_count > 0"; $filter[] = "critical_count > 0";
break; break;
case AGENT_STATUS_UNKNOWN: case AGENT_STATUS_UNKNOWN:
$filter[] = "(critical_count = 0 AND warning_count = 0 AND unknown_count > 0)"; $filter[] = "(
critical_count = 0
AND warning_count = 0
AND unknown_count > 0)";
break; break;
case AGENT_STATUS_NOT_NORMAL: case AGENT_STATUS_NOT_NORMAL:
$filter[] = "normal_count <> total_count $filter[] = "(
AND critical_count = 0 AND warning_count = 0"; critical_count > 0
OR warning_count > 0
OR unknown_count > 0
OR total_count = 0
OR total_count = notinit_count)";
break; break;
case AGENT_STATUS_NOT_INIT: case AGENT_STATUS_NOT_INIT:
$filter[] = "notinit_count = total_count"; $filter[] = "(
total_count = 0
OR total_count = notinit_count)";
break; break;
} }
unset($search['status']); unset($search['status']);
@ -2762,7 +2785,7 @@ function agents_get_status_clause($state, $show_not_init = true) {
)"; )";
case AGENT_STATUS_NOT_INIT: case AGENT_STATUS_NOT_INIT:
return $show_not_init return $show_not_init
? "(ta.total_count = ta.notinit_count)" ? "(ta.total_count = ta.notinit_count OR ta.total_count = 0)"
: "1=0"; : "1=0";
case AGENT_STATUS_NORMAL: case AGENT_STATUS_NORMAL:
return "( return "(

View File

@ -85,22 +85,39 @@ if (is_ajax ()) {
switch ($status_agents) { switch ($status_agents) {
case AGENT_STATUS_NORMAL: case AGENT_STATUS_NORMAL:
$filter[] = "(normal_count = total_count)"; $filter[] = "(
critical_count = 0
AND warning_count = 0
AND unknown_count = 0
AND normal_count > 0)";
break; break;
case AGENT_STATUS_WARNING: case AGENT_STATUS_WARNING:
$filter[] = "(critical_count = 0 AND warning_count > 0)"; $filter[] = "(
critical_count = 0
AND warning_count > 0
AND total_count > 0)";
break; break;
case AGENT_STATUS_CRITICAL: case AGENT_STATUS_CRITICAL:
$filter[] = "(critical_count > 0)"; $filter[] = "(critical_count > 0)";
break; break;
case AGENT_STATUS_UNKNOWN: case AGENT_STATUS_UNKNOWN:
$filter[] = "(critical_count = 0 AND warning_count = 0 AND unknown_count > 0)"; $filter[] = "(
critical_count = 0
AND warning_count = 0
AND unknown_count > 0)";
break; break;
case AGENT_STATUS_NOT_NORMAL: case AGENT_STATUS_NOT_NORMAL:
$filter[] = "(normal_count <> total_count)"; $filter[] = "(
critical_count > 0
OR warning_count > 0
OR unknown_count > 0
OR total_count = 0
OR total_count = notinit_count)";
break; break;
case AGENT_STATUS_NOT_INIT: case AGENT_STATUS_NOT_INIT:
$filter[] = "(notinit_count = total_count)"; $filter[] = "(
total_count = 0
OR total_count = notinit_count)";
break; break;
} }
$filter['order'] = "alias ASC"; $filter['order'] = "alias ASC";