App-nrun

 view release on metacpan or  search on metacpan

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


###
# this check checks whether the provided hostname is resolveable.
###

package NRun::Checks::CheckNs;

use strict;
use warnings;

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

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

BEGIN {

    NRun::Check::register ( {

        'CHECK' => "ns",
        'DESC'  => "check if hostname is resolvable",
        '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;

    if (not gethostbyname($_self->{hostname})) {
    
        print STDERR "$_self->{hostname};stderr;" . time() . ";$$;n/a;error;\"dns entry is missing for $_self->{hostname}\"\n";
        print STDOUT "$_self->{hostname};stdout;" . time() . ";$$;n/a;exit;\"exit code $NRun::Constants::CHECK_FAILED_NS\"\n";

        return 0;
    }

    return 1;
}

1;



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