2012-10-08 Vanessa Gil <vanessa.gil@artica.es>
* util/tool_api.pl: Added: validate events using API. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7048 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
5bdb22d90e
commit
1c4984af41
|
@ -1,3 +1,7 @@
|
||||||
|
2012-10-08 Vanessa Gil <vanessa.gil@artica.es>
|
||||||
|
|
||||||
|
* util/tool_api.pl: Added: validate events using API.
|
||||||
|
|
||||||
2012-10-04 Junichi Satoh <junichi@rworks.jp>
|
2012-10-04 Junichi Satoh <junichi@rworks.jp>
|
||||||
|
|
||||||
* lib/PandoraFMS/Core.pm: Fixed unexpected execution with monthly
|
* lib/PandoraFMS/Core.pm: Fixed unexpected execution with monthly
|
||||||
|
|
|
@ -24,13 +24,24 @@ tool_api_main();
|
||||||
##############################################################################
|
##############################################################################
|
||||||
sub help_screen{
|
sub help_screen{
|
||||||
|
|
||||||
print "Usage: perl $0 -p <path to pandora console API> -u <credentials> -name <event_name> -group <id_group> -type <event_type> [-agent <id_agent>] [-user <id_user>] [-status <status>] [-am <id_agent_module>] [-alert <id_alert_am>] [-criticity <criticity>] [-comment <user_comment>] [-tag <tags>] [-source <source>] [-extra <id_extra>] [-c_instructions <critical_instructions>] [-w_instructions <warning_instructions>] [-u_instructions <unknown_instructions>] [-owner <owner_user>] \n\n";
|
print "CREATE EVENT:\n\n";
|
||||||
|
print "Usage: perl $0 -p <path to pandora console API> -u <credentials> -create_event -name <event_name> -group <id_group> -type <event_type> [-agent <id_agent>] [-user <id_user>] [-status <status>] [-am <id_agent_module>] [-alert <id_alert_am>] [-criticity <criticity>] [-comment <user_comment>] [-tag <tags>] [-source <source>] [-extra <id_extra>] [-c_instructions <critical_instructions>] [-w_instructions <warning_instructions>] [-u_instructions <unknown_instructions>] [-owner <owner_user>] \n\n";
|
||||||
print "Call syntax create_event: \n\t";
|
print "Call syntax create_event: \n\t";
|
||||||
print "<credentials>: Credentials of API and database separated by comma (required). In this order\n\t\t";
|
print "<credentials>: Credentials of API and database separated by comma (required). In this order\n\t\t";
|
||||||
print "<api_pass>,<db_user>,<db_pass>\n\n";
|
print "<api_pass>,<db_user>,<db_pass>\n\n";
|
||||||
|
|
||||||
print "EXAMPLE: \n\t";
|
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 "perl tool_api.pl -p http://localhost/pandora_console/include/api.php -u 1234,admin,pandora -create_event -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";
|
||||||
|
|
||||||
|
print "VALIDATE EVENT\n\n";
|
||||||
|
print "Usage: perl $0 -p <path to pandora console API> -u <credentials> -validate_event -id <id_event>\n\n";
|
||||||
|
print "Call syntax validate_event: \n\t";
|
||||||
|
print "<credentials>: Credentials of API and database separated by comma (required). In this order\n\t\t";
|
||||||
|
print "<api_pass>,<db_user>,<db_pass>\n\n";
|
||||||
|
|
||||||
|
print "EXAMPLE: \n\t";
|
||||||
|
print "perl tool_api.pl -p http://localhost/pandora_console/include/api.php -u 1234,admin,pandora -validate_event -id 234";
|
||||||
print "\n\n\n";
|
print "\n\n\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -44,10 +55,13 @@ sub tool_api_init () {
|
||||||
print "This program is Free Software, licensed under the terms of GPL License v2\n";
|
print "This program is Free Software, licensed under the terms of GPL License v2\n";
|
||||||
print "You can download latest versions and documentation at http://www.pandorafms.org\n\n";
|
print "You can download latest versions and documentation at http://www.pandorafms.org\n\n";
|
||||||
|
|
||||||
# Load config file from command line
|
if ($#ARGV < 0) {
|
||||||
help_screen () if ($#ARGV < 0);
|
help_screen();
|
||||||
|
}
|
||||||
|
|
||||||
help_screen () if (($ARGV[0] eq '-h') || ($ARGV[0] eq '-help'));
|
if (($ARGV[0] eq '-h') || ($ARGV[0] eq '-help')) {
|
||||||
|
help_screen();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +97,9 @@ sub tool_api_main () {
|
||||||
my $warning_instructions = '';
|
my $warning_instructions = '';
|
||||||
my $unknown_instructions = '';
|
my $unknown_instructions = '';
|
||||||
my $owner_user = '';
|
my $owner_user = '';
|
||||||
|
my $id_event;
|
||||||
|
my $option = $ARGV[4];
|
||||||
|
my $call_api;
|
||||||
|
|
||||||
#~ help or api path (required)
|
#~ help or api path (required)
|
||||||
if ($ARGV[0] eq '-h') {
|
if ($ARGV[0] eq '-h') {
|
||||||
|
@ -113,29 +130,30 @@ sub tool_api_main () {
|
||||||
help_screen ();
|
help_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($ARGV[4] eq '-create_event') {
|
||||||
#~ event name (required)
|
#~ event name (required)
|
||||||
if ($ARGV[4] ne '-name') {
|
if ($ARGV[5] ne '-name') {
|
||||||
print "[ERROR] Missing event name! Read help info:\n\n";
|
print "[ERROR] Missing event name! Read help info:\n\n";
|
||||||
help_screen ();
|
help_screen ();
|
||||||
} else {
|
} else {
|
||||||
$event_name = $ARGV[5];
|
$event_name = $ARGV[6];
|
||||||
}
|
}
|
||||||
|
|
||||||
#~ id group (required)
|
#~ id group (required)
|
||||||
if ($ARGV[6] ne '-group') {
|
if ($ARGV[7] ne '-group') {
|
||||||
print "[ERROR] Missing event group! Read help info:\n\n";
|
print "[ERROR] Missing event group! Read help info:\n\n";
|
||||||
help_screen ();
|
help_screen ();
|
||||||
} else {
|
} else {
|
||||||
$id_group = $ARGV[7];
|
$id_group = $ARGV[8];
|
||||||
$data_event = $id_group;
|
$data_event = $id_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
#~ id group (required)
|
#~ id group (required)
|
||||||
if ($ARGV[8] ne '-type') {
|
if ($ARGV[9] ne '-type') {
|
||||||
print "[ERROR] Missing event type! Read help info:\n\n";
|
print "[ERROR] Missing event type! Read help info:\n\n";
|
||||||
help_screen ();
|
help_screen ();
|
||||||
} else {
|
} else {
|
||||||
$event_type = $ARGV[9];
|
$event_type = $ARGV[10];
|
||||||
$data_event .= ",".$event_type;
|
$data_event .= ",".$event_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +206,20 @@ sub tool_api_main () {
|
||||||
}
|
}
|
||||||
|
|
||||||
$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;
|
$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;
|
||||||
|
$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;
|
||||||
|
|
||||||
|
} elsif ($ARGV[4] eq '-validate_event') {
|
||||||
|
#~ id event(required)
|
||||||
|
if ($ARGV[5] ne '-id') {
|
||||||
|
print "[ERROR] Missing id event! Read help info:\n\n";
|
||||||
|
help_screen ();
|
||||||
|
} else {
|
||||||
|
$id_event = $ARGV[6];
|
||||||
|
}
|
||||||
|
|
||||||
|
$call_api = $api_path.'?op=set&op2=validate_event_by_id&id='.$id_event.'&apipass='.$api_pass.'&user='.$db_user.'&pass='.$db_pass;
|
||||||
|
}
|
||||||
|
|
||||||
my @args = @ARGV;
|
my @args = @ARGV;
|
||||||
my $ltotal=$#args;
|
my $ltotal=$#args;
|
||||||
|
|
||||||
|
@ -197,15 +229,18 @@ sub tool_api_main () {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $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;
|
|
||||||
my $content = get($call_api);
|
my $content = get($call_api);
|
||||||
|
|
||||||
if ($content == undef) {
|
if ($option eq '-create_event') {
|
||||||
|
if ($content eq undef) {
|
||||||
print "[ERROR] Not respond or bad syntax. Read help info:\n\n";
|
print "[ERROR] Not respond or bad syntax. Read help info:\n\n";
|
||||||
help_screen();
|
help_screen();
|
||||||
} else {
|
} else {
|
||||||
print "Event ID: $content";
|
print "Event ID: $content";
|
||||||
}
|
}
|
||||||
|
} elsif ($option eq '-validate_event') {
|
||||||
|
print "[RESULT] $content";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\nExiting!\n\n";
|
print "\nExiting!\n\n";
|
||||||
|
|
Loading…
Reference in New Issue