App-OTRS-CreateTicket

 view release on metacpan or  search on metacpan

bin/otrs.CreateTicket.pl  view on Meta::CPAN

#! /usr/bin/perl

use strict;
use warnings;

use Encode;
use Encode::Locale;
use File::Basename;
use File::MimeInfo;
use Getopt::Long;
use MIME::Base64;
use Pod::Usage;
use SOAP::Lite;
use Time::Piece;

our $VERSION = '1.16';

print "$0 version $VERSION \n\n";

@ARGV = map { decode(locale => $_, 1) } @ARGV if -t STDIN;
binmode STDOUT, ":encoding(console_out)" if -t STDOUT;
binmode STDERR, ":encoding(console_out)" if -t STDERR;

my @TicketFields
    = qw ( Title CustomerUser Queue Priority State Type Service SLA Owner Responsible );
my @ArticleFields = qw ( Subject Body ContentType ArticleType SenderType TimeUnit );

my @TicketOptions  = map { $_ . '=s' } @TicketFields;
my @ArticleOptions = map { $_ . '=s' } @ArticleFields;

my %Param = ();
GetOptions(
    \%Param,
    # options for connection
    'UserLogin=s',
    'Password=s',
    'Server=s',
    'Operation=s',
    'Namespace=s',
    'Url=s',
    'BodyFile=s',
    'Ssl',
    'help',
    # options for ticket
    @TicketOptions,
    'PendingTime=s',
    # options for article
    @ArticleOptions,
    # dynamic fields; can be multiple
    'DynamicField=s%',
    # attachments; can be multiple
    'Attachment=s@',
);

if ( $Param{help} || !$Param{Url} && !$Param{Server} ) {
    pod2usage( -exitstatus => 0 );
}

my $URL;

# if we do not have a URL, compose one
if ( !$Param{Url} ) {
    my $Server = $Param{Server} || 'localhost';
    my $HTTPType = $Param{Ssl} ? 'https://' : 'http://';
    $URL = $HTTPType . $Server . '/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector'
}
else {
    $URL = $Param{Url};
}

# handle attachments
my @Attachments;
if (defined $Param{Attachment}) {

    for my $File ( @{$Param{Attachment}} ) {
        die "Can't find attachment '$File'.\n" if !-f $File;

        # open attachment && read in
        open my $fh, "<:unix", $File or die "Couldn't open $File: $!\n";
        read $fh, my $Content, -s $fh or die "Couldn't read $File: $!";

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.364 second using v1.00-cache-2.02-grep-82fe00e-cpan-9e6bc14194b )