From 1e2387474a449452b78520b9ad96a8b4b5e99722 Mon Sep 17 00:00:00 2001 From: Harald Pfeiffer Date: Wed, 17 Apr 2019 19:07:19 +0200 Subject: initial commit of source fetch --- .../check_etc_resolv/Makefile | 5 + .../check_etc_resolv/check_etc_resolv | 139 +++++++++++++++++++++ .../check_etc_resolv/control | 5 + .../check_etc_resolv/copyright | 14 +++ .../check_etc_resolv/tests | 2 + 5 files changed, 165 insertions(+) create mode 100644 nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/Makefile create mode 100755 nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/check_etc_resolv create mode 100644 nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/control create mode 100644 nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/copyright create mode 100644 nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/tests (limited to 'nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv') diff --git a/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/Makefile b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/Makefile new file mode 100644 index 0000000..cac655c --- /dev/null +++ b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/Makefile @@ -0,0 +1,5 @@ +#/usr/bin/make -f + +PLUGIN = check_etc_resolv + +include ../common.mk diff --git a/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/check_etc_resolv b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/check_etc_resolv new file mode 100755 index 0000000..e94b72e --- /dev/null +++ b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/check_etc_resolv @@ -0,0 +1,139 @@ +#!/usr/bin/perl -w +# +# Author: Petter Reinholdtsen +# Date: 2001-11-09 +# +# Check /etc/resolv.conf, and make sure the name servers listed are +# working. It will ignore entries with '# NAGIOSIGNORE' at the end. + +use Socket; + +use vars qw($host $debug $mincount $trycount $testhost $retval $nagiosmsg); + +$retval = 0; +$nagiosmsg = ""; + +$host = '/usr/bin/host'; + +$debug = 0; + +# There should be at least this many servers in the list +$mincount = 1; + +# Try to call host this many times before reporting any bugs +$trycount = 3; + +# Which DNS name to look up +$testhost = "www.uio.no"; + +# Stolen from Logwatch.pm +sub canonical_ipv6_address { + my @a = split /:/, shift; + my @b = qw(0 0 0 0 0 0 0 0); + my $i = 0; + # comparison is numeric, so we use hex function + while (defined $a[0] and $a[0] ne '') {$b[$i++] = hex(shift @a);} + @a = reverse @a; + $i = 7; + while (defined $a[0] and $a[0] ne '') {$b[$i--] = hex(shift @a);} + @b; +} + +sub error_with_dns { + local ($count, $ip, $error) = @_; + + # Count 1 = Error + # Count 2 = Problem + # Count 3-> = Warning + if (1 == $count) { + $retval = 2; + } elsif (2 == $count) { + $retval = 1 unless ($retval > 0); + } + + $nagiosmsg .= "
" unless ($nagiosmsg =~ /^$/); + $nagiosmsg .= "/etc/resolv.conf: nameserver #$count $ip: $error"; +} + +# Check if there is a DNS server running on the given IP address +sub test_dns_server { + local ($ip) = @_; + local ($name) = ""; + + print "Checking $1\n" if $debug; + + # there are other module functions that do this more gracefully + # (such as inet_pton), but we can't guarantee that they are available + # in every system, so we use the built-in gethostbyaddr. + if ($ip =~ /^[\d\.]*$/) { + $PackedAddr = pack('C4', split /\./,$ip); + $name = gethostbyaddr($PackedAddr,AF_INET()); + } elsif ($ip =~ /^[0-9a-zA-Z:]*/) { + $PackedAddr = pack('n8', canonical_ipv6_address($ip)); + $name = gethostbyaddr($PackedAddr, AF_INET6()); + } + + return "missing in DNS" if ( ! defined $name ); + + my $try = $trycount; + my $delay = 1; # Exponensial backoff + for ($try = $trycount; $try; --$try) { + print "Running '$host $testhost $ip 2>/dev/null'\n" if $debug; + local $lookup = `$host $testhost $ip 2>/dev/null`; + + print "Reply from host (try=$try):\n $lookup\n" if $debug; + + if ($lookup =~ /\sA\s+\d/ || $lookup =~ /has address/ || + $lookup =~ /domain name pointer/ || $lookup =~ /Name: /) { + return undef; # true + } + print "Sleeping $delay\n" if $debug; + sleep $delay; + $delay += $delay; + } + + return "no/bad reply from DNS server"; +} + +sub check_etc_resolv_conf { + open(RESOLV, "< /etc/resolv.conf") || die "Unable to open /etc/resolv.conf"; + local $count = 0; + while () { + chomp; + if (/# NAGIOSIGNORE$/) { # Skip lines marked to be ignored + $count++ if (m/^nameserver\s+/); # Count ignored nameservers + next; + } + s/\#.+//; # Skip comments + next if (/^\s*$/); # Skip empty lines + if (/^nameserver\s+(\S+)/) { + $count++; + local ($error) = test_dns_server($1); + if ( defined $error ) { + error_with_dns($count, $1, $error); + } + } + } + close(RESOLV); + + if ($count < $mincount) { + $retval = 1 unless $retval > 0; + $nagiosmsg .= "
" unless ($nagiosmsg =~ /^$/); + $nagiosmsg .= "/etc/resolv.conf: Only $count nameservers in " . + "/etc/resolv.conf (low-limit is $mincount)"; + } +} + +check_etc_resolv_conf() if ( -f "/etc/resolv.conf" && -x $host ); + +unless ( -x $host ) { + $nagiosmsg .= "$host is missing or not executable, please fix.."; + $retval = 1; +} + +if ($nagiosmsg =~ /^$/) { + print "/etc/resolv.conf OK\n"; +} else { + print $nagiosmsg . "\n"; +} +exit $retval; diff --git a/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/control b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/control new file mode 100644 index 0000000..8f4a735 --- /dev/null +++ b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/control @@ -0,0 +1,5 @@ +Uploaders: Petter Reinholdtsen +Description: plugin to check /etc/resolv.conf + Check /etc/resolv.conf, and make sure the name servers listed are + working. It will ignore entries with '# NAGIOSIGNORE' at the end. +Recommends: bind9-host | knot-host diff --git a/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/copyright b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/copyright new file mode 100644 index 0000000..ed4b2a9 --- /dev/null +++ b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/copyright @@ -0,0 +1,14 @@ +Copyright (C) 2001 Petter Reinholdtsen + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, see . diff --git a/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/tests b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/tests new file mode 100644 index 0000000..1349860 --- /dev/null +++ b/nagios-plugins-contrib-24.20190301~bpo9+1/check_etc_resolv/tests @@ -0,0 +1,2 @@ +Test-Command: /usr/lib/nagios/plugins/check_etc_resolv +Depends: bind9-host | knot-host -- cgit v1.2.3