BZ-Client

 view release on metacpan or  search on metacpan

eg/nagios2bugzilla/talktobugzilla.pl  view on Meta::CPAN

#!/usr/bin/perl
#
# Don't be affraid to aggressively refactor this.
# It is a first start and will no doubt need an actual design as it gets bigger!
#
# vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl smarttab
#

use strict;
use warnings;

# so i can hack on the server and on my local machine
BEGIN {
    if (-d '/root/dean/lib') {
        eval q|use lib '/root/dean/lib'|;
    }
}

use lib '/usr/lib/nagios/perl'; # OIE::Nagios

use v5.10; # i like 'say'
use BZ::Client;
use BZ::Client::Bug;
use BZ::Client::Bug::Comment;
use BZ::Client::Bugzilla;
use Path::Tiny;
use Try::Tiny; # nb this is slow. see http://perladvent.org/2016/2016-12-12.html
use Sys::Hostname qw/ hostname /;
use Log::Log4perl;
use DateTime;
use Nagios::Cmd; # replace nagios_command
use Data::Dumper;
$Data::Dumper::Indent = 0;
$Data::Dumper::Sortkeys = 0;

# use 0 when debugging, 1 will delete the notice files from spool
my $delete = 1;
# use 1 when debugging to close *everything* after opening
my $closeplease = 0;

my $closetime = 24 * 7; #hours
my $acktime   = 24 * 1; #hours
my $stirtime  = 24 * 2; #hours

# alias template for sprintf
#my $aliastmpl = 'TESTaaaSERVICEPROBLEMID%d'; # use something for development
my $aliastmpl = 'SERVICEPROBLEMID%d';
my $nagiosuri = 'http://nagios.domain.com/nagios';

if (hostname() =~ m/lab/) {
    $aliastmpl = 'LAB' . $aliastmpl; # FIXME get this from a config file
    $nagiosuri = 'http://nagios.lab.domain.com/nagios';
}

# use this for debugging too
#my %team = (
#    product   => 'Internet Services Engineering',
#    component => 'AOP',
#    version   => 'unspecified',
#    op_sys    => 'other',
#    platform  => 'Other',
#    priority  => 'P1',
#    status    => 'NEW',
#);

# team details and other bug defaults
my %team = ( # FIXME get this from a config file
    product   => 'IPSP',
    component => 'Hardware',
    version   => 'Production',
    op_sys    => 'other',
    platform  => 'Other',
    status    => 'NEW',
    keywords  => ['nagiosgenerated'],
);
$team{keywords} = ['nagiosgeneratedlab']
    if hostname() =~ m/lab/;

# list of files
my $spool = '/var/spool/nagios/notify-by-bugzilla';

# nagios pipe
my $nagiospipe = '/usr/local/nagios/var/rw/cmd.pipe';
my $cmd = Nagios::Cmd->new( $nagiospipe );

# fire up logging
Log::Log4perl->init('talktobugzilla-log4perl.conf');



( run in 0.501 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )