From 00d2fde04c3e7f75d2084fd4b57bb5082056a6e8 Mon Sep 17 00:00:00 2001 From: vgilc Date: Mon, 11 Mar 2013 17:53:13 +0000 Subject: [PATCH] 2013-03-11 Vanessa Gil * util/pandora_revent.pl: Addapted to API's function 'create_event'. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7833 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 ++ pandora_server/util/pandora_revent.pl | 81 ++++++++++++++------------- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 7bc3bf7d21..9193cde8f1 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2013-03-11 Vanessa Gil + + * util/pandora_revent.pl: Addapted to API's function + 'create_event'. + 2013-03-11 Sancho Lerena * util/pandora_xml_stress.conf: Updated conf file to use the new diff --git a/pandora_server/util/pandora_revent.pl b/pandora_server/util/pandora_revent.pl index 09c3101a98..f23553a146 100755 --- a/pandora_server/util/pandora_revent.pl +++ b/pandora_server/util/pandora_revent.pl @@ -33,42 +33,41 @@ Where options:\n -create_event -name : Free text -group : Group ID (use 0 for 'all') - -type : unknown, alert_fired, alert_recovered, alert_ceased - alert_manual_validation, system, error, new_agent - configuration_change, going_unknown, going_down_critical, - going_down_warning, going_up_normal + -agent :Agent ID Optional parameters: - [-agent ] : Agent ID - [-agent_name ] : Set agent by name (Exact match!) - [-user ] : User comment (use in combination with -comment option) [-status ] : 0 New, 1 Validated, 2 In process - [-am ] : ID Agent Module linked to event - [-module_name ] : Name of the module linked to the event (You need or ) - [-alert ] : ID Alert Module linked to event + [-user ] : User comment (use in combination with -comment option) + [type ] : unknown, alert_fired, alert_recovered, alert_ceased + alert_manual_validation, system, error, new_agent + configuration_change, going_unknown, going_down_critical, + going_down_warning, going_up_normal [-criticity ] : 0 Maintance, 1 Informative, 2 Normal, 3 Warning, 4 Crit, 5 Minor, 6 Major - - [-comment ] : Free text for comment - [-tag ] : Tag (must exist in the system to be imported) - [-source ] : (By default 'Pandora') - [-extra ] + [-am ] : ID Agent Module linked to event + [-alert ] : ID Alert Module linked to event [-c_instructions ] [-w_instructions ] [-u_instructions ] - [-owner ] : Use the login name, not the descriptive \n\n"; + [-source ] : (By default 'Pandora') + [-tag ] : Tag (must exist in the system to be imported)"; print "Credential/API syntax: \n\n\t"; print ": API credentials separated by comma: ,,\n\n"; print "Example of event generation:\n\n"; - print "\t./pandora_revent.pl -p http://192.168.70.160/pandora_console/include/api.php -u pot12,admin,pandora \ -\t-create_event -name \"Sample event executed from commandline\" -group 2 -type \"system\" -agent 2 \ -\t-user \"admin\" -status 0 -am 0 -alert 9 -criticity 3 -comment \"User comments\" -tag \"tags\" \ -\t-source \"Commandline\" -extra 3 -c_instructions \"Critical instructions\" \ -\t-w_instructions \"Warning instructions\" -u_instructions \"Unknown instructions\" -owner \"other\" "; + #~ print "\t./pandora_revent.pl -p http://192.168.70.160/pandora_console/include/api.php -u pot12,admin,pandora \ +#~ \t-create_event -name \"Sample event executed from commandline\" -group 2 -type \"system\" -agent 2 \ +#~ \t-user \"admin\" -status 0 -am 0 -alert 9 -criticity 3 -comment \"User comments\" -tag \"tags\" \ +#~ \t-source \"Commandline\" -extra 3 -c_instructions \"Critical instructions\" \ +#~ \t-w_instructions \"Warning instructions\" -u_instructions \"Unknown instructions\" -owner \"other\" "; + + print "\t./pandora_revent.pl -p http://localhost/pandora_console/include/api.php -u 1234,admin,pandora \ + \t-create_event -name \"SampleEvent\" -group 2 -agent 189 -status 0 -user \"admin\" -type \"system\" \ + \t-criticity 3 -am 0 -alert 9 -c_instructions \"Critical instructions\" -w_instructions \"Warning instructions\" \ + \t-u_instructions \"Unknown instructions\" -source \"Commandline\" -tag \"Tags\""; print "\n\nOptions to validate event: \n\n\t"; print "$0 -p -u -validate_event -id \n\n"; @@ -172,6 +171,7 @@ sub tool_api_main () { help_screen (); } else { $event_name = $ARGV[6]; + $data_event = $event_name; } #~ id group (required) @@ -180,23 +180,24 @@ sub tool_api_main () { help_screen (); } else { $id_group = $ARGV[8]; - $data_event = $id_group; + #~ $data_event = $id_group; + $data_event .= "|".$id_group; } - #~ id group (required) - if ($ARGV[9] ne '-type') { - print "[ERROR] Missing event type! Read help info:\n\n"; + #~ id agent (required) + if ($ARGV[9] ne '-agent') { + print "[ERROR] Missing id agent! Read help info:\n\n"; help_screen (); } else { - $event_type = $ARGV[10]; - $data_event .= ",".$event_type; + $id_agent = $ARGV[10]; + $data_event .= "|".$id_agent; } my $i = 0; foreach (@ARGV) { my $line = $_; - if ($line eq '-agent') { - $id_agent = $ARGV[$i+1]; + if ($line eq '-type') { + $event_type = $ARGV[$i+1]; } if ($line eq '-agent_name') { $agent_name = $ARGV[$i+1]; @@ -219,18 +220,18 @@ sub tool_api_main () { if ($line eq '-criticity') { $criticity = $ARGV[$i+1]; } - if ($line eq '-comment') { - $user_comment = $ARGV[$i+1]; - } + #~ if ($line eq '-comment') { + #~ $user_comment = $ARGV[$i+1]; + #~ } if ($line eq '-tag') { $tags = $ARGV[$i+1]; } if ($line eq '-source') { $source = $ARGV[$i+1]; } - if ($line eq '-extra') { - $id_extra = $ARGV[$i+1]; - } + #~ if ($line eq '-extra') { + #~ $id_extra = $ARGV[$i+1]; + #~ } if ($line eq '-c_instructions') { $critical_instructions = $ARGV[$i+1]; } @@ -240,14 +241,14 @@ sub tool_api_main () { if ($line eq '-u_instructions') { $unknown_instructions = $ARGV[$i+1]; } - if ($line eq '-owner') { - $owner_user = $ARGV[$i+1]; - } + #~ if ($line eq '-owner') { + #~ $owner_user = $ARGV[$i+1]; + #~ } $i++; } - $data_event .= ",".$id_agent.",".$agent_name.",".$id_user.",".$status.",".$id_agent_module.",".$module_name.",".$id_alert_am.",".$criticity.",".$user_comment.",".$tags.",".$source.",".$id_extra.",".$critical_instructions.",".$warning_instructions.",".$unknown_instructions.",".$owner_user; - $call_api = $api_path.'?op=set&op2=create_event&id='.$event_name.'&other='.$data_event.'&other_mode=url_encode_separator_,&apipass='.$api_pass.'&user='.$db_user.'&pass='.$db_pass; + $data_event .= "|".$status."|".$id_user."|".$event_type."|".$criticity."|".$id_agent_module."|".$id_alert_am."|".$critical_instructions."|".$warning_instructions."|".$unknown_instructions."|".$source.",".$tags; + $call_api = $api_path.'?op=set&op2=create_event&other='.$data_event.'&other_mode=url_encode_separator_|&apipass='.$api_pass.'&user='.$db_user.'&pass='.$db_pass; } elsif ($ARGV[4] eq '-validate_event') { #~ id event(required)