[Pkg-nagios-changes] [pkg-nagios-plugins-contrib] 03/18: Add check_etc_resolv module from the sitesummary-client package.

Bernd Zeimetz bernd at bzed.de
Wed Oct 1 11:13:15 UTC 2014


This is an automated email from the git hooks/post-receive script.

bzed pushed a commit to branch master
in repository pkg-nagios-plugins-contrib.

commit 9c5232b50efe328cbc65de37bcbe6dfb82c8c821
Author: Petter Reinholdtsen <pere at hungry.com>
Date:   Thu Sep 11 10:28:36 2014 +0200

    Add check_etc_resolv module from the sitesummary-client package.
---
 check_etc_resolv/Makefile         |   5 ++
 check_etc_resolv/check_etc_resolv | 139 ++++++++++++++++++++++++++++++++++++++
 check_etc_resolv/control          |   6 ++
 check_etc_resolv/copyright        |  14 ++++
 4 files changed, 164 insertions(+)

diff --git a/check_etc_resolv/Makefile b/check_etc_resolv/Makefile
new file mode 100644
index 0000000..cac655c
--- /dev/null
+++ b/check_etc_resolv/Makefile
@@ -0,0 +1,5 @@
+#/usr/bin/make -f
+
+PLUGIN = check_etc_resolv
+
+include ../common.mk
diff --git a/check_etc_resolv/check_etc_resolv b/check_etc_resolv/check_etc_resolv
new file mode 100755
index 0000000..e94b72e
--- /dev/null
+++ b/check_etc_resolv/check_etc_resolv
@@ -0,0 +1,139 @@
+#!/usr/bin/perl -w
+#
+# Author: Petter Reinholdtsen <pere at hungry.com>
+# 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 .= "<br>" 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 (<RESOLV>) {
+        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 .= "<br>" 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/check_etc_resolv/control b/check_etc_resolv/control
new file mode 100644
index 0000000..fd4ed8e
--- /dev/null
+++ b/check_etc_resolv/control
@@ -0,0 +1,6 @@
+Uploaders: Petter Reinholdtsen <pere at hungry.com>
+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: perl-base
+Version: ?
diff --git a/check_etc_resolv/copyright b/check_etc_resolv/copyright
new file mode 100644
index 0000000..ed4b2a9
--- /dev/null
+++ b/check_etc_resolv/copyright
@@ -0,0 +1,14 @@
+Copyright (C) 2001 Petter Reinholdtsen <pere at hungry.com>
+
+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 <http://www.gnu.org/licenses/>.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-nagios/pkg-nagios-plugins-contrib.git



More information about the Pkg-nagios-changes mailing list