check_enum

Plugin pro systém NAGIOS na monitoring ENUM záznamů.

verze 0.4 - aktuální produkční

#!/usr/bin/perl -w
#
# *** CZ ENUM check plugin for Nagios ***
#
# (c)2oo8-9 Miroslav Dvorak <Miroslav.Dvorak@cesnet.cz>
#
# Last Modified: 2009-09-24
#
# Usage and description:
#
# ./check_enum [-h] \
#              [-W<days_WARNING>] [-C<days_CRITICAL>]
#              -N<E164_number> -P<prefix_length>
#
# -W warning if expiration of domain < days_WR
#
# -C critical if expiration of domain < days_CR
#
# -N E164 number
#
# -P prefix length
#
# -h prints version & help
#
# Description:
#
# Output:
#
# Notes:
#
# Examples:
#
#

use strict;
use Getopt::Std;
use Date::Calc qw (Delta_Days);
use Net::Whois::Raw;
use Net::DNS;
use vars qw ($opt_h $opt_W $opt_C $opt_N $opt_P);

getopt("hWCNP");

my $WHOIS_SER='whois.nic.cz';
my $VERSION=0.4;

if ( ! $opt_N || ! $opt_P || $opt_h )
{
  &print_help;
}

my $exit_status;

my $STATE_OK=0;
my $STATE_WARNING=1;
my $STATE_CRITICAL=2;
my $STATE_UNKNOWN=3;
my $STATE_DEPENDENT=1;

my ($revers,$revers_bp,$dayz,$cisel,$dayzE);
my ($rgstr,$ns_ser,$valid_to,$expire);
my ($DY,$DM,$DD,$TY,$TM,$TD,$TT,$DT,$ED,$EM,$EY);
my ($STATE,$STA_VAL,$STA_DNS,$STA_NAP,$STA_EXP);
my ($ton,$radek,$i);
my (@whois_result,$whois_vel);

my $pref_length = 0;

if ($opt_P>0)
{
  $pref_length = $opt_P;
}

if ($opt_W == 1)
{
  $opt_W = 30;
}

if ($opt_C == 1)
{
  $opt_C = 10;
}

$cisel = map $_, $opt_N =~ /(.)/gs;

for($i = $cisel + 1; $i <= 12 ; $i++)
{
  $opt_N .= "1";
}

$revers = reverse $opt_N;
$revers =~ s/[0-9]/$&./g;
$revers = $revers."e164.arpa";
$revers_bp = substr ($revers, - ($pref_length * 2 + 9));

($TD,$TM,$TY) = (localtime)[3,4,5];
$TY = $TY + 1900;
$TM = $TM + 1;

@whois_result = split ("\n",whois ($revers_bp,$WHOIS_SER));
$whois_vel = @whois_result;

if ($whois_vel < 2)
{
  print "No answer from CZ WHOIS server or CZ WHOIS server in laaaaag.\n";
  exit $STATE_DEPENDENT;
}

foreach $radek (@whois_result)
{
#  print $radek;

  if ($radek =~ /validated-to:/)
  {
    $valid_to = $radek;
    $valid_to =~ s/validated-to: //;

    my @Dcele = split(/\./, $valid_to);
    ($DD,$DM,$DY) = ($Dcele[0],$Dcele[1],$Dcele[2]);
    chomp ($DY);
  }

  if ($radek =~ /expire:/)
  {
    $expire = $radek;
    $expire =~ s/expire: //;

    my @Dcele = split(/\./, $expire);
    ($ED,$EM,$EY) = ($Dcele[0],$Dcele[1],$Dcele[2]);
    chomp ($EY);
  }

  if ($radek =~ /nserver:/)
  {
    $ns_ser = $radek;
    $ns_ser =~ s/nserver: //;
    $ns_ser =~ s/ //g;
    chomp($ns_ser);
  }
}


$dayz = Delta_Days ($TY, $TM, $TD, $DY, $DM, $DD);
if ($dayz <= $opt_C )
{ $STA_VAL = $STATE_CRITICAL ; $STATE = $STATE_CRITICAL; }
elsif ($dayz <= $opt_W)
{ $STA_VAL = $STATE_WARNING ; $STATE = $STATE_WARNING; }
else
{ $STA_VAL = $STATE_OK ; $STATE = $STATE_OK; }

$dayzE = Delta_Days ($TY, $TM, $TD, $EY, $EM, $ED);
if ($dayzE <= $opt_C )
{ $STA_EXP = $STATE_CRITICAL ; $STATE = $STATE_CRITICAL; }
elsif ($dayzE <= $opt_W)
{ $STA_EXP = $STATE_WARNING ; $STATE = $STATE_WARNING; }
else
{ $STA_EXP = $STATE_OK ; $STATE = $STATE_OK; }


if ($ns_ser ne "")
{ $STA_DNS = $STATE_OK; }
else
{ $STA_DNS = $STATE_CRITICAL ; $STATE = $STATE_CRITICAL; }

print "Validated for ".$dayz." days. It is ".$STA_VAL.". ";
print "Expire in ".$dayzE." days. It is ".$STA_EXP.". ";
print "At least one DNS ".$ns_ser.". It is ".$STA_DNS.". ";

my $resolver = Net::DNS::Resolver -> new;
my $query = $resolver -> query ($revers, "NAPTR");

$ton = 0;

if ($query)
{
  if ($query->answer)
  {
    $ton++;
  }
  else
  {
    print "Query failed: ", $resolver -> errorstring, "\n";
  }
}

if ($ton > 0)
{ $STA_NAP = $STATE_OK; }
else
{ $STA_NAP = $STATE_CRITICAL ; $STATE = $STATE_CRITICAL; }

print $ton." of NAPTR records. It is ".$STA_NAP.". \n";

exit $STATE;


sub print_help
{
  print "CZ ENUM (+420) check plugin for nagios version ".$VERSION."\n";
  print "(C)2oo8-9 Miroslav Dvorak <miroslav.dvorak\@cesnet.cz>\n";
  print "USAGE:\n";
  print " ./check_enum [-h] \
              [-Wdays_WR] [-Cdays_CR] \
              -N<E164_number> -P<prefix_length>\n";

  exit 3;
}

Starší verze

cs/monitoring/enum/check_enum.txt · Poslední úprava: 2009/09/24 07:13 autor: mirecek@cesnet.cz
Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0