Modified help to describe the real plugins performance.

Deleted params not used.
pandora_revent and pandora_revent_create are the same except for validate option
This commit is contained in:
fermin831 2015-10-02 11:49:35 +02:00
parent 4525769ffc
commit 617f36bec9
2 changed files with 131 additions and 161 deletions

View File

@ -26,52 +26,47 @@ sub help_screen{
print "Options to create event: print "Options to create event:
\t$0 -p <path_to_consoleAPI> -create event <options> \t$0 -p <path_to_consoleAPI> -u <credentials> -create_event <options>
Where options:\n Where options:\n
-u <credentials> -u <credentials> : API credentials separated by comma: <api_pass>,<user>,<pass>
-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, [-severity <severity>] : 0 Maintance,
3 Warning, 4 Crit, 5 Minor, 6 Major 1 Informative,
2 Normal,
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>]
[-user_comment <comment>] [-user_comment <comment>]
[-owner_user <user for the event>] [-owner_user <owner event>] : Use the login name, not the descriptive
[-source <source>] : (By default 'Pandora') [-source <source>] : (By default 'Pandora')
[-tag <tags>] : Tag (must exist in the system to be imported)"; [-tag <tags>] : Tag (must exist in the system to be imported)\n\n";
print "Credential/API syntax: \n\n\t";
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 \
#~ \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 \ 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-severity 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\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";
@ -118,17 +113,14 @@ sub tool_api_main () {
my $db_pass; my $db_pass;
my @db_info; my @db_info;
my $id_agent; my $id_agent;
my $agent_name;
my $id_user = ''; my $id_user = '';
my $status = ''; my $status = '';
my $id_agent_module = ''; my $id_agent_module = '';
my $module_name = '';
my $id_alert_am = ''; my $id_alert_am = '';
my $criticity = ''; my $severity = '';
my $user_comment = ''; my $user_comment = '';
my $tags = ''; my $tags = '';
my $source = ''; my $source = '';
my $id_extra = '';
my $critical_instructions = ''; my $critical_instructions = '';
my $warning_instructions = ''; my $warning_instructions = '';
my $unknown_instructions = ''; my $unknown_instructions = '';
@ -190,9 +182,6 @@ sub tool_api_main () {
if ($line eq '-type') { if ($line eq '-type') {
$event_type = $ARGV[$i + 1]; $event_type = $ARGV[$i + 1];
} }
if ($line eq '-agent_name') {
$agent_name = $ARGV[$i + 1];
}
if ($line eq '-user') { if ($line eq '-user') {
$id_user = $ARGV[$i + 1]; $id_user = $ARGV[$i + 1];
} }
@ -202,14 +191,11 @@ sub tool_api_main () {
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') {
$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 '-severity') {
$criticity = $ARGV[$i + 1]; $severity = $ARGV[$i + 1];
} }
if ($line eq '-tag') { if ($line eq '-tag') {
$tags = $ARGV[$i + 1]; $tags = $ARGV[$i + 1];
@ -255,7 +241,7 @@ sub tool_api_main () {
"|" . $status . "|" . $status .
"|" . $id_user . "|" . $id_user .
"|" . $event_type . "|" . $event_type .
"|" . $criticity . "|" . $severity .
"|" . $id_agent_module . "|" . $id_agent_module .
"|" . $id_alert_am . "|" . $id_alert_am .
"|" . $critical_instructions . "|" . $critical_instructions .
@ -265,6 +251,7 @@ sub tool_api_main () {
"|" . $owner_user . "|" . $owner_user .
"|" . $source . "|" . $source .
"|" . $tags; "|" . $tags;
$call_api = $api_path . '?' . $call_api = $api_path . '?' .
'op=set&' . 'op=set&' .
'op2=create_event&' . 'op2=create_event&' .

233
pandora_server/util/pandora_revent_create.pl Normal file → Executable file
View File

@ -12,7 +12,6 @@
# Includes list # Includes list
use strict; use strict;
use LWP::Simple; use LWP::Simple;
use URI::Escape;
# Init # Init
tool_api_init(); tool_api_init();
@ -23,62 +22,56 @@ 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:
\t$0 -p <path_to_consoleAPI> -create event <options> print "Options to create event:
\t$0 -p <path_to_consoleAPI> -u <credentials> -create_event <options>
Where options:\n Where options:\n
-u <credentials> -u <credentials> : API credentials separated by comma: <api_pass>,<user>,<pass>
-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
-type <event_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
Optional parameters: Optional parameters:
[-agent <id_agent>] : Agent ID [-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)
[-status <status>] : 0 New, 1 Validated, 2 In process [-type <event_type>] : unknown, alert_fired, alert_recovered, alert_ceased
[-am <id_agent_module>] : ID Agent Module linked to event alert_manual_validation, system, error, new_agent
[-alert <id_alert_am>] : ID Alert Module linked to event configuration_change, going_unknown, going_down_critical,
[-criticity <criticity>] : 0 Maintance, 1 Informative, 2 Normal, going_down_warning, going_up_normal
3 Warning, 4 Crit, 5 Minor, 6 Major [-severity <severity>] : 0 Maintance,
1 Informative,
[-comment <user_comment>] : Free text for comment 2 Normal,
[-tag <tags>] : Tag (must exist in the system to be imported) 3 Warning,
[-source <source>] : (By default 'Pandora') 4 Crit,
5 Minor,
6 Major
[-am <id_agent_module>] : ID Agent 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>]
[-owner <owner_user>] : Use the login name, not the descriptive [-user_comment <comment>]
[-owner_user <owner event>] : Use the login name, not the descriptive
[-source <source>] : (By default 'Pandora')
[-tag <tags>] : Tag (must exist in the system to be imported)\n\n";
print "Example of event generation:\n\n";
Credential/API syntax: 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\" \
<credentials> : API credentials separated by comma: <api_pass>,<user>,<pass> \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; 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";
@ -95,9 +88,6 @@ sub tool_api_init () {
} }
######################################################################## ########################################################################
######################################################################## ########################################################################
# MAIN # MAIN
@ -117,17 +107,14 @@ sub tool_api_main () {
my $db_pass; my $db_pass;
my @db_info; my @db_info;
my $id_agent; my $id_agent;
my $agent_name;
my $id_user = ''; my $id_user = '';
my $status = ''; my $status = '';
my $id_agent_module = ''; my $id_agent_module = '';
my $module_name = '';
my $id_alert_am = ''; my $id_alert_am = '';
my $criticity = ''; my $severity = '';
my $user_comment = ''; my $user_comment = '';
my $tags = ''; my $tags = '';
my $source = ''; my $source = '';
my $id_extra = '';
my $critical_instructions = ''; my $critical_instructions = '';
my $warning_instructions = ''; my $warning_instructions = '';
my $unknown_instructions = ''; my $unknown_instructions = '';
@ -170,39 +157,25 @@ sub tool_api_main () {
} }
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 = 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; my $i = 0;
foreach (@ARGV) { foreach (@ARGV) {
my $line = $_; my $line = $_;
#-----------DEBUG----------------------------
#print("i " . $i . " line " . $line . "\n");
if ($line eq '-agent') { if ($line eq '-agent') {
$id_agent = $ARGV[$i + 1]; $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') { if ($line eq '-user') {
$id_user = $ARGV[$i + 1]; $id_user = $ARGV[$i + 1];
} }
@ -215,89 +188,99 @@ sub tool_api_main () {
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 '-severity') {
$criticity = $ARGV[$i + 1]; $severity = $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 = uri_escape($ARGV[$i + 1]); $source = $ARGV[$i + 1];
} }
if ($line eq '-c_instructions') { if ($line eq '-c_instructions') {
$critical_instructions = uri_escape($ARGV[$i + 1]); $critical_instructions = $ARGV[$i + 1];
} }
if ($line eq '-w_instructions') { if ($line eq '-w_instructions') {
$warning_instructions = uri_escape($ARGV[$i + 1]); $warning_instructions = $ARGV[$i + 1];
} }
if ($line eq '-u_instructions') { if ($line eq '-u_instructions') {
$unknown_instructions = uri_escape($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 = $event_name . "|" . if ($event_name eq "") {
$id_group . "|" . print "[ERROR] Missing id agent! Read help info:\n\n";
$id_agent . "|" . help_screen ();
$status . "|" . }
$id_user . "|" . if ($id_group eq "") {
$event_type . "|" . print "[ERROR] Missing event group! Read help info:\n\n";
$criticity . "|" . help_screen ();
$id_agent_module . "|" . }
$id_alert_am . "|" . if ($id_agent eq "") {
$critical_instructions . "|" . print "[ERROR] Missing id agent! Read help info:\n\n";
$warning_instructions . "|" . help_screen ();
$unknown_instructions . "|" . }
$user_comment . "|" .
$owner_user . "|" . $data_event = $event_name .
$source . "|" . "|" . $id_group .
$tags; "|" . $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;
$call_api = $api_path . '?' . $call_api = $api_path . '?' .
'op=set&' . 'op=set&' .
'op2=create_event&' . 'op2=create_event&' .
'id=' . $event_name . '&' . 'other=' . $data_event .'&' .
'other=' . $data_event . '&' .
'other_mode=url_encode_separator_|&' . 'other_mode=url_encode_separator_|&' .
'apipass=' . $api_pass . '&' . 'apipass=' . $api_pass . '&' .
'user=' . $db_user . '&' . 'user=' . $db_user . '&' .
'pass=' . $db_pass; 'pass=' . $db_pass;
#DEBUG TRACE#
#print "$call_api\n";
} }
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 {
my $content = get($call_api); #-----------DEBUG----------------------------
print("\n\n"); #print($call_api . "\n\n\n");
print($call_api);
print("\n\n");
if ($option eq '-create_event') { my $content = get($call_api);
if ($content eq undef) {
print "[ERROR] Not respond or bad syntax. Read help info:\n\n"; #-----------DEBUG----------------------------
help_screen(); #print($content . "\n\n\n");
}
else { if ($content eq undef) {
print "Event ID: $content"; print "[ERROR] Not respond or bad syntax. Read help info:\n\n";
} help_screen();
} }
else {
print "Event ID: $content";
}
} }
print "\nExiting!\n\n"; print "\nExiting!\n\n";