BZ-Client

 view release on metacpan or  search on metacpan

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

            next FILELOOP
        }

        $log->info("Searching for $alias on server");

        # does the bug already exist?
        my $search = try {
            return BZ::Client::Bug->search( $client, { alias => $alias } );
        }
        catch {
             $log->logdie(sprintf 'Something bad happened searching for %s via alias %s, error: %s',
                $alias , $params{SERVICEPROBLEMID} , Dumper( $_ ) );
        };

        ## not new, so skipping it
        if ( ref $search eq 'ARRAY' and @$search ) {
            $log->info( "Found and skipping $params{SERVICEPROBLEMID}" );
            $problems{ $alias } = $search->[0]; # hold on to this for later
            try { if ($delete) { $log->debug('Removing file: ' .$f->basename); $f->remove() }}
            catch { $log->warn(sprintf 'Failed to delete %s because: %s', $f->basename, $_) };
            next FILELOOP
        }

        # if 0, we came from OK state so no bug exists. otherwise we found the existing bug
        if ($params{LASTSERVICEPROBLEMID}) {

            my $lastalias = bugalias( $params{LASTSERVICEPROBLEMID} );
            $log->debug("The last alias for $params{LASTSERVICEPROBLEMID} is $lastalias");

            # short circuit if we have seen this bug before
            if ($problems{ $lastalias }) {
                update_bug($f, $problems{ $lastalias }, \%params);
                push @pleaseclose, $lastalias;
                next FILELOOP
            }

            $log->info("Searching for $lastalias on server");

            # does the bug already exist?
            my $search = try {
                return BZ::Client::Bug->search( $client, { alias => $lastalias } );
            }
            catch {
                 $log->logdie(sprintf 'Something bad happened searching for %s via alias %s, error: %s',
                    $lastalias , $params{SERVICEPROBLEMID} , Dumper( $_ ) );
            };

            if ( ref $search eq 'ARRAY' and @$search ) {
                $log->info( "Found and updating $params{LASTSERVICEPROBLEMID}" );
                $problems{ $lastalias } = $search->[0]; # hold on to this for later
                update_bug($f, $problems{ $lastalias }, \%params);
                push @pleaseclose, $lastalias;
                next FILELOOP
            }

            $log->info("Unable to locate last event $lastalias, processing current event id")

        }

        # skip time'd out plugins if we are going from OK to UNKNOWN
        if ($params{SERVICEOUTPUT} =~ m/^UNKNOWN: Plugin failed: Timeout executing plugin/) {

            $log->info( 'Skipping time\'d out plugin notice' );
            try { if ($delete) { $log->debug('Removing file: ' .$f->basename); $f->remove() }}
            catch { $log->warn(sprintf 'Failed to delete %s because: %s', $f->basename, $_) };
            next FILELOOP

        }

        # create the bug
        create_bug( $f, $alias, \%params );
        push @pleaseclose, $alias;

    } # end for

    $log->info( 'Finished handling problems' );

} # end handle_problems

}

{

# recovery we have already observed
my %recovery;

sub close_bug {

    my $f = shift;
    my $bug = shift;
    my $params = shift;

    $log->info('Going to close ' . $bug->alias());

    # We only care if its still open
    unless ( $bug->is_open() ) {
        $log->info( 'Bug is already closed. Next' );
        try { if ($delete) { $log->debug('Removing file: ' .$f->basename); $f->remove() }}
        catch { $log->warn(sprintf 'Failed to delete %s because: %s', $f->basename, $_) };
        return 1;
    }

    $log->debug('Close params: ' . Dumper( $params )) if $log->is_debug;

        my $comment = sprintf(
            <<'EOF', $0, hostname(), @{$params}{qw( SERVICESTATE SERVICEOUTPUT )}, join( "\n", map { "$_=$params->{$_}" } sort keys %$params ) );

This fault has cleared in Nagios.

New Details:

Status: %3$s
Information: %4$s

Changing Status to: RESOLVED
...with Resolution: FIXED

Your next steps:

 * Check to ensure you agree
 * Then, set this bug's Status to VERIFIED



( run in 1.394 second using v1.01-cache-2.11-cpan-df04353d9ac )