2014-08-18 15:03:34 +02:00
|
|
|
#!/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:
|
|
|
|
|
2016-06-27 09:39:22 +02:00
|
|
|
$0 -p <path_to_integria_console_API> -u <credentials> -create_ticket <options>
|
2014-08-18 15:03:34 +02:00
|
|
|
|
|
|
|
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
|
2019-09-02 17:01:41 +02:00
|
|
|
[-owner <owner>] : Free text
|
2014-08-18 15:03:34 +02:00
|
|
|
[-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";
|
2016-06-06 15:06:24 +02:00
|
|
|
print "<credentials>: API credentials separated by comma: <api_pass>,<user>,<user_pass>\n\n";
|
2014-08-18 15:03:34 +02:00
|
|
|
|
|
|
|
print "Example of ticket generation:\n\n";
|
|
|
|
|
2016-06-06 15:06:24 +02:00
|
|
|
print "\t$0 -p http://localhost/integria/include/api.php -u 1234,admin,1234 \
|
2014-08-18 15:03:34 +02:00
|
|
|
\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 () {
|
|
|
|
|
2015-12-01 12:16:52 +01:00
|
|
|
print "\nIntegria IMS Remote Ticket Tool Copyright (c) 2013-2015 Artica ST\n";
|
2014-08-18 15:03:34 +02:00
|
|
|
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;
|
2016-06-29 12:43:15 +02:00
|
|
|
my $db_user_pass;
|
2014-08-18 15:03:34 +02:00
|
|
|
my @db_info;
|
2016-06-29 12:43:15 +02:00
|
|
|
my $integria_user;
|
|
|
|
my $user_pass;
|
2014-08-18 15:03:34 +02:00
|
|
|
|
|
|
|
my $ticket_name = "";
|
|
|
|
my $group_id = -1;
|
|
|
|
my $ticket_priority = 0;
|
2019-09-02 17:01:41 +02:00
|
|
|
my $ticket_owner = '';
|
2014-08-18 15:03:34 +02:00
|
|
|
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];
|
2016-06-29 12:43:15 +02:00
|
|
|
$integria_user = $db_info[1];
|
|
|
|
$user_pass = $db_info[2];
|
2014-08-18 15:03:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
}
|
2019-09-02 17:01:41 +02:00
|
|
|
if ($line eq '-owner') {
|
|
|
|
$ticket_owner = $ARGV[$i + 1];
|
|
|
|
}
|
2014-08-18 15:03:34 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-06 15:06:24 +02:00
|
|
|
#~ $data_ticket = $ticket_name .
|
|
|
|
#~ "|;|" . $group_id .
|
|
|
|
#~ "|;|" . $ticket_priority .
|
|
|
|
#~ "|;|" . $ticket_description .
|
|
|
|
#~ "|;|" . $ticket_inventory .
|
|
|
|
#~ "|;|" . $ticket_type .
|
|
|
|
#~ "|;|" . $email_copy;
|
|
|
|
|
2014-08-18 15:03:34 +02:00
|
|
|
$data_ticket = $ticket_name .
|
2016-06-06 15:06:24 +02:00
|
|
|
"|;|" . $group_id .
|
|
|
|
"|;|" . $ticket_priority .
|
2019-09-02 17:01:41 +02:00
|
|
|
"|;|" . $ticket_owner .
|
2016-06-06 15:06:24 +02:00
|
|
|
"|;|" . $ticket_description .
|
|
|
|
"|;|" . $ticket_inventory .
|
|
|
|
"|;|" . $ticket_type .
|
|
|
|
"|;|" . $email_copy .
|
2016-06-29 12:43:15 +02:00
|
|
|
"|;|" . $integria_user .
|
|
|
|
"|;|" .
|
2016-06-06 15:06:24 +02:00
|
|
|
"|;|" . '1' .
|
|
|
|
"|;|" .
|
|
|
|
"|;|";
|
2014-08-18 15:03:34 +02:00
|
|
|
$call_api = $api_path . '?' .
|
2016-06-06 15:06:24 +02:00
|
|
|
'user=' . $integria_user . '&' .
|
|
|
|
'user_pass=' . $user_pass . '&' .
|
2014-08-18 15:03:34 +02:00
|
|
|
'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;
|
2015-12-01 12:16:52 +01:00
|
|
|
}
|