From a58fad4bd8d9f4c8f7118badeae883c7222474b5 Mon Sep 17 00:00:00 2001
From: Mark Harrison <mark@omniti.com>
Date: Fri, 9 May 2008 20:14:43 +0000
Subject: [PATCH] Adding a DNS health check for onager

git-svn-id: https://labs.omniti.com/resmon/trunk@85 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
---
 lib/Resmon/Module/DNS.pm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100755 lib/Resmon/Module/DNS.pm

diff --git a/lib/Resmon/Module/DNS.pm b/lib/Resmon/Module/DNS.pm
new file mode 100755
index 0000000..868f76a
--- /dev/null
+++ b/lib/Resmon/Module/DNS.pm
@@ -0,0 +1,34 @@
+package Resmon::Module::DNS;
+
+use Resmon::Module;
+use Resmon::ExtComm qw/cache_command/;
+
+use vars qw/@ISA/;
+@ISA = qw/Resmon::Module/;
+
+# Checks the dns server status on onager
+
+sub handler {
+    my $self = shift;
+    my $os = $self->fresh_status();
+    return $os if $os;
+    my $object = $self->{object};
+
+    my $key = "-k $self->{key}" if $self->{key};
+
+    my $output = cache_command("rndc $key status 2>&1", 600);
+    if ($output) {
+        foreach (split(/\n/, $output)) {
+            if (/server is up and running/) {
+                return "OK", "$_";
+            } elsif (/^rndc: neither \S+ nor (\S+) was found$/) {
+                return "BAD", "Key file $1 not found";
+            } elsif (/connection refused/) {
+                return "BAD", "$_";
+            }
+        }
+    }
+    return "BAD", "no data";
+}
+
+1;
-- 
GitLab