Added events in DataServer processed XML

Former-commit-id: e3166d9fb2bcbf1b6aa574ae1a96e796a26a70a6
This commit is contained in:
fermin831 2019-01-21 15:12:46 +01:00
parent 979a87762e
commit cbe518dc53
1 changed files with 48 additions and 1 deletions

View File

@ -29,6 +29,8 @@ use XML::Parser::Expat;
use XML::Simple; use XML::Simple;
use POSIX qw(setsid strftime); use POSIX qw(setsid strftime);
use IO::Uncompress::Unzip; use IO::Uncompress::Unzip;
use JSON qw(decode_json);
use MIME::Base64;
# For Reverse Geocoding # For Reverse Geocoding
use LWP::Simple; use LWP::Simple;
@ -321,6 +323,7 @@ sub process_xml_data ($$$$$) {
# Get agent id # Get agent id
my $agent_id = get_agent_id ($dbh, $agent_name); my $agent_id = get_agent_id ($dbh, $agent_name);
my $group_id = 0;
if ($agent_id < 1) { if ($agent_id < 1) {
if ($pa_config->{'autocreate'} == 0) { if ($pa_config->{'autocreate'} == 0) {
logger($pa_config, "ERROR: There is no agent defined with name $agent_name", 3); logger($pa_config, "ERROR: There is no agent defined with name $agent_name", 3);
@ -329,7 +332,7 @@ sub process_xml_data ($$$$$) {
# Get OS, group and description # Get OS, group and description
my $os = pandora_get_os ($dbh, $data->{'os_name'}); my $os = pandora_get_os ($dbh, $data->{'os_name'});
my $group_id = $pa_config->{'autocreate_group'}; $group_id = $pa_config->{'autocreate_group'};
if (! defined (get_group_name ($dbh, $group_id))) { if (! defined (get_group_name ($dbh, $group_id))) {
if (defined ($data->{'group_id'}) && $data->{'group_id'} ne '') { if (defined ($data->{'group_id'}) && $data->{'group_id'} ne '') {
$group_id = $data->{'group_id'}; $group_id = $data->{'group_id'};
@ -594,6 +597,9 @@ sub process_xml_data ($$$$$) {
# Process snmptrapd modules # Process snmptrapd modules
enterprise_hook('process_snmptrap_data', [$pa_config, $data, $server_id, $dbh]); enterprise_hook('process_snmptrap_data', [$pa_config, $data, $server_id, $dbh]);
# Process events
process_events_dataserver($pa_config, $data, $agent_id, $group_id, $dbh);
} }
########################################################################## ##########################################################################
@ -962,5 +968,46 @@ sub unlink_modules {
db_do($dbh, "UPDATE tagente_modulo SET parent_module_id = 0 WHERE id_agente_modulo = ?", $child_id); db_do($dbh, "UPDATE tagente_modulo SET parent_module_id = 0 WHERE id_agente_modulo = ?", $child_id);
} }
##########################################################################
# Process events in the XML.
##########################################################################
sub process_events_dataserver {
my ($pa_config, $data, $agent_id, $group_id, $dbh) = @_;
return unless defined($data->{'events'});
foreach my $event (@{$data->{'events'}}) {
next unless defined($event->{'event'}) && defined($event->{'event'}->[0]);
my $event_info_encoded = $event->{'event'}->[0];
# Try to decode the base64 inside
my $event_info;
eval {
$event_info = decode_json(decode_base64($event_info_encoded));
};
if ($@) {
logger($pa_config, "Error processing base64 event data '$event_info_encoded'.", 5);
next;
}
next unless defined($event_info->{'data'});
pandora_event(
$pa_config,
$event_info->{'data'},
$group_id,
$agent_id,
defined($event_info->{'severity'}) ? $event_info->{'severity'} : 0,
0,
0,
'system',
0,
$dbh
);
}
return;
}
1; 1;
__END__ __END__