diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index fa283fe01d..6a49f4258c 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,7 @@ +2012-10-03 Vanessa Gil + + * util/tool_api.pl: Changed format for creating events using API. + 2012-10-01 Sancho Lerena * util/pandora_manage.pl: Fixed problem in CLI enabling the eacl from diff --git a/pandora_server/util/tool_api.pl b/pandora_server/util/tool_api.pl index 2b53ce96a1..0cfade3447 100644 --- a/pandora_server/util/tool_api.pl +++ b/pandora_server/util/tool_api.pl @@ -23,33 +23,15 @@ tool_api_main(); # Print a help screen and exit. ############################################################################## sub help_screen{ - print "Usage: perl $0 -p -n [-o ] -u \n\n"; - print "Call syntax create_event: \n\t"; - print ": Name of event (required)\n\t"; - print ": Serialized parameters separated by comma (optional). In this order: \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t\t"; - print " \n\t"; - print ": Credentials of API and database separated by comma (required). In this order\n\t\t"; - print ",,\n\t"; - print "Example: \n\t"; - print "perl ./api.pl -p http://127.0.0.1/pandora_console/include/api.php -n name_event_create_api -o 1,admin,0,0 -u 1234,admin,pandora\n"; - - print "\n"; + print "Usage: perl $0 -p -u -name -group -type [-agent ] [-user ] [-status ] [-am ] [-alert ] [-criticity ] [-comment ] [-tag ] [-source ] [-extra ] [-c_instructions ] [-w_instructions ] [-u_instructions ] [-owner ] \n\n"; + print "Call syntax create_event: \n\t"; + print ": Credentials of API and database separated by comma (required). In this order\n\t\t"; + print ",,\n\n"; + + print "EXAMPLE: \n\t"; + print "perl tool_api.pl -p http://localhost/pandora_console/include/api.php -u 1234,admin,pandora -name \"Event name\" -group 2 -type \"system\" -agent 2 -user \"admin\" -status 0 -am 0 -alert 9 -criticity 3 -comment \"User comments\" -tag \"tags\" -source \"Pandora\" -extra 3 -c_instructions \"Critical instructions\" -w_instructions \"Warning instructions\" -u_instructions \"Unknown instructions\" -owner \"other\" "; + print "\n\n\n"; exit; } @@ -78,67 +60,139 @@ sub tool_api_init () { sub tool_api_main () { my $api_path; - my $event_name; + my $event_name; + my $id_group; + my $event_type; my $data_event; my $credentials; my $api_pass; my $db_user; my $db_pass; my @db_info; + my $id_agent; + my $id_user = ''; + my $status = ''; + my $id_agent_module = ''; + my $id_alert_am = ''; + my $criticity = ''; + my $user_comment = ''; + my $tags = ''; + my $source = ''; + my $id_extra = ''; + my $critical_instructions = ''; + my $warning_instructions = ''; + my $unknown_instructions = ''; + my $owner_user = ''; #~ help or api path (required) if ($ARGV[0] eq '-h') { print "HELP!\n"; help_screen (); } elsif ($ARGV[0] ne '-p') { - print "Missing API path! See help info...\n"; + print "[ERROR] Missing API path! Read help info:\n\n"; help_screen (); } else { $api_path = $ARGV[1]; } - #~ event name (required) - if ($ARGV[2] ne '-n') { - print "Missing event name! See help info...\n"; - help_screen (); - } else { - $event_name = $ARGV[3]; - } - - #~ other event fields (optional) - if ($ARGV[4] eq '-o') { - $data_event = $ARGV[5]; + #~ credentials of database + if ($ARGV[2] eq '-u') { + $credentials = $ARGV[3]; + @db_info = split(',', $credentials); - #~ credentials of database - if ($ARGV[6] eq '-u') { - $credentials = $ARGV[7]; - @db_info = split(',', $credentials); - - if ($#db_info < 2) { - print "Invalid database credentials! See help info...\n"; - help_screen (); - } else { - $api_pass = $db_info[0]; - $db_user = $db_info[1]; - $db_pass = $db_info[2]; - - } - } else { - print "Missing database credentials! See help info...\n"; + if ($#db_info < 2) { + print "[ERROR] Invalid database credentials! Read help info:\n\n"; help_screen (); + } else { + $api_pass = $db_info[0]; + $db_user = $db_info[1]; + $db_pass = $db_info[2]; } - } elsif ($ARGV[4] eq '-u') { #~ credentials of database - $credentials = $ARGV[5]; } else { - print "Missing database credentials! See help info...\n"; + print "[ERROR] Missing database credentials! Read help info:\n\n"; help_screen (); } + #~ event name (required) + if ($ARGV[4] ne '-name') { + print "[ERROR] Missing event name! Read help info:\n\n"; + help_screen (); + } else { + $event_name = $ARGV[5]; + } + + #~ id group (required) + if ($ARGV[6] ne '-group') { + print "[ERROR] Missing event group! Read help info:\n\n"; + help_screen (); + } else { + $id_group = $ARGV[7]; + $data_event = $id_group; + } + + #~ id group (required) + if ($ARGV[8] ne '-type') { + print "[ERROR] Missing event type! Read help info:\n\n"; + help_screen (); + } else { + $event_type = $ARGV[9]; + $data_event .= ",".$event_type; + } + + my $i = 0; + foreach (@ARGV) { + my $line = $_; + if ($line eq '-agent') { + $id_agent = $ARGV[$i+1]; + } + if ($line eq '-user') { + $id_user = $ARGV[$i+1]; + } + if ($line eq '-status') { + $status = $ARGV[$i+1]; + } + if ($line eq '-am') { + $id_agent_module = $ARGV[$i+1]; + } + 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 '-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 '-c_instructions') { + $critical_instructions = $ARGV[$i+1]; + } + if ($line eq '-w_instructions') { + $warning_instructions = $ARGV[$i+1]; + } + if ($line eq '-u_instructions') { + $unknown_instructions = $ARGV[$i+1]; + } + if ($line eq '-owner') { + $owner_user = $ARGV[$i+1]; + } + $i++; + } + + $data_event .= ",".$id_agent.",".$id_user.",".$status.",".$id_agent_module.",".$id_alert_am.",".$criticity.",".$user_comment.",".$tags.",".$source.",".$id_extra.",".$critical_instructions.",".$warning_instructions.",".$unknown_instructions.",".$owner_user; my @args = @ARGV; my $ltotal=$#args; if ($ltotal < 0) { - print "[ERROR] No valid arguments\n\n"; + print "[ERROR] No valid arguments. Read help info:\n\n"; help_screen (); exit; } @@ -147,7 +201,7 @@ sub tool_api_main () { my $content = get($call_api); if ($content == undef) { - print "[ERROR] Not respond or bad syntax.\n\n"; + print "[ERROR] Not respond or bad syntax. Read help info:\n\n"; help_screen(); } else { print "Event ID: $content";