App-nrun

 view release on metacpan or  search on metacpan

lib/NRun/Checks/CheckRscd.pm  view on Meta::CPAN


###
# this check checks whether the rscd agent is running on the provided hostname.
###

package NRun::Checks::CheckRscd;

use strict;
use warnings;

use File::Basename;
use NRun::Check;

our @ISA = qw(NRun::Check);

BEGIN {

    NRun::Check::register ( {

        'CHECK' => "rscd",
        'DESC'  => "check if rscd agent answers",
        'NAME'  => __PACKAGE__,
    } );
}

###
# create a new object.
#
# <- the new object
sub new {

    my $_pkg = shift;
    my $_cfg = shift;

    my $self = {};
    bless $self, $_pkg;

    return $self;
}

###
# initialize this check module.
#
# $_cfg - parameter hash where
# {
#   'hostname' - hostname this check should act on
# }
sub init {

    my $_self = shift;
    my $_cfg  = shift;

    $_self->{hostname} = $_cfg->{hostname};
}

###
# execute the check on $_self->{hostname}.
#
# on error, the following string will be printed on stderr:
#
# HOSTNAME;stderr;PID;n/a;error;"OUTPUT"
#
# <- 1 on success and 0 on error
sub execute {

    my $_self = shift;

    my $out = `agentinfo $_self->{hostname} 2>&1`;

    if ($? != 0) {

        foreach my $line (split(/\n/, $out)) {
        
            print STDERR "$_self->{hostname};stderr;" . time() . ";$$;n/a;error;\"$line\"\n";
        }
        print STDOUT "$_self->{hostname};stdout;" . time() . ";$$;n/a;exit;\"exit code $NRun::Constants::CHECK_FAILED_RSCD\"\n";

        return 0;
    }

    return 1;
}

1;



( run in 0.693 second using v1.01-cache-2.11-cpan-d8267643d1d )