diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index dda28a5325..8e794aa56e 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2013-02-14 Sergio Martin + + * lib/PandoraFMS/Core.pm + bin/pandora_server + util/pandora_db.pl: Adapt status counts querys to use only + not disabled modules + 2013-02-13 Ramon Novoa * lib/PandoraFMS/NmapParser.pm: Merged with version 1.3 of Nmap::Parser. diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 9751db1049..fd0ac8d307 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -87,12 +87,12 @@ sub pandora_startup () { my @agents = get_db_rows ($DBH, 'SELECT id_agente FROM tagente'); foreach my $agent (@agents) { my $agent_id = $agent->{'id_agente'}; - db_do ($DBH, 'UPDATE tagente SET normal_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=0 AND disabled=0), - critical_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=1 AND disabled=0), - warning_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=2 AND disabled=0), - unknown_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=3 AND disabled=0), - notinit_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=4 AND disabled=0), - total_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND disabled=0) + db_do ($DBH, 'UPDATE tagente SET normal_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=0 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + critical_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=1 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + warning_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=2 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + unknown_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=3 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + notinit_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND estado=4 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + total_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $agent_id . ' AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)) WHERE id_agente = ' . $agent_id); } diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 5e60c329c5..49fc55d883 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2238,12 +2238,14 @@ sub pandora_create_module_from_hash ($$$) { db_do ($dbh, 'INSERT INTO tagente_estado (id_agente_modulo, id_agente, estado, last_status, last_known_status, last_try) VALUES (?, ?, ?, ?, ?, \'1970-01-01 00:00:00\')', $module_id, $parameters->{'id_agente'}, $status, $status, $status); - # Update the module status count - if ($status == 4) { - db_do ($dbh, 'UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente=?', $parameters->{'id_agente'}); - } - else { - db_do ($dbh, 'UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 WHERE id_agente=?', $parameters->{'id_agente'}); + # Update the module status count. When the module is created disabled dont do it + if(!defined($parameters->{'disabled'}) || $parameters->{'disabled'} == 0) { + if ($status == 4) { + db_do ($dbh, 'UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente=?', $parameters->{'id_agente'}); + } + else { + db_do ($dbh, 'UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 WHERE id_agente=?', $parameters->{'id_agente'}); + } } return $module_id; diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index e5d1a863ac..dd4c4dda4c 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -637,8 +637,6 @@ sub pandora_checkdb_consistency { # Delete the module db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agente_modulo); - # Update the module status count - db_do ($dbh, 'UPDATE tagente SET total_count=total_count-1, notinit_count=notinit_count-1 WHERE id_agente=?', $module->{'id_agente'}); # Delete any alerts associated to the module db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ?', $id_agente_modulo); @@ -655,11 +653,8 @@ sub pandora_checkdb_consistency { next if (defined($is_policy_module) && $is_policy_module); # Delete the module - db_do ($dbh, 'DELETE FROM tagente_modulo WHERE disabled = 0 AND id_agente_modulo = ?', $id_agente_modulo);; - - # Update the module status count - db_do ($dbh, 'UPDATE tagente SET total_count=total_count-1, unknown_count=unknown_count-1 WHERE id_agente=?', $module->{'id_agente'}); - + db_do ($dbh, 'DELETE FROM tagente_modulo WHERE disabled = 0 AND id_agente_modulo = ?', $id_agente_modulo); + # Delete any alerts associated to the module db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ? AND NOT EXISTS (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente_modulo = ?)', $id_agente_modulo, $id_agente_modulo); } @@ -700,12 +695,12 @@ sub pandora_checkdb_consistency { my @agents = get_db_rows ($dbh, 'SELECT id_agente FROM tagente'); foreach my $agent (@agents) { my $id_agente = $agent->{'id_agente'}; - db_do ($dbh, 'UPDATE tagente SET normal_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=0 AND disabled=0), - critical_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=1 AND disabled=0), - warning_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=2 AND disabled=0), - unknown_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=3 AND disabled=0), - notinit_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=4 AND disabled=0), - total_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND disabled=0) + db_do ($dbh, 'UPDATE tagente SET normal_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=0 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + critical_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=1 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + warning_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=2 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + unknown_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=3 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + notinit_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND estado=4 AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)), + total_count=(SELECT COUNT(*) FROM tagente_estado WHERE id_agente=' . $id_agente . ' AND id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_modulo WHERE disabled=0)) WHERE id_agente = ' . $id_agente); } }