2014-08-18 Alejandro Gallardo <alejandro.gallardo@artica.es>

* lib/PandoraFMS/Core.pm: Added an internal action to
	create a Integria IMS incident on the function
	"pandora_execute_action". Added the function
	"pandora_create_integria_ticket".

	* util/pandora_manage.pl: Added an option to recreate
	a collection with the function "cli_recreate_collection".
	Added a call to get the Pandora FMS shared config.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10432 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
alexhigh 2014-08-18 13:03:34 +00:00
parent 1e99530fbc
commit afded600f0
4 changed files with 358 additions and 0 deletions

View File

@ -1,3 +1,14 @@
2014-08-18 Alejandro Gallardo <alejandro.gallardo@artica.es>
* lib/PandoraFMS/Core.pm: Added an internal action to
create a Integria IMS incident on the function
"pandora_execute_action". Added the function
"pandora_create_integria_ticket".
* util/pandora_manage.pl: Added an option to recreate
a collection with the function "cli_recreate_collection".
Added a call to get the Pandora FMS shared config.
2014-08-14 Ramon Novoa <rnovoa@artica.es>
* conf/pandora_server.conf.new: Added recon_timing_template to the

View File

@ -982,6 +982,46 @@ sub pandora_execute_action ($$$$$$$$$;$) {
}
}
# Integria IMS Ticket
} elsif ($clean_name eq "Integria IMS Ticket") {
$field1 = subst_alert_macros ($field1, \%macros);
$field3 = subst_alert_macros ($field3, \%macros);
$field4 = subst_alert_macros ($field4, \%macros);
$field6 = subst_alert_macros ($field6, \%macros);
$field7 = subst_alert_macros ($field7, \%macros);
# Field 1 (Integria IMS API path)
my $api_path = $field1;
# Field 2 (Integria IMS API pass)
my $api_pass = $field2;
# Field 3 (Integria IMS user)
my $integria_user = $field3;
# Field 4 (Ticket name)
my $ticket_name = $field4;
if ($ticket_name eq "") {
$ticket_name = "Pandora FMS alert action created by API";
}
# Field 5 (Ticket group ID)
my $ticket_group_id = $field5;
if ($ticket_group_id eq '') {
$ticket_group_id = 0;
}
# Field 6 (Ticket priority);
my $ticket_priority = $field6;
if ($ticket_priority eq '') {
$ticket_priority = 0;
}
# Field 7 (Ticket description);
my $ticket_description = $field7;
pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_description);
# Unknown
} else {
logger($pa_config, "Unknown action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'nombre'} : 'N/A') . "'.", 3);
@ -4628,6 +4668,50 @@ sub pandora_edit_custom_graph ($$$$$$$$$$$) {
return $res;
}
sub pandora_create_integria_ticket ($$$$$$$$) {
my ($pa_config,$api_path,$api_pass,$integria_user,$ticket_name,$group_id,$ticket_priority,$ticket_description) = @_;
my $data_ticket;
my $call_api;
if ($api_path eq "") {
return 0;
}
if ($integria_user eq "") {
$integria_user = "admin";
}
if ($ticket_name eq "") {
$ticket_name = "Ticket created by Pandora FMS";
}
if ($group_id eq "") {
$group_id = 0;
}
if ($ticket_priority eq "") {
$ticket_priority = 1;
}
$data_ticket = $ticket_name .
"|;|" . $group_id .
"|;|" . $ticket_priority .
"|;|" . $ticket_description;
$call_api = $api_path . '?' .
'user=' . $integria_user . '&' .
'pass=' . $api_pass . '&' .
'op=create_incident&' .
'params=' . $data_ticket .'&' .
'token=|;|';
logger($pa_config, "Integria ticket call:" . $call_api . "", 3);
my $content = get($call_api);
logger($pa_config, "Integria ticket res:" . $content . "", 3);
if (is_numeric($content) && $content ne "-1") {
return $content;
}
else {
return 0;
}
}
# End of function declaration
# End of defined Code

View File

@ -0,0 +1,237 @@
#!/usr/bin/perl
########################################################################
# Integria IMS - Remote Ticket 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;
# Init
tool_api_init();
# Main
tool_api_main();
########################################################################
# Print a help screen and exit.
########################################################################
sub help_screen{
print "Options to create event:
$0 -p <path_to_integria_console_API> -c <credentials> -create_ticket <options>
Where options:
-u <credentials>
-create_ticket
-name <ticket_name> : Free text
-group <id_group> : Group ID (use 0 for 'all')
Optional parameters:
[-priority <priority>] : 10 Maintance, 0 Informative, 1 Low, 2 Medium, 3 Serious, 4 Very serious
[-desc <description>] : Free text
[-type <ticket_type>] : Type ID (must exist in Integria IMS)
[-inventory <inventory_id>] : Inventory ID (must exist in Integria IMS)
[-email <email_copy>] : 1 or 0\n\n";
print "Credential/API syntax: \n\n";
print "<credentials>: API credentials separated by comma: <api_pass>,<user>\n\n";
print "Example of ticket generation:\n\n";
print "\t$0 -p http://localhost/integria/include/api.php -u 1234,admin \
\t-create_ticket -name \"SampleTicket\" -group 1 -priority 2 -desc \"This is a sample\" \
\t-type 4 -inventory 6 -email 1";
print "\n\n\n";
exit;
}
##############################################################################
# Init screen
##############################################################################
sub tool_api_init () {
print "\nIntegria IMS Remote Ticket Tool Copyright (c) 2013 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.integriaims.com\n\n";
if ($#ARGV < 0) {
help_screen();
}
if (($ARGV[0] eq '-h') || ($ARGV[0] eq '-help')) {
help_screen();
}
}
########################################################################
########################################################################
# MAIN
########################################################################
########################################################################
sub tool_api_main () {
my $api_path;
my $credentials;
my $api_pass;
my $db_user;
my @db_info;
my $ticket_name = "";
my $group_id = -1;
my $ticket_priority = 0;
my $ticket_description = '';
my $ticket_type = '';
my $ticket_inventory = '';
my $email_copy = 0;
my $option = $ARGV[4];
my $data_ticket;
my $call_api;
#~ help or api path (required)
if ($ARGV[0] eq '-h') {
print "HELP!\n";
help_screen();
}
elsif ($ARGV[0] ne '-p') {
print "[ERROR] Missing API path! Read help info:\n\n";
help_screen();
exit;
}
else {
$api_path = $ARGV[1];
}
#~ credentials of database
if ($ARGV[2] eq '-u') {
$credentials = $ARGV[3];
@db_info = split(',', $credentials);
if ($#db_info < 1) {
print "[ERROR] Invalid database credentials! Read help info:\n\n";
help_screen();
}
else {
$api_pass = $db_info[0];
$db_user = $db_info[1];
}
}
else {
print "[ERROR] Missing database credentials! Read help info:\n\n";
help_screen();
exit;
}
if ($option eq '-create_ticket') {
my $i = 0;
foreach (@ARGV) {
my $line = $_;
#-------------------DEBUG--------------------
#print("i " . $i . " line " . $line . "\n");
if ($line eq '-name') {
$ticket_name = $ARGV[$i + 1];
}
if ($line eq '-group') {
$group_id = $ARGV[$i + 1];
}
if ($line eq '-priority') {
$ticket_priority = $ARGV[$i + 1];
}
if ($line eq '-desc') {
$ticket_description = $ARGV[$i + 1];
}
if ($line eq '-type') {
$ticket_type = $ARGV[$i + 1];
}
if ($line eq '-inventory') {
$ticket_inventory = $ARGV[$i + 1];
}
if ($line eq '-email') {
$email_copy = $ARGV[$i + 1];
}
$i++;
}
if ($ticket_name eq "") {
print "[ERROR] Missing ticket name! Read help info:\n\n";
help_screen();
exit;
}
if ($group_id == -1) {
print "[ERROR] Missing ticket group! Read help info:\n\n";
help_screen();
exit;
}
$data_ticket = $ticket_name .
"|;|" . $group_id .
"|;|" . $ticket_priority .
"|;|" . $ticket_description .
"|;|" . $ticket_inventory .
"|;|" . $ticket_type .
"|;|" . $email_copy;
$call_api = $api_path . '?' .
'user=' . $db_user . '&' .
'pass=' . $api_pass . '&' .
'op=create_incident&' .
'params=' . $data_ticket .'&' .
'token=|;|';
}
else {
print "[ERROR] No valid option selected! Read help info:\n\n";
help_screen();
exit;
}
my @args = @ARGV;
my $ltotal = $#args;
if ($ltotal < 0) {
print "[ERROR] No valid arguments. Read help info:\n\n";
help_screen();
exit;
}
else {
#-----------DEBUG------------
#print($call_api . "\n\n\n");
my $content = get($call_api);
#-----------DEBUG-----------
#print($content . "\n\n\n");
if ($option eq '-create_ticket') {
if ($content eq undef) {
print "[ERROR] Not respond or bad syntax. Read help info:\n\n";
help_screen();
exit;
}
else {
print "Ticket ID: $content";
}
}
else {
print "[ERROR] No valid option selected!";
}
}
print "\nExiting!\n\n";
exit;
}

View File

@ -69,6 +69,9 @@ my $dbh = db_connect ('mysql', $conf{'dbname'}, $conf{'dbhost'}, $conf{'dbport'}
my $history_dbh = ($conf{'_history_db_enabled'} eq '1') ? db_connect ('mysql', $conf{'_history_db_name'},
$conf{'_history_db_host'}, '3306', $conf{'_history_db_user'}, $conf{'_history_db_pass'}) : undef;
# Read shared config file
pandora_get_sharedconfig (\%conf, $dbh);
my $conf = \%conf;
# Main
@ -166,6 +169,7 @@ sub help_screen{
help_screen_line('--validate_policy_alerts', '<policy_name>', 'Validate the alerts of a given policy');
help_screen_line('--get_policy_modules', '<policy_name>', 'Get the modules of a policy');
help_screen_line('--get_policies', '[<agent_name>]', "Get all the policies (without parameters) or \n\tthe policies of a given agent (agent name as parameter)");
help_screen_line('--recreate_collection', '<collection_id>', 'Recreate the files of a collection');
print "\nNETFLOW:\n\n" unless $param ne '';
help_screen_line('--create_netflow_filter', "<filter_name> <group_name> <filter> \n\t <aggregate_by dstip|dstport|none|proto|srcip|srcport> <output_format kilobytes|kilobytespersecond|\n\t megabytes|megabytespersecond>", "Create a new netflow filter");
@ -2813,6 +2817,24 @@ sub cli_apply_all_policies() {
}
}
##############################################################################
# Recreate the files of a collection.
# Related option: --recreate_collection
##############################################################################
sub cli_recreate_collection () {
my $collection_id = @ARGV[2];
my $result = enterprise_hook('pandora_recreate_collection', [$conf, $collection_id, $dbh]);
if ($result == 1) {
print_log "[INFO] Collection recreated successfully.\n";
}
elsif ($result == 0) {
print_log "[ERROR] Collection not recreated.\n";
}
}
##############################################################################
# Validate all the alerts
# Related option: --validate_all_alerts
@ -3899,6 +3921,10 @@ sub pandora_manage_main ($$$) {
param_check($ltotal, 35, 33);
cli_create_local_component();
}
elsif ($param eq '--recreate_collection') {
param_check($ltotal, 1);
cli_recreate_collection();
}
else {
print_log "[ERROR] Invalid option '$param'.\n\n";
$param = '';