mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
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
c77a285a97
commit
dbaa27ce6c
@ -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>
|
||||
|
||||
* lib/PandoraFMS/Core.pm: Added support for tag phone information.
|
||||
|
@ -1,13 +1,13 @@
|
||||
#!/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;
|
||||
@ -19,9 +19,9 @@ tool_api_init();
|
||||
# Main
|
||||
tool_api_main();
|
||||
|
||||
##############################################################################
|
||||
########################################################################
|
||||
# Print a help screen and exit.
|
||||
##############################################################################
|
||||
########################################################################
|
||||
sub help_screen{
|
||||
|
||||
print "Options to create event:
|
||||
@ -50,6 +50,8 @@ Optional parameters:
|
||||
[-c_instructions <critical_instructions>]
|
||||
[-w_instructions <warning_instructions>]
|
||||
[-u_instructions <unknown_instructions>]
|
||||
[-user_comment <comment>]
|
||||
[-owner_user <user for the event>]
|
||||
[-source <source>] : (By default 'Pandora')
|
||||
[-tag <tags>] : Tag (must exist in the system to be imported)";
|
||||
|
||||
@ -97,11 +99,11 @@ sub tool_api_init () {
|
||||
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
########################################################################
|
||||
########################################################################
|
||||
# MAIN
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
########################################################################
|
||||
########################################################################
|
||||
|
||||
sub tool_api_main () {
|
||||
|
||||
@ -139,10 +141,12 @@ sub tool_api_main () {
|
||||
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];
|
||||
}
|
||||
|
||||
@ -154,48 +158,35 @@ 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];
|
||||
$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;
|
||||
foreach (@ARGV) {
|
||||
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') {
|
||||
$event_type = $ARGV[$i + 1];
|
||||
}
|
||||
@ -220,18 +211,12 @@ sub tool_api_main () {
|
||||
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];
|
||||
}
|
||||
@ -241,21 +226,62 @@ sub tool_api_main () {
|
||||
if ($line eq '-u_instructions') {
|
||||
$unknown_instructions = $ARGV[$i + 1];
|
||||
}
|
||||
#~ if ($line eq '-owner') {
|
||||
#~ $owner_user = $ARGV[$i+1];
|
||||
#~ }
|
||||
if ($line eq '-user_comment') {
|
||||
$user_comment = $ARGV[$i + 1];
|
||||
}
|
||||
if ($line eq '-owner_user') {
|
||||
$owner_user = $ARGV[$i + 1];
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$data_event .= "|".$status."|".$id_user."|".$event_type."|".$criticity."|".$id_agent_module."|".$id_alert_am."|".$critical_instructions."|".$warning_instructions."|".$unknown_instructions."|".$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;
|
||||
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 "") {
|
||||
print "[ERROR] Missing id agent! Read help info:\n\n";
|
||||
help_screen ();
|
||||
}
|
||||
|
||||
} elsif ($ARGV[4] eq '-validate_event') {
|
||||
$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') {
|
||||
print "[ERROR] Missing id event! Read help info:\n\n";
|
||||
help_screen ();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$id_event = $ARGV[6];
|
||||
}
|
||||
|
||||
@ -271,16 +297,24 @@ sub tool_api_main () {
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
#-----------DEBUG----------------------------
|
||||
#print($call_api . "\n\n\n");
|
||||
|
||||
my $content = get($call_api);
|
||||
|
||||
#-----------DEBUG----------------------------
|
||||
#print($content . "\n\n\n");
|
||||
|
||||
if ($option eq '-create_event') {
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user