From 1c719b3bdecc60c033b9022aea02e6a93c54ba9b Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Tue, 30 Jun 2015 16:32:31 +0200 Subject: [PATCH] Fixes for the metaconsole's plug-in server. --- pandora_server/bin/pandora_server | 2 +- pandora_server/lib/PandoraFMS/Core.pm | 11 ++++++----- pandora_server/lib/PandoraFMS/Tools.pm | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index f6c5f5fb3f..3dad433d68 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -107,7 +107,7 @@ sub pandora_startup () { pandora_audit (\%Config, 'Pandora FMS Server Daemon starting', 'SYSTEM', 'System', $DBH); # Load servers - if (!defined($Config{"license_type"}) || $Config{"license_type"} != METACONSOLE_LICENSE) { + if (!is_metaconsole(\%Config)) { pandora_reset_server (\%Config, $DBH); push (@Servers, new PandoraFMS::DataServer (\%Config, $DBH)); push (@Servers, new PandoraFMS::NetworkServer (\%Config, $DBH)); diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index a23b56308f..670a05ae03 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2856,9 +2856,10 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) { $id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags, $critical_instructions, $warning_instructions, $unknown_instructions, $custom_data) = @_; - + my $event_table = is_metaconsole($pa_config) ? 'tmetaconsole_event' : 'tevento'; + my $agent = undef; - if ($id_agente != 0) { + if (defined($id_agente) && $id_agente != 0) { $agent = get_db_single_row ($dbh, 'SELECT * FROM tagente WHERE id_agente = ?', $id_agente); if (defined ($agent) && $agent->{'quiet'} == 1) { logger($pa_config, "Generate Event. The agent '" . $agent->{'nombre'} . "' is in quiet mode.", 10); @@ -2867,7 +2868,7 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) { } my $module = undef; - if ($id_agentmodule != 0) { + if (defined($id_agentmodule) && $id_agentmodule != 0) { $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agentmodule); if (defined ($module) && $module->{'quiet'} == 1) { logger($pa_config, "Generate Event. The module '" . $module->{'nombre'} . "' is in quiet mode.", 10); @@ -2912,12 +2913,12 @@ sub pandora_event ($$$$$$$$$$;$$$$$$$$$) { # Validate events with the same event id if (defined ($id_extra) && $id_extra ne '') { logger($pa_config, "Updating events with extended id '$id_extra'.", 10); - db_do ($dbh, 'UPDATE tevento SET estado = 1, ack_utimestamp = ? WHERE estado = 0 AND id_extra=?', $utimestamp, $id_extra); + db_do ($dbh, 'UPDATE ' . $event_table . ' SET estado = 1, ack_utimestamp = ? WHERE estado = 0 AND id_extra=?', $utimestamp, $id_extra); } # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); - db_do ($dbh, 'INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data) + db_do ($dbh, 'INSERT INTO ' . $event_table . ' (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, user_comment, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $comment, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data); # Do not write to the event file diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index c31e2751e4..5b567ec74b 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -71,6 +71,7 @@ our @EXPORT = qw( float_equal sqlWrap is_numeric + is_metaconsole clean_blank pandora_sendmail pandora_trash_ascii @@ -1375,6 +1376,19 @@ sub valid_regex ($) { return 1; } +############################################################################### +# Returns 1 if a valid metaconsole license is configured, 0 otherwise. +############################################################################### +sub is_metaconsole ($) { + my ($pa_config) = @_; + + if (defined($pa_config->{"license_type"}) && $pa_config->{"license_type"} == METACONSOLE_LICENSE) { + return 1; + } + + return 0; +} + # End of function declaration # End of defined Code