2013-09-03 Miguel de Dios <miguel.dedios@artica.es>
* util/pandora_revent.pl: fixed the script, now runs fine the tags and set correclty the comment and owner user, and other fixes. Fixes: #2386 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8734 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
8394895dca
commit
2e5bdf9149
pandora_server
|
@ -1,3 +1,10 @@
|
||||||
|
2013-09-03 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
|
* util/pandora_revent.pl: fixed the script, now runs fine the tags
|
||||||
|
and set correclty the comment and owner user, and other fixes.
|
||||||
|
|
||||||
|
Fixes: #2386
|
||||||
|
|
||||||
2013-09-03 Ramon Novoa <rnovoa@artica.es>
|
2013-09-03 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* lib/PandoraFMS/Core.pm: Added support for tag phone information.
|
* lib/PandoraFMS/Core.pm: Added support for tag phone information.
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
###############################################################################
|
########################################################################
|
||||||
# Pandora FMS - Remote Event Tool (via WEB API)
|
# Pandora FMS - Remote Event Tool (via WEB API)
|
||||||
###############################################################################
|
########################################################################
|
||||||
# Copyright (c) 2013 Artica Soluciones Tecnologicas S.L
|
# Copyright (c) 2013 Artica Soluciones Tecnologicas S.L
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License version 2
|
# modify it under the terms of the GNU General Public License version 2
|
||||||
###############################################################################
|
########################################################################
|
||||||
|
|
||||||
# Includes list
|
# Includes list
|
||||||
use strict;
|
use strict;
|
||||||
|
@ -19,9 +19,9 @@ tool_api_init();
|
||||||
# Main
|
# Main
|
||||||
tool_api_main();
|
tool_api_main();
|
||||||
|
|
||||||
##############################################################################
|
########################################################################
|
||||||
# Print a help screen and exit.
|
# Print a help screen and exit.
|
||||||
##############################################################################
|
########################################################################
|
||||||
sub help_screen{
|
sub help_screen{
|
||||||
|
|
||||||
print "Options to create event:
|
print "Options to create event:
|
||||||
|
@ -29,64 +29,66 @@ sub help_screen{
|
||||||
\t$0 -p <path_to_consoleAPI> -create event <options>
|
\t$0 -p <path_to_consoleAPI> -create event <options>
|
||||||
|
|
||||||
Where options:\n
|
Where options:\n
|
||||||
-u <credentials>
|
-u <credentials>
|
||||||
-create_event
|
-create_event
|
||||||
-name <event_name> : Free text
|
-name <event_name> : Free text
|
||||||
-group <id_group> : Group ID (use 0 for 'all')
|
-group <id_group> : Group ID (use 0 for 'all')
|
||||||
-agent :Agent ID
|
-agent :Agent ID
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
|
|
||||||
[-status <status>] : 0 New, 1 Validated, 2 In process
|
[-status <status>] : 0 New, 1 Validated, 2 In process
|
||||||
[-user <id_user>] : User comment (use in combination with -comment option)
|
[-user <id_user>] : User comment (use in combination with -comment option)
|
||||||
[type <event_type>] : unknown, alert_fired, alert_recovered, alert_ceased
|
[type <event_type>] : unknown, alert_fired, alert_recovered, alert_ceased
|
||||||
alert_manual_validation, system, error, new_agent
|
alert_manual_validation, system, error, new_agent
|
||||||
configuration_change, going_unknown, going_down_critical,
|
configuration_change, going_unknown, going_down_critical,
|
||||||
going_down_warning, going_up_normal
|
going_down_warning, going_up_normal
|
||||||
[-criticity <criticity>] : 0 Maintance, 1 Informative, 2 Normal,
|
[-criticity <criticity>] : 0 Maintance, 1 Informative, 2 Normal,
|
||||||
3 Warning, 4 Crit, 5 Minor, 6 Major
|
3 Warning, 4 Crit, 5 Minor, 6 Major
|
||||||
[-am <id_agent_module>] : ID Agent Module linked to event
|
[-am <id_agent_module>] : ID Agent Module linked to event
|
||||||
[-alert <id_alert_am>] : ID Alert Module linked to event
|
[-alert <id_alert_am>] : ID Alert Module linked to event
|
||||||
[-c_instructions <critical_instructions>]
|
[-c_instructions <critical_instructions>]
|
||||||
[-w_instructions <warning_instructions>]
|
[-w_instructions <warning_instructions>]
|
||||||
[-u_instructions <unknown_instructions>]
|
[-u_instructions <unknown_instructions>]
|
||||||
[-source <source>] : (By default 'Pandora')
|
[-user_comment <comment>]
|
||||||
[-tag <tags>] : Tag (must exist in the system to be imported)";
|
[-owner_user <user for the event>]
|
||||||
|
[-source <source>] : (By default 'Pandora')
|
||||||
|
[-tag <tags>] : Tag (must exist in the system to be imported)";
|
||||||
|
|
||||||
print "Credential/API syntax: \n\n\t";
|
print "Credential/API syntax: \n\n\t";
|
||||||
print "<credentials>: API credentials separated by comma: <api_pass>,<user>,<pass>\n\n";
|
print "<credentials>: API credentials separated by comma: <api_pass>,<user>,<pass>\n\n";
|
||||||
|
|
||||||
print "Example of event generation:\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 \
|
#~ 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-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-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-source \"Commandline\" -extra 3 -c_instructions \"Critical instructions\" \
|
||||||
#~ \t-w_instructions \"Warning instructions\" -u_instructions \"Unknown instructions\" -owner \"other\" ";
|
#~ \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 \
|
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-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-criticity 3 -am 0 -alert 9 -c_instructions \"Critical instructions\" -w_instructions \"Warning instructions\" \
|
||||||
\t-u_instructions \"Unknown instructions\" -source \"Commandline\" -tag \"Tags\"";
|
\t-u_instructions \"Unknown instructions\" -source \"Commandline\" -tag \"Tags\"";
|
||||||
|
|
||||||
print "\n\nOptions to validate event: \n\n\t";
|
print "\n\nOptions to validate event: \n\n\t";
|
||||||
print "$0 -p <path_to_consoleAPI> -u <credentials> -validate_event <options> -id <id_event>\n\n";
|
print "$0 -p <path_to_consoleAPI> -u <credentials> -validate_event <options> -id <id_event>\n\n";
|
||||||
print "Sample of event validation: \n\n\t";
|
print "Sample of event validation: \n\n\t";
|
||||||
|
|
||||||
print "$0 -p http://localhost/pandora/include/api.php -u pot12,admin,pandora -validate_event -id 234";
|
print "$0 -p http://localhost/pandora/include/api.php -u pot12,admin,pandora -validate_event -id 234";
|
||||||
print "\n\n\n";
|
print "\n\n\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Init screen
|
# Init screen
|
||||||
##############################################################################
|
##############################################################################
|
||||||
sub tool_api_init () {
|
sub tool_api_init () {
|
||||||
|
|
||||||
print "\nPandora FMS Remote Event Tool Copyright (c) 2013 Artica ST\n";
|
print "\nPandora FMS Remote Event Tool Copyright (c) 2013 Artica ST\n";
|
||||||
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";
|
||||||
|
|
||||||
if ($#ARGV < 0) {
|
if ($#ARGV < 0) {
|
||||||
help_screen();
|
help_screen();
|
||||||
}
|
}
|
||||||
|
@ -94,14 +96,14 @@ sub tool_api_init () {
|
||||||
if (($ARGV[0] eq '-h') || ($ARGV[0] eq '-help')) {
|
if (($ARGV[0] eq '-h') || ($ARGV[0] eq '-help')) {
|
||||||
help_screen();
|
help_screen();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
########################################################################
|
||||||
###############################################################################
|
########################################################################
|
||||||
# MAIN
|
# MAIN
|
||||||
###############################################################################
|
########################################################################
|
||||||
###############################################################################
|
########################################################################
|
||||||
|
|
||||||
sub tool_api_main () {
|
sub tool_api_main () {
|
||||||
|
|
||||||
|
@ -134,15 +136,17 @@ sub tool_api_main () {
|
||||||
my $id_event;
|
my $id_event;
|
||||||
my $option = $ARGV[4];
|
my $option = $ARGV[4];
|
||||||
my $call_api;
|
my $call_api;
|
||||||
|
|
||||||
#~ help or api path (required)
|
#~ help or api path (required)
|
||||||
if ($ARGV[0] eq '-h') {
|
if ($ARGV[0] eq '-h') {
|
||||||
print "HELP!\n";
|
print "HELP!\n";
|
||||||
help_screen();
|
help_screen();
|
||||||
} elsif ($ARGV[0] ne '-p') {
|
}
|
||||||
|
elsif ($ARGV[0] ne '-p') {
|
||||||
print "[ERROR] Missing API path! Read help info:\n\n";
|
print "[ERROR] Missing API path! Read help info:\n\n";
|
||||||
help_screen ();
|
help_screen ();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$api_path = $ARGV[1];
|
$api_path = $ARGV[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,108 +158,130 @@ sub tool_api_main () {
|
||||||
if ($#db_info < 2) {
|
if ($#db_info < 2) {
|
||||||
print "[ERROR] Invalid database credentials! Read help info:\n\n";
|
print "[ERROR] Invalid database credentials! Read help info:\n\n";
|
||||||
help_screen();
|
help_screen();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$api_pass = $db_info[0];
|
$api_pass = $db_info[0];
|
||||||
$db_user = $db_info[1];
|
$db_user = $db_info[1];
|
||||||
$db_pass = $db_info[2];
|
$db_pass = $db_info[2];
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
print "[ERROR] Missing database credentials! Read help info:\n\n";
|
print "[ERROR] Missing database credentials! Read help info:\n\n";
|
||||||
help_screen ();
|
help_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ARGV[4] eq '-create_event') {
|
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 = $ARGV[6];
|
|
||||||
$data_event = $event_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
#~ 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];
|
|
||||||
#~ $data_event = $id_group;
|
|
||||||
$data_event .= "|".$id_group;
|
|
||||||
}
|
|
||||||
|
|
||||||
#~ id agent (required)
|
|
||||||
if ($ARGV[9] ne '-agent') {
|
|
||||||
print "[ERROR] Missing id agent! Read help info:\n\n";
|
|
||||||
help_screen ();
|
|
||||||
} else {
|
|
||||||
$id_agent = $ARGV[10];
|
|
||||||
$data_event .= "|".$id_agent;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
foreach (@ARGV) {
|
foreach (@ARGV) {
|
||||||
my $line = $_;
|
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') {
|
if ($line eq '-type') {
|
||||||
$event_type = $ARGV[$i+1];
|
$event_type = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-agent_name') {
|
if ($line eq '-agent_name') {
|
||||||
$agent_name = $ARGV[$i+1];
|
$agent_name = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-user') {
|
if ($line eq '-user') {
|
||||||
$id_user = $ARGV[$i+1];
|
$id_user = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-status') {
|
if ($line eq '-status') {
|
||||||
$status = $ARGV[$i+1];
|
$status = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-am') {
|
if ($line eq '-am') {
|
||||||
$id_agent_module = $ARGV[$i+1];
|
$id_agent_module = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-module_name') {
|
if ($line eq '-module_name') {
|
||||||
$module_name = $ARGV[$i+1];
|
$module_name = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-alert') {
|
if ($line eq '-alert') {
|
||||||
$id_alert_am = $ARGV[$i+1];
|
$id_alert_am = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-criticity') {
|
if ($line eq '-criticity') {
|
||||||
$criticity = $ARGV[$i+1];
|
$criticity = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
#~ if ($line eq '-comment') {
|
|
||||||
#~ $user_comment = $ARGV[$i+1];
|
|
||||||
#~ }
|
|
||||||
if ($line eq '-tag') {
|
if ($line eq '-tag') {
|
||||||
$tags = $ARGV[$i+1];
|
$tags = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-source') {
|
if ($line eq '-source') {
|
||||||
$source = $ARGV[$i+1];
|
$source = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
#~ if ($line eq '-extra') {
|
|
||||||
#~ $id_extra = $ARGV[$i+1];
|
|
||||||
#~ }
|
|
||||||
if ($line eq '-c_instructions') {
|
if ($line eq '-c_instructions') {
|
||||||
$critical_instructions = $ARGV[$i+1];
|
$critical_instructions = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-w_instructions') {
|
if ($line eq '-w_instructions') {
|
||||||
$warning_instructions = $ARGV[$i+1];
|
$warning_instructions = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
if ($line eq '-u_instructions') {
|
if ($line eq '-u_instructions') {
|
||||||
$unknown_instructions = $ARGV[$i+1];
|
$unknown_instructions = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
#~ if ($line eq '-owner') {
|
if ($line eq '-user_comment') {
|
||||||
#~ $owner_user = $ARGV[$i+1];
|
$user_comment = $ARGV[$i + 1];
|
||||||
#~ }
|
}
|
||||||
|
if ($line eq '-owner_user') {
|
||||||
|
$owner_user = $ARGV[$i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data_event .= "|".$status."|".$id_user."|".$event_type."|".$criticity."|".$id_agent_module."|".$id_alert_am."|".$critical_instructions."|".$warning_instructions."|".$unknown_instructions."|".$source.",".$tags;
|
if ($event_name eq "") {
|
||||||
$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;
|
print "[ERROR] Missing id agent! Read help info:\n\n";
|
||||||
|
help_screen ();
|
||||||
} elsif ($ARGV[4] eq '-validate_event') {
|
}
|
||||||
#~ id event(required)
|
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 .
|
||||||
|
"|" . $criticity .
|
||||||
|
"|" . $id_agent_module .
|
||||||
|
"|" . $id_alert_am .
|
||||||
|
"|" . $critical_instructions .
|
||||||
|
"|" . $warning_instructions .
|
||||||
|
"|" . $unknown_instructions .
|
||||||
|
"|" . $user_comment .
|
||||||
|
"|" . $owner_user .
|
||||||
|
"|" . $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)
|
||||||
if ($ARGV[5] ne '-id') {
|
if ($ARGV[5] ne '-id') {
|
||||||
print "[ERROR] Missing id event! Read help info:\n\n";
|
print "[ERROR] Missing id event! Read help info:\n\n";
|
||||||
help_screen ();
|
help_screen ();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$id_event = $ARGV[6];
|
$id_event = $ARGV[6];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,29 +289,37 @@ sub tool_api_main () {
|
||||||
}
|
}
|
||||||
|
|
||||||
my @args = @ARGV;
|
my @args = @ARGV;
|
||||||
my $ltotal=$#args;
|
my $ltotal=$#args;
|
||||||
|
|
||||||
if ($ltotal < 0) {
|
if ($ltotal < 0) {
|
||||||
print "[ERROR] No valid arguments. Read help info:\n\n";
|
print "[ERROR] No valid arguments. Read help info:\n\n";
|
||||||
help_screen ();
|
help_screen ();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#-----------DEBUG----------------------------
|
||||||
|
#print($call_api . "\n\n\n");
|
||||||
|
|
||||||
my $content = get($call_api);
|
my $content = get($call_api);
|
||||||
|
|
||||||
|
#-----------DEBUG----------------------------
|
||||||
|
#print($content . "\n\n\n");
|
||||||
|
|
||||||
if ($option eq '-create_event') {
|
if ($option eq '-create_event') {
|
||||||
if ($content eq undef) {
|
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') {
|
}
|
||||||
|
elsif ($option eq '-validate_event') {
|
||||||
print "[RESULT] $content";
|
print "[RESULT] $content";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\nExiting!\n\n";
|
print "\nExiting!\n\n";
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue