diff --git a/pandora_server/util/pandora_revent.pl b/pandora_server/util/pandora_revent.pl index f63f1329e7..3fc50bdffe 100755 --- a/pandora_server/util/pandora_revent.pl +++ b/pandora_server/util/pandora_revent.pl @@ -26,24 +26,23 @@ sub help_screen{ print "Options to create event: -\t$0 -p -create event +\t$0 -p -u -create_event Where options:\n - -u - -create_event + -u : API credentials separated by comma: ,, -name : Free text -group : Group ID (use 0 for 'all') - -agent : Agent ID + -agent : Agent ID Optional parameters: [-status ] : 0 New, 1 Validated, 2 In process [-user ] : User comment (use in combination with -comment option) - [-type ] : unknown, alert_fired, alert_recovered, alert_ceased + [-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, + [-severity ] : 0 Maintance, 1 Informative, 2 Normal, 3 Warning, @@ -56,23 +55,20 @@ Optional parameters: [-w_instructions ] [-u_instructions ] [-user_comment ] - [-owner_user ] + [-owner_user ] : Use the login name, not the descriptive [-source ] : (By default 'Pandora') [-tag ] : Tag (must exist in the system to be imported) [-custom_data ]: Custom data should be a base 64 encoded JSON document - [-server_id ] : The pandora node server_id"; - - print "Credential/API syntax: \n\n\t"; - print ": API credentials separated by comma: ,,\n\n"; + [-server_id ] : The pandora node server_id\n\n"; print "Example of event generation:\n\n"; 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-severity 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 "\n\n\nOptions to validate event: \n\n\t"; print "$0 -p -u -validate_event -id \n\n"; print "Sample of event validation: \n\n\t"; @@ -119,17 +115,14 @@ sub tool_api_main () { my $db_pass; my @db_info; my $id_agent; - my $agent_name; my $id_user = ''; my $status = ''; my $id_agent_module = ''; - my $module_name = ''; my $id_alert_am = ''; - my $criticity = ''; + my $severity = ''; my $user_comment = ''; my $tags = ''; my $source = ''; - my $id_extra = ''; my $critical_instructions = ''; my $warning_instructions = ''; my $unknown_instructions = ''; @@ -193,9 +186,6 @@ sub tool_api_main () { if ($line eq '-type') { $event_type = $ARGV[$i + 1]; } - if ($line eq '-agent_name') { - $agent_name = $ARGV[$i + 1]; - } if ($line eq '-user') { $id_user = $ARGV[$i + 1]; } @@ -205,14 +195,11 @@ sub tool_api_main () { if ($line eq '-am') { $id_agent_module = $ARGV[$i + 1]; } - if ($line eq '-module_name') { - $module_name = $ARGV[$i + 1]; - } if ($line eq '-alert') { $id_alert_am = $ARGV[$i + 1]; } - if ($line eq '-criticity') { - $criticity = $ARGV[$i + 1]; + if ($line eq '-severity') { + $severity = $ARGV[$i + 1]; } if ($line eq '-tag') { $tags = $ARGV[$i + 1]; @@ -264,7 +251,7 @@ sub tool_api_main () { "|" . $status . "|" . $id_user . "|" . $event_type . - "|" . $criticity . + "|" . $severity . "|" . $id_agent_module . "|" . $id_alert_am . "|" . $critical_instructions . diff --git a/pandora_server/util/pandora_revent_create.pl b/pandora_server/util/pandora_revent_create.pl old mode 100644 new mode 100755 index 3c4e68c79a..a9720f85d4 --- a/pandora_server/util/pandora_revent_create.pl +++ b/pandora_server/util/pandora_revent_create.pl @@ -12,7 +12,6 @@ # Includes list use strict; use LWP::Simple; -use URI::Escape; # Init tool_api_init(); @@ -23,62 +22,58 @@ tool_api_main(); ######################################################################## # Print a help screen and exit. ######################################################################## -sub help_screen () { - - print " -Options to create event: +sub help_screen{ -\t$0 -p -create event + print "Options to create event: + +\t$0 -p -u -create_event Where options:\n - -u - -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 + -u : API credentials separated by comma: ,, + -name : Free text + -group : Group ID (use 0 for 'all') + -agent : Agent ID Optional parameters: - [-agent ] : Agent ID - [-user ] : User comment (use in combination with -comment option) - [-status ] : 0 New, 1 Validated, 2 In process - [-am ] : ID Agent Module linked to event - [-alert ] : ID Alert Module linked to event - [-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') + [-status ] : 0 New, 1 Validated, 2 In process + [-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 + [-severity ] : 0 Maintance, + 1 Informative, + 2 Normal, + 3 Warning, + 4 Crit, + 5 Minor, + 6 Major + [-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 + [-user_comment ] + [-owner_user ] : Use the login name, not the descriptive + [-source ] : (By default 'Pandora') + [-tag ] : Tag (must exist in the system to be imported) + [-custom_data ]: Custom data should be a base 64 encoded JSON document + [-server_id ] : The pandora node server_id\n\n"; + print "Example of event generation:\n\n"; -Credential/API syntax: - - : API credentials separated by comma: ,, + 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-severity 3 -am 0 -alert 9 -c_instructions \"Critical instructions\" -w_instructions \"Warning instructions\" \ + \t-u_instructions \"Unknown instructions\" -source \"Commandline\" -tag \"Tags\"\n\n"; -Example of event generation: - - $0 -p http://localhost/pandora_console/include/api.php -u 1234,admin,pandora - -create_event -name \"SampleEvent\" -group 2 -type \"system\" -agent 189 -status 0 -user \"admin\" - -criticity 3 -am 0 -alert 9 -c_instructions \"Critical instructions\" -w_instructions \"Warning instructions\" - -u_instructions \"Unknown instructions\" -source \"Commandline\" -tag \"Tags\" -owner \"other\" - - -"; - exit; } -######################################################################## +############################################################################## # Init screen -######################################################################## +############################################################################## sub tool_api_init () { print "\nPandora FMS Remote Event Tool Copyright (c) 2013 Artica ST\n"; @@ -95,9 +90,6 @@ sub tool_api_init () { } - - - ######################################################################## ######################################################################## # MAIN @@ -117,17 +109,14 @@ sub tool_api_main () { my $db_pass; my @db_info; my $id_agent; - my $agent_name; my $id_user = ''; my $status = ''; my $id_agent_module = ''; - my $module_name = ''; my $id_alert_am = ''; - my $criticity = ''; + my $severity = ''; my $user_comment = ''; my $tags = ''; my $source = ''; - my $id_extra = ''; my $critical_instructions = ''; my $warning_instructions = ''; my $unknown_instructions = ''; @@ -135,6 +124,8 @@ sub tool_api_main () { my $id_event; my $option = $ARGV[4]; my $call_api; + my $custom_data = ""; + my $server_id = 0; #~ help or api path (required) if ($ARGV[0] eq '-h') { @@ -170,39 +161,25 @@ sub tool_api_main () { } if ($ARGV[4] eq '-create_event') { - #~ event name (required) - if ($ARGV[5] ne '-name') { - print "[ERROR] Missing event name! Read help info:\n\n"; - help_screen (); - } - else { - $event_name = uri_escape($ARGV[6]); - } - - #~ id group (required) - if ($ARGV[7] ne '-group') { - print "[ERROR] Missing event group! Read help info:\n\n"; - help_screen (); - } - else { - $id_group = $ARGV[8]; - } - - #~ id group (required) - if ($ARGV[9] ne '-type') { - print "[ERROR] Missing event type! Read help info:\n\n"; - help_screen (); - } - else { - $event_type = $ARGV[10]; - } - my $i = 0; foreach (@ARGV) { my $line = $_; + + #-----------DEBUG---------------------------- + #print("i " . $i . " line " . $line . "\n"); + if ($line eq '-agent') { $id_agent = $ARGV[$i + 1]; } + if ($line eq '-group') { + $id_group = $ARGV[$i + 1]; + } + if ($line eq '-name') { + $event_name = $ARGV[$i + 1]; + } + if ($line eq '-type') { + $event_type = $ARGV[$i + 1]; + } if ($line eq '-user') { $id_user = $ARGV[$i + 1]; } @@ -215,89 +192,107 @@ sub tool_api_main () { if ($line eq '-alert') { $id_alert_am = $ARGV[$i + 1]; } - if ($line eq '-criticity') { - $criticity = $ARGV[$i + 1]; - } - if ($line eq '-comment') { - $user_comment = $ARGV[$i + 1]; + if ($line eq '-severity') { + $severity = $ARGV[$i + 1]; } if ($line eq '-tag') { - $tags = $ARGV[$i+1]; + $tags = $ARGV[$i + 1]; } if ($line eq '-source') { - $source = uri_escape($ARGV[$i + 1]); + $source = $ARGV[$i + 1]; } if ($line eq '-c_instructions') { - $critical_instructions = uri_escape($ARGV[$i + 1]); + $critical_instructions = $ARGV[$i + 1]; } if ($line eq '-w_instructions') { - $warning_instructions = uri_escape($ARGV[$i + 1]); + $warning_instructions = $ARGV[$i + 1]; } if ($line eq '-u_instructions') { - $unknown_instructions = uri_escape($ARGV[$i + 1]); + $unknown_instructions = $ARGV[$i + 1]; } - if ($line eq '-owner') { - $owner_user = $ARGV[$i+1]; + if ($line eq '-user_comment') { + $user_comment = $ARGV[$i + 1]; } + if ($line eq '-owner_user') { + $owner_user = $ARGV[$i + 1]; + } + if ($line eq '-custom_data') { + $custom_data = $ARGV[$i + 1]; + } + if ($line eq '-server_id') { + $server_id = $ARGV[$i + 1]; + } + $i++; } - $data_event = $event_name . "|" . - $id_group . "|" . - $id_agent . "|" . - $status . "|" . - $id_user . "|" . - $event_type . "|" . - $criticity . "|" . - $id_agent_module . "|" . - $id_alert_am . "|" . - $critical_instructions . "|" . - $warning_instructions . "|" . - $unknown_instructions . "|" . - $user_comment . "|" . - $owner_user . "|" . - $source . "|" . - $tags; + if ($event_name eq "") { + print "[ERROR] Missing id agent! Read help info:\n\n"; + help_screen (); + } + if ($id_group eq "") { + print "[ERROR] Missing event group! Read help info:\n\n"; + help_screen (); + } + if ($id_agent eq "") { + print "[ERROR] Missing id agent! Read help info:\n\n"; + help_screen (); + } + + $data_event = $event_name . + "|" . $id_group . + "|" . $id_agent . + "|" . $status . + "|" . $id_user . + "|" . $event_type . + "|" . $severity . + "|" . $id_agent_module . + "|" . $id_alert_am . + "|" . $critical_instructions . + "|" . $warning_instructions . + "|" . $unknown_instructions . + "|" . $user_comment . + "|" . $owner_user . + "|" . $source . + "|" . $tags . + "|" . $custom_data . + "|" . $server_id; $call_api = $api_path . '?' . 'op=set&' . 'op2=create_event&' . - 'id=' . $event_name . '&' . - 'other=' . $data_event . '&' . + 'other=' . $data_event .'&' . 'other_mode=url_encode_separator_|&' . 'apipass=' . $api_pass . '&' . 'user=' . $db_user . '&' . 'pass=' . $db_pass; - #DEBUG TRACE# - - #print "$call_api\n"; - } - + my @args = @ARGV; - my $ltotal = $#args; + my $ltotal=$#args; if ($ltotal < 0) { print "[ERROR] No valid arguments. Read help info:\n\n"; help_screen (); exit; - } + } else { - my $content = get($call_api); - print("\n\n"); - print($call_api); - print("\n\n"); + #-----------DEBUG---------------------------- + #print($call_api . "\n\n\n"); - if ($option eq '-create_event') { - if ($content eq undef) { - print "[ERROR] Not respond or bad syntax. Read help info:\n\n"; - help_screen(); - } - else { - print "Event ID: $content"; - } - } + my $content = get($call_api); + + #-----------DEBUG---------------------------- + #print($content . "\n\n\n"); + + if ($content eq undef) { + print "[ERROR] Not respond or bad syntax. Read help info:\n\n"; + help_screen(); + } + else { + print "Event ID: $content"; + } } print "\nExiting!\n\n";