From 6e8a4abaae7386598a1355827992d414f8ac9ae8 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 30 Jun 2022 19:22:01 +0200 Subject: [PATCH] Generate events for pandora_db related problems. Generate events if pandora_db has never been run or has not been run for more than 24 hours. --- pandora_server/lib/PandoraFMS/Core.pm | 30 ++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index a068486c79..f1419da6db 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5788,30 +5788,18 @@ sub pandora_self_monitoring ($$) { } my $queued_modules = get_db_value ($dbh, "SELECT SUM(queued_modules) FROM tserver WHERE BINARY name = '".$pa_config->{"servername"}."'"); - if (!defined($queued_modules)) { $queued_modules = 0; } - my $dbmaintance; - if ($RDBMS eq 'postgresql') { - $dbmaintance = get_db_value ($dbh, - "SELECT COUNT(*) - FROM tconfig - WHERE token = 'db_maintance' - AND NULLIF(value, '')::int > UNIX_TIMESTAMP() - 86400"); - } - elsif ($RDBMS eq 'oracle') { - $dbmaintance = get_db_value ($dbh, - "SELECT COUNT(*) - FROM tconfig - WHERE token = 'db_maintance' AND DBMS_LOB.substr(value, 100, 1) > UNIX_TIMESTAMP() - 86400"); - } - else { - $dbmaintance = get_db_value ($dbh, - "SELECT COUNT(*) - FROM tconfig - WHERE token = 'db_maintance' AND value > UNIX_TIMESTAMP() - 86400"); + my $pandoradb = 0; + my $pandoradb_tstamp = get_db_value ($dbh, "SELECT `value` FROM tconfig WHERE token = 'db_maintance'"); + if (!defined($pandoradb_tstamp) || $pandoradb_tstamp == 0) { + pandora_event ($pa_config, "Pandora DB maintenance tool has never been run.", 0, 0, 4, 0, 0, 'system', 0, $dbh); + } elsif ($pandoradb_tstamp < time() - 86400) { + pandora_event ($pa_config, "Pandora DB maintenance tool has not been run since " . strftime("%Y-%m-%d %H:%M:%S", localtime($pandoradb_tstamp)) . ".", 0, 0, 4, 0, 0, 'system', 0, $dbh); + } else { + $pandoradb = 1; } my $start_performance = time; @@ -5825,7 +5813,7 @@ sub pandora_self_monitoring ($$) { $xml_output .=" "; $xml_output .=" Database Maintenance"; $xml_output .=" generic_proc"; - $xml_output .=" $dbmaintance"; + $xml_output .=" $pandoradb"; $xml_output .=" "; $xml_output .=" ";