From 55c59585baeaa1c42dda08ee3538425de28dd453 Mon Sep 17 00:00:00 2001 From: vgilc Date: Tue, 14 Feb 2012 14:53:22 +0000 Subject: [PATCH] 2012-02-14 Vanessa Gil * util/pandora_manage.pl lib/PandoraFMS/Core.pm: Added 'tags'parameter to create_event and check if user name exists. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5596 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 6 +++++ pandora_server/lib/PandoraFMS/Core.pm | 16 ++++++++----- pandora_server/util/pandora_manage.pl | 34 ++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 29f7975e6a..28d1202bf1 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,9 @@ +2012-02-14 Vanessa Gil + + * util/pandora_manage.pl + lib/PandoraFMS/Core.pm: Added 'tags'parameter + to create_event and check if user name exists. + 2012-02-14 Ramon Novoa * util/pandora_xml_stress.conf: Removed a trailing blank space from diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 1aa21f709a..fb2bbf2c93 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1539,16 +1539,20 @@ Generate an event. =cut ########################################################################## -sub pandora_event ($$$$$$$$$$;$$$$) { +sub pandora_event ($$$$$$$$$$;$$$$$) { my ($pa_config, $evento, $id_grupo, $id_agente, $severity, - $id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra) = @_; + $id_alert_am, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags) = @_; logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); # Get module tags my $module_tags = ''; - if (defined ($id_agentmodule) && $id_agentmodule > 0) { - $module_tags = pandora_get_module_tags ($pa_config, $dbh, $id_agentmodule); + if (defined ($tags) && ($tags ne '')) { + $module_tags = $tags + } else { + if (defined ($id_agentmodule) && $id_agentmodule > 0) { + $module_tags = pandora_get_module_tags ($pa_config, $dbh, $id_agentmodule); + } } # Set default values for optional parameters @@ -1561,8 +1565,8 @@ sub pandora_event ($$$$$$$$$$;$$$$) { my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); $id_agentmodule = 0 unless defined ($id_agentmodule); - 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) - 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); + 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) + 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); } ########################################################################## diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index fb044aae6b..6d2a10c104 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -129,7 +129,7 @@ sub help_screen{ help_screen_line('--disable_eacl', '', 'Disable enterprise ACL system'); help_screen_line('--enable_eacl', '', 'Enable enterprise ACL system'); print "EVENTS:\n\n" unless $param ne ''; - help_screen_line('--create_event', ' [ ]', 'Add event'); + help_screen_line('--create_event', ' [ ]', 'Add event'); help_screen_line('--validate_event', ' ', 'Validate events'); help_screen_line('--validate_event_id', '', 'Validate event given a event id'); help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); @@ -2247,10 +2247,20 @@ sub cli_delete_profile() { ############################################################################## sub cli_create_event() { - my ($event,$event_type,$group_name,$agent_name,$module_name,$event_status,$severity,$template_name, $user_name, $comment, $source, $id_extra) = @ARGV[2..13]; + my ($event,$event_type,$group_name,$agent_name,$module_name,$event_status,$severity,$template_name, $user_name, $comment, $source, $id_extra, $tags) = @ARGV[2..14]; $event_status = 0 unless defined($event_status); $severity = 0 unless defined($severity); + + my $id_user; + + if (!defined($user_name)) { + $id_user = 0; + } + else { + $id_user = pandora_get_user_id($dbh,$user_name); + exist_check($id_user,'user',$user_name); + } my $id_group; @@ -2284,11 +2294,11 @@ sub cli_create_event() { my $id_alert_agent_module; - if(defined($template_name)) { + if(defined($template_name) && $template_name ne '') { my $id_template = get_template_id($dbh,$template_name); exist_check($id_template,'template',$template_name); $id_alert_agent_module = get_template_module_id($dbh,$id_agentmodule,$id_template); - exist_check($id_alert_agent_module,'template module',$template_name); + exist_check($id_alert_agent_module,'alert template module',$template_name); } else { $id_alert_agent_module = 0; @@ -2297,7 +2307,7 @@ sub cli_create_event() { print "[INFO] Adding event '$event' for agent '$agent_name' \n\n"; pandora_event ($conf, $event, $id_group, $id_agent, $severity, - $id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra); + $id_alert_agent_module, $id_agentmodule, $event_type, $event_status, $dbh, $source, $user_name, $comment, $id_extra, $tags); } ############################################################################## @@ -3124,6 +3134,18 @@ sub pandora_get_event_name($$) { return defined ($event_name) ? $event_name : -1; } +############################################################################## +# Return user id given a user name +############################################################################## + +sub pandora_get_user_id($$) { + my ($dbh,$user_name) = @_; + + my $user_id = get_db_value($dbh, 'SELECT id_user FROM tusuario WHERE id_user = ? or fullname = ?',$user_name, $user_name); + + return defined ($user_id) ? $user_id : -1; +} + ############################################################################### ############################################################################### # MAIN @@ -3245,7 +3267,7 @@ sub pandora_manage_main ($$$) { cli_delete_profile(); } elsif ($param eq '--create_event') { - param_check($ltotal, 12, 9); + param_check($ltotal, 13, 10); cli_create_event(); } elsif ($param eq '--validate_event') {