fixed errors in pandora revent
This commit is contained in:
parent
1b262808f2
commit
d3a0c4b52b
|
@ -1,17 +1,20 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
###############################################################################
|
||||
########################################################################
|
||||
# Pandora FMS - Remote Event Tool (via WEB API)
|
||||
###############################################################################
|
||||
########################################################################
|
||||
# Copyright (c) 2013 Artica Soluciones Tecnologicas S.L
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License version 2
|
||||
###############################################################################
|
||||
########################################################################
|
||||
|
||||
# Includes list
|
||||
use strict;
|
||||
use LWP::Simple;
|
||||
use MIME::Base64;
|
||||
use lib '/usr/lib/perl5';
|
||||
use PandoraFMS::Tools;
|
||||
|
||||
# Init
|
||||
tool_api_init();
|
||||
|
@ -19,72 +22,76 @@ tool_api_init();
|
|||
# Main
|
||||
tool_api_main();
|
||||
|
||||
##############################################################################
|
||||
########################################################################
|
||||
# Print a help screen and exit.
|
||||
##############################################################################
|
||||
########################################################################
|
||||
sub help_screen{
|
||||
|
||||
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
|
||||
-u <credentials>
|
||||
-create_event
|
||||
-name <event_name> : Free text
|
||||
-group <id_group> : Group ID (use 0 for 'all')
|
||||
-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
|
||||
-u <credentials> : API credentials separated by comma: <api_pass>,<user>,<pass>
|
||||
-name <event_name> : Free text
|
||||
-group <id_group> : Group ID (use 0 for 'all')
|
||||
-agent : Agent ID
|
||||
|
||||
Optional parameters:
|
||||
|
||||
[-agent <id_agent>] : Agent ID
|
||||
[-user <id_user>] : User comment (use in combination with -comment option)
|
||||
[-status <status>] : 0 New, 1 Validated, 2 In process
|
||||
[-am <id_agent_module>] : ID Agent Module linked to event
|
||||
[-alert <id_alert_am>] : ID Alert Module linked to event
|
||||
[-criticity <criticity>] : 0 Maintance, 1 Informative, 2 Normal,
|
||||
3 Warning, 4 Crit, 5 Minor, 6 Major
|
||||
[-status <status>] : 0 New, 1 Validated, 2 In process
|
||||
[-user <id_user>] : User comment (use in combination with -comment option)
|
||||
[-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
|
||||
[-severity <severity>] : 0 Maintance,
|
||||
1 Informative,
|
||||
2 Normal,
|
||||
3 Warning,
|
||||
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>]
|
||||
[-w_instructions <warning_instructions>]
|
||||
[-u_instructions <unknown_instructions>]
|
||||
[-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)
|
||||
[-custom_data <custom_data>]: Custom data has to be in JSON format. Example: -custom_data \'{\"test1\" : \"t1\", \"test2\": \"2\"}\'
|
||||
[-id_extra <id extra>] : Id extra
|
||||
[-agent_name <Agent name>] : Agent name, Not to be confused with the alias.
|
||||
[-force_create_agent<0 o 1>]: Force the creation of agent through an event this will create when it is 1.
|
||||
[-server_id <server_id>] : The pandora node server_id\n\n";
|
||||
|
||||
[-comment <user_comment>] : Free text for comment
|
||||
[-tag <tags>] : Tag (must exist in the system to be imported)
|
||||
[-source <source>] : (By default 'Pandora')
|
||||
[-c_instructions <critical_instructions>]
|
||||
[-w_instructions <warning_instructions>]
|
||||
[-u_instructions <unknown_instructions>]
|
||||
[-owner <owner_user>] : Use the login name, not the descriptive \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 "\t$0 -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\" -c_instructions \"Critical instructions\" \
|
||||
\t-w_instructions \"Warning instructions\" -u_instructions \"Unknown instructions\" -owner \"other\" ";
|
||||
|
||||
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 "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 "\n\n\n";
|
||||
exit;
|
||||
|
||||
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\" -id_extra \"id extra\" -agent_name \"agent name\" -source \"Commandline\" -tag \"Tags\"";
|
||||
|
||||
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 "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 "\n\n\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
# Init screen
|
||||
##############################################################################
|
||||
sub tool_api_init () {
|
||||
|
||||
print "\nPandora FMS Remote Event Tool Copyright (c) 2015 Artica ST\n";
|
||||
|
||||
print "\nPandora FMS Remote Event Tool Copyright (c) 2013-2015 Artica ST\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";
|
||||
|
||||
|
||||
if ($#ARGV < 0) {
|
||||
help_screen();
|
||||
}
|
||||
|
@ -92,14 +99,14 @@ sub tool_api_init () {
|
|||
if (($ARGV[0] eq '-h') || ($ARGV[0] eq '-help')) {
|
||||
help_screen();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
########################################################################
|
||||
########################################################################
|
||||
# MAIN
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
########################################################################
|
||||
########################################################################
|
||||
|
||||
sub tool_api_main () {
|
||||
|
||||
|
@ -114,33 +121,37 @@ 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 = '';
|
||||
my $id_extra = '';
|
||||
my $agent_name = '';
|
||||
my $force_create_agent = 0;
|
||||
my $owner_user = '';
|
||||
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') {
|
||||
print "HELP!\n";
|
||||
help_screen();
|
||||
} elsif ($ARGV[0] ne '-p') {
|
||||
}
|
||||
elsif ($ARGV[0] ne '-p') {
|
||||
print "[ERROR] Missing API path! Read help info:\n\n";
|
||||
help_screen ();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$api_path = $ARGV[1];
|
||||
}
|
||||
|
||||
|
@ -152,105 +163,149 @@ sub tool_api_main () {
|
|||
if ($#db_info < 2) {
|
||||
print "[ERROR] Invalid database credentials! Read help info:\n\n";
|
||||
help_screen();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$api_pass = $db_info[0];
|
||||
$db_user = $db_info[1];
|
||||
$db_pass = $db_info[2];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
print "[ERROR] Missing database credentials! Read help info:\n\n";
|
||||
help_screen ();
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
#~ 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];
|
||||
}
|
||||
|
||||
# -agent_name, -module_name and -extra are not supported by api. Maybe in the future
|
||||
my $i = 0;
|
||||
foreach (@ARGV) {
|
||||
my $line = $_;
|
||||
|
||||
#-----------DEBUG----------------------------
|
||||
#print("i " . $i . " line " . $line . "\n");
|
||||
|
||||
if ($line eq '-agent') {
|
||||
$id_agent = $ARGV[$i+1];
|
||||
$id_agent = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-agent_name') {
|
||||
$agent_name = $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];
|
||||
$id_user = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-status') {
|
||||
$status = $ARGV[$i+1];
|
||||
$status = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-am') {
|
||||
$id_agent_module = $ARGV[$i+1];
|
||||
}
|
||||
if ($line eq '-module_name') {
|
||||
$module_name = $ARGV[$i+1];
|
||||
$id_agent_module = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-alert') {
|
||||
$id_alert_am = $ARGV[$i+1];
|
||||
$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 = $ARGV[$i+1];
|
||||
}
|
||||
if ($line eq '-extra') {
|
||||
$id_extra = $ARGV[$i+1];
|
||||
$source = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-c_instructions') {
|
||||
$critical_instructions = $ARGV[$i+1];
|
||||
$critical_instructions = $ARGV[$i + 1];
|
||||
$critical_instructions = uri_encode($critical_instructions);
|
||||
}
|
||||
if ($line eq '-w_instructions') {
|
||||
$warning_instructions = $ARGV[$i+1];
|
||||
$warning_instructions = $ARGV[$i + 1];
|
||||
$warning_instructions = uri_encode($warning_instructions);
|
||||
}
|
||||
if ($line eq '-u_instructions') {
|
||||
$unknown_instructions = $ARGV[$i+1];
|
||||
$unknown_instructions = $ARGV[$i + 1];
|
||||
$unknown_instructions = uri_encode($unknown_instructions);
|
||||
}
|
||||
if ($line eq '-owner') {
|
||||
$owner_user = $ARGV[$i+1];
|
||||
if ($line eq '-id_extra') {
|
||||
$id_extra = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-agent_name') {
|
||||
$agent_name = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-force_create_agent') {
|
||||
$force_create_agent = $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];
|
||||
$custom_data = encode_base64($custom_data, '');
|
||||
}
|
||||
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.",";
|
||||
$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;
|
||||
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 "" && $agent_name eq "") {
|
||||
print "[ERROR] Missing id agent! and agent_name 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 .
|
||||
"|" . $id_extra .
|
||||
"|" . $agent_name .
|
||||
"|" . $force_create_agent;
|
||||
|
||||
} elsif ($ARGV[4] eq '-validate_event') {
|
||||
#~ id event(required)
|
||||
$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') {
|
||||
print "[ERROR] Missing id event! Read help info:\n\n";
|
||||
help_screen ();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$id_event = $ARGV[6];
|
||||
}
|
||||
|
||||
|
@ -258,8 +313,8 @@ sub tool_api_main () {
|
|||
}
|
||||
|
||||
my @args = @ARGV;
|
||||
my $ltotal=$#args;
|
||||
|
||||
my $ltotal=$#args;
|
||||
|
||||
if ($ltotal < 0) {
|
||||
print "[ERROR] No valid arguments. Read help info:\n\n";
|
||||
help_screen ();
|
||||
|
@ -272,15 +327,17 @@ sub tool_api_main () {
|
|||
if ($content eq undef) {
|
||||
print "[ERROR] Not respond or bad syntax. Read help info:\n\n";
|
||||
help_screen();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
print "Event ID: $content";
|
||||
}
|
||||
} elsif ($option eq '-validate_event') {
|
||||
}
|
||||
elsif ($option eq '-validate_event') {
|
||||
print "[RESULT] $content";
|
||||
}
|
||||
}
|
||||
|
||||
print "\nExiting!\n\n";
|
||||
|
||||
exit;
|
||||
|
||||
print "\nExiting!\n\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -8867,12 +8867,47 @@ function api_set_create_event($id, $trash1, $other, $returnType) {
|
|||
returnError('error_parameter', 'Group ID required.');
|
||||
return;
|
||||
}
|
||||
|
||||
$error_msg ='';
|
||||
if ($other['data'][2] != '') {
|
||||
$values['id_agente'] = $other['data'][2];
|
||||
$id_agent_exist = db_get_value('id_agente', 'tagente', 'id_agente', $other['data'][2]);
|
||||
if($id_agent_exist){
|
||||
$values['id_agente'] = $other['data'][2];
|
||||
}
|
||||
else{
|
||||
$error_msg = 'id_not_exist';
|
||||
}
|
||||
}
|
||||
else {
|
||||
returnError('error_parameter', 'Agent ID required.');
|
||||
if($other['data'][19] != ''){
|
||||
$values['id_agente'] = db_get_value('id_agente', 'tagente', 'nombre', $other['data'][19]);
|
||||
if(!$values['id_agente']){
|
||||
if($other['data'][20] == 1){
|
||||
$values['id_agente'] = db_process_sql_insert ('tagente',
|
||||
array ( 'nombre' => $other['data'][19],
|
||||
'id_grupo' => $other['data'][1],
|
||||
'alias' => $other['data'][19] )
|
||||
);
|
||||
}
|
||||
else{
|
||||
$error_msg = 'name_not_exist';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error_msg = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
if($error_msg != ''){
|
||||
if($error_msg == 'id_not_exist'){
|
||||
returnError('error_parameter', 'Agent ID does not exist.');
|
||||
}
|
||||
elseif($error_msg == 'name_not_exist'){
|
||||
returnError('error_parameter', 'Agent Name does not exist.');
|
||||
}
|
||||
elseif($error_msg == 'none'){
|
||||
returnError('error_parameter', 'Agent ID or name required.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8961,7 +8996,12 @@ function api_set_create_event($id, $trash1, $other, $returnType) {
|
|||
else {
|
||||
$values['server_id'] = 0;
|
||||
}
|
||||
|
||||
if ($other['data'][18] != '') {
|
||||
$values['id_extra'] = $other['data'][18];
|
||||
}
|
||||
else {
|
||||
$values['id_extra'] = '';
|
||||
}
|
||||
$return = events_create_event(
|
||||
$values['event'], $values['id_grupo'], $values['id_agente'],
|
||||
$values['status'], $values['id_usuario'],
|
||||
|
@ -8971,7 +9011,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) {
|
|||
$values['warning_instructions'],
|
||||
$values['unknown_instructions'], $values['source'],
|
||||
$values['tags'], $values['custom_data'],
|
||||
$values['server_id']);
|
||||
$values['server_id'], $values['id_extra']);
|
||||
|
||||
if ($other['data'][12] != '') { //user comments
|
||||
if ($return !== false) { //event successfully created
|
||||
|
|
|
@ -703,7 +703,7 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
|||
$id_user = "", $event_type = "unknown", $priority = 0,
|
||||
$id_agent_module = 0, $id_aam = 0, $critical_instructions = '',
|
||||
$warning_instructions = '', $unknown_instructions = '',
|
||||
$source="Pandora", $tags="", $custom_data="", $server_id = 0) {
|
||||
$source="Pandora", $tags="", $custom_data="", $server_id = 0, $id_extra ="") {
|
||||
|
||||
global $config;
|
||||
|
||||
|
@ -719,15 +719,15 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
|||
event_type, criticity, id_agentmodule, id_alert_am,
|
||||
critical_instructions, warning_instructions,
|
||||
unknown_instructions, source, tags, custom_data,
|
||||
server_id)
|
||||
server_id, id_extra)
|
||||
VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()),
|
||||
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s",
|
||||
"%s", "%s", %d)',
|
||||
"%s", "%s", %d, "%s")',
|
||||
$id_agent, $id_group, $event, $status, $id_user,
|
||||
$event_type, $priority, $id_agent_module, $id_aam,
|
||||
$critical_instructions, $warning_instructions,
|
||||
$unknown_instructions, $source, $tags, $custom_data,
|
||||
$server_id);
|
||||
$server_id, $id_extra);
|
||||
break;
|
||||
case "postgresql":
|
||||
$sql = sprintf ('
|
||||
|
@ -736,16 +736,16 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
|||
event_type, criticity, id_agentmodule, id_alert_am,
|
||||
critical_instructions, warning_instructions,
|
||||
unknown_instructions, source, tags, custom_data,
|
||||
server_id)
|
||||
server_id, id_extra)
|
||||
VALUES (%d, %d, "%s", NOW(), %d,
|
||||
ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s",
|
||||
"%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s",
|
||||
"%s", %d)',
|
||||
"%s", %d, "%s")',
|
||||
$id_agent, $id_group, $event, $status, $id_user,
|
||||
$event_type, $priority, $id_agent_module, $id_aam,
|
||||
$critical_instructions, $warning_instructions,
|
||||
$unknown_instructions, $source, $tags, $custom_data,
|
||||
$server_id);
|
||||
$server_id, $id_extra);
|
||||
break;
|
||||
case "oracle":
|
||||
$sql = sprintf ('
|
||||
|
@ -754,15 +754,15 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
|||
event_type, criticity, id_agentmodule, id_alert_am,
|
||||
critical_instructions, warning_instructions,
|
||||
unknown_instructions, source, tags, custom_data,
|
||||
server_id)
|
||||
server_id, id_extra)
|
||||
VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d, UNIX_TIMESTAMP,
|
||||
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s",
|
||||
"%s", "%s", %d)',
|
||||
"%s", "%s", %d, "%s")',
|
||||
$id_agent, $id_group, $event, $status, $id_user,
|
||||
$event_type, $priority, $id_agent_module, $id_aam,
|
||||
$critical_instructions, $warning_instructions,
|
||||
$unknown_instructions, $source, $tags, $custom_data,
|
||||
$server_id);
|
||||
$server_id, $id_extra);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -774,13 +774,13 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
|||
timestamp, estado, utimestamp, id_usuario,
|
||||
event_type, criticity, id_agentmodule, id_alert_am,
|
||||
critical_instructions, warning_instructions,
|
||||
unknown_instructions, source, tags, custom_data)
|
||||
unknown_instructions, source, tags, custom_data, id_extra)
|
||||
VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()),
|
||||
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
|
||||
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s", "%s")',
|
||||
$id_agent, $id_group, $event, $status, $id_user,
|
||||
$event_type, $priority, $id_agent_module, $id_aam,
|
||||
$critical_instructions, $warning_instructions,
|
||||
$unknown_instructions, $source, $tags, $custom_data);
|
||||
$unknown_instructions, $source, $tags, $custom_data, $id_extra);
|
||||
break;
|
||||
case "postgresql":
|
||||
$sql = sprintf ('
|
||||
|
@ -788,14 +788,14 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
|||
timestamp, estado, utimestamp, id_usuario,
|
||||
event_type, criticity, id_agentmodule, id_alert_am,
|
||||
critical_instructions, warning_instructions,
|
||||
unknown_instructions, source, tags, custom_data)
|
||||
unknown_instructions, source, tags, custom_data, id_extra)
|
||||
VALUES (%d, %d, "%s", NOW(), %d,
|
||||
ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s",
|
||||
"%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
|
||||
"%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s", "%s")',
|
||||
$id_agent, $id_group, $event, $status, $id_user,
|
||||
$event_type, $priority, $id_agent_module, $id_aam,
|
||||
$critical_instructions, $warning_instructions,
|
||||
$unknown_instructions, $source, $tags, $custom_data);
|
||||
$unknown_instructions, $source, $tags, $custom_data, $id_extra);
|
||||
break;
|
||||
case "oracle":
|
||||
$sql = sprintf ("
|
||||
|
@ -803,13 +803,13 @@ function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
|||
timestamp, estado, utimestamp, id_usuario,
|
||||
event_type, criticity, id_agentmodule, id_alert_am,
|
||||
critical_instructions, warning_instructions,
|
||||
unknown_instructions, source, tags, custom_data)
|
||||
unknown_instructions, source, tags, custom_data, id_extra)
|
||||
VALUES (%d, %d, '%s', CURRENT_TIMESTAMP, %d, UNIX_TIMESTAMP,
|
||||
'%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s')",
|
||||
'%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
|
||||
$id_agent, $id_group, $event, $status, $id_user,
|
||||
$event_type, $priority, $id_agent_module, $id_aam,
|
||||
$critical_instructions, $warning_instructions,
|
||||
$unknown_instructions, $source, $tags, $custom_data);
|
||||
$unknown_instructions, $source, $tags, $custom_data, $id_extra);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ our @EXPORT = qw(
|
|||
translate_obj
|
||||
valid_regex
|
||||
set_file_permissions
|
||||
uri_encode
|
||||
);
|
||||
|
||||
# ID of the different servers
|
||||
|
@ -1468,6 +1469,61 @@ sub is_metaconsole ($) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#######################
|
||||
# ENCODE
|
||||
#######################
|
||||
sub uri_encode {
|
||||
# Un-reserved characters
|
||||
my $unreserved_re = qr{ ([^a-zA-Z0-9\Q-_.~\E\%]) }x;
|
||||
my $enc_map = { ( map { chr($_) => sprintf( "%%%02X", $_ ) } ( 0 ... 255 ) ) };
|
||||
my $dec_map = { ( map { sprintf( "%02X", $_ ) => chr($_) } ( 0 ... 255 ) ) };
|
||||
|
||||
my ($data) = @_;
|
||||
|
||||
# Check for data
|
||||
# Allow to be '0'
|
||||
return unless defined $data;
|
||||
|
||||
# UTF-8 encode
|
||||
$data = Encode::encode( 'utf-8-strict', $data );
|
||||
|
||||
# Encode a literal '%'
|
||||
$data =~ s{(\%)(.*)}{uri_encode_literal_percent($1, $2, $enc_map, $dec_map)}gex;
|
||||
|
||||
# Percent Encode
|
||||
$data =~ s{$unreserved_re}{uri_encode_get_encoded_char($1, $enc_map)}gex;
|
||||
|
||||
# Done
|
||||
return $data;
|
||||
} ## end sub encode
|
||||
|
||||
#######################
|
||||
# INTERNAL
|
||||
#######################
|
||||
sub uri_encode_get_encoded_char($$) {
|
||||
my ( $char, $enc_map ) = @_;
|
||||
|
||||
return $enc_map->{$char} if exists $enc_map->{$char};
|
||||
return $char;
|
||||
} ## end sub uri_encode_get_encoded_char
|
||||
|
||||
sub uri_encode_literal_percent {
|
||||
my ( $char, $post, $enc_map, $dec_map ) = @_;
|
||||
|
||||
return uri_encode_get_encoded_char($char, $enc_map) if not defined $post;
|
||||
|
||||
my $return_char;
|
||||
if ( $post =~ m{^([a-fA-F0-9]{2})}x ) {
|
||||
if ( exists $dec_map->{$1} ) {
|
||||
$return_char = join( '', $char, $post );
|
||||
}
|
||||
} ## end if ( $post =~ m{^([a-fA-F0-9]{2})}x)
|
||||
|
||||
$return_char ||= join( '', uri_encode_get_encoded_char($char, $enc_map), $post );
|
||||
return $return_char;
|
||||
} ## end sub uri_encode_literal_percent
|
||||
|
||||
|
||||
# End of function declaration
|
||||
# End of defined Code
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
# Includes list
|
||||
use strict;
|
||||
use LWP::Simple;
|
||||
use MIME::Base64;
|
||||
use lib '/usr/lib/perl5';
|
||||
use PandoraFMS::Tools;
|
||||
|
||||
# Init
|
||||
tool_api_init();
|
||||
|
@ -32,17 +35,17 @@ Where options:\n
|
|||
-u <credentials> : API credentials separated by comma: <api_pass>,<user>,<pass>
|
||||
-name <event_name> : Free text
|
||||
-group <id_group> : Group ID (use 0 for 'all')
|
||||
-agent : Agent ID
|
||||
-agent : Agent ID
|
||||
|
||||
Optional parameters:
|
||||
|
||||
[-status <status>] : 0 New, 1 Validated, 2 In process
|
||||
[-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
|
||||
configuration_change, going_unknown, going_down_critical,
|
||||
going_down_warning, going_up_normal
|
||||
[-severity <severity>] : 0 Maintance,
|
||||
[-severity <severity>] : 0 Maintance,
|
||||
1 Informative,
|
||||
2 Normal,
|
||||
3 Warning,
|
||||
|
@ -58,7 +61,10 @@ Optional parameters:
|
|||
[-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)
|
||||
[-custom_data <custom_data>]: Custom data should be a base 64 encoded JSON document
|
||||
[-custom_data <custom_data>]: Custom data should be a base 64 encoded JSON document example -custom_data \'{\"test1\" : 1, \"test2\": 2}\'
|
||||
[-id_extra <id extra>] : Id extra
|
||||
[-agent_name <Agent name>] : Agent name, Not to be confused with the alias.
|
||||
[-force_create_agent<0 o 1>]: Force the creation of agent through an event this will create when it is 1.
|
||||
[-server_id <server_id>] : The pandora node server_id\n\n";
|
||||
|
||||
print "Example of event generation:\n\n";
|
||||
|
@ -66,7 +72,7 @@ Optional parameters:
|
|||
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\"";
|
||||
\t-u_instructions \"Unknown instructions\" -id_extra \"id extra\" -agent_name \"agent name\" -source \"Commandline\" -tag \"Tags\"";
|
||||
|
||||
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";
|
||||
|
@ -126,6 +132,9 @@ sub tool_api_main () {
|
|||
my $critical_instructions = '';
|
||||
my $warning_instructions = '';
|
||||
my $unknown_instructions = '';
|
||||
my $id_extra = '';
|
||||
my $agent_name = '';
|
||||
my $force_create_agent = 0;
|
||||
my $owner_user = '';
|
||||
my $id_event;
|
||||
my $option = $ARGV[4];
|
||||
|
@ -209,12 +218,24 @@ sub tool_api_main () {
|
|||
}
|
||||
if ($line eq '-c_instructions') {
|
||||
$critical_instructions = $ARGV[$i + 1];
|
||||
$critical_instructions = uri_encode($critical_instructions);
|
||||
}
|
||||
if ($line eq '-w_instructions') {
|
||||
$warning_instructions = $ARGV[$i + 1];
|
||||
$warning_instructions = uri_encode($warning_instructions);
|
||||
}
|
||||
if ($line eq '-u_instructions') {
|
||||
$unknown_instructions = $ARGV[$i + 1];
|
||||
$unknown_instructions = uri_encode($unknown_instructions);
|
||||
}
|
||||
if ($line eq '-id_extra') {
|
||||
$id_extra = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-agent_name') {
|
||||
$agent_name = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-force_create_agent') {
|
||||
$force_create_agent = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-user_comment') {
|
||||
$user_comment = $ARGV[$i + 1];
|
||||
|
@ -224,6 +245,7 @@ sub tool_api_main () {
|
|||
}
|
||||
if ($line eq '-custom_data') {
|
||||
$custom_data = $ARGV[$i + 1];
|
||||
$custom_data = encode_base64($custom_data, '');
|
||||
}
|
||||
if ($line eq '-server_id') {
|
||||
$server_id = $ARGV[$i + 1];
|
||||
|
@ -240,8 +262,8 @@ sub tool_api_main () {
|
|||
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";
|
||||
if ($id_agent eq "" && $agent_name eq "") {
|
||||
print "[ERROR] Missing id agent! and agent_name Read help info:\n\n";
|
||||
help_screen ();
|
||||
}
|
||||
|
||||
|
@ -262,8 +284,11 @@ sub tool_api_main () {
|
|||
"|" . $source .
|
||||
"|" . $tags .
|
||||
"|" . $custom_data .
|
||||
"|" . $server_id;
|
||||
|
||||
"|" . $server_id .
|
||||
"|" . $id_extra .
|
||||
"|" . $agent_name .
|
||||
"|" . $force_create_agent;
|
||||
|
||||
$call_api = $api_path . '?' .
|
||||
'op=set&' .
|
||||
'op2=create_event&' .
|
||||
|
|
Loading…
Reference in New Issue