[Nagiosplug-devel] Added Reverse Lookup to check_dig

Sean Kane spkane at mac.com
Fri May 18 20:52:00 CEST 2007


I have had a pretty significant need for being able to do reverse  
lookup queries via Nagios to ensure that the PTR records are setup  
correctly. At the command line I would use "dig -x", but was  
disappointed to find out that check_dig did not support this, so I  
wrote this quick patch to make the functionality work. There are  
likely improvements that can be made, but this is working for me. I  
hope you will consider using it a future release.

I am not a member of the list, so please write to me directly if you  
respond.

Thanks,
Sean


--- check_dig.c 2007-01-28 21:46:40.000000000 +0000
+++ check_dig_reverse.c 2007-05-18 18:40:03.000000000 +0000
@@ -38,8 +38,8 @@
   *  because on some architectures those strings are in non-writable  
memory */
const char *progname = "check_dig";
-const char *revision = "$Revision: 1.46 $";
-const char *copyright = "2002-2006";
+const char *revision = "$Revision: 1.461 $";
+const char *copyright = "2002-2007";
const char *email = "nagiosplug-devel at lists.sourceforge.net";
#include "common.h"
@@ -57,6 +57,7 @@
char *query_address = NULL;
char *record_type = "A";
+char *reverse_query = NULL;
char *expected_address = NULL;
char *dns_server = NULL;
int verbose = FALSE;
@@ -89,8 +90,8 @@
      usage_va(_("Could not parse arguments"));
    /* get the command to run */
-  asprintf (&command_line, "%s @%s -p %d %s -t %s",
-            PATH_TO_DIG, dns_server, server_port, query_address,  
record_type);
+  asprintf (&command_line, "%s @%s -p %d %s %s -t %s",
+            PATH_TO_DIG, dns_server, server_port, reverse_query,  
query_address, record_type);
    alarm (timeout_interval);
    gettimeofday (&tv, NULL);
@@ -193,6 +194,7 @@
      {"critical", required_argument, 0, 'c'},
      {"timeout", required_argument, 0, 't'},
      {"verbose", no_argument, 0, 'v'},
+    {"reverse_query", no_argument, 0, 'x'},
      {"version", no_argument, 0, 'V'},
      {"help", no_argument, 0, 'h'},
      {"record_type", required_argument, 0, 'T'},
@@ -205,7 +207,7 @@
      return ERROR;
    while (1) {
-    c = getopt_long (argc, argv, "hVvt:l:H:w:c:T:p:a:", longopts,  
&option);
+    c = getopt_long (argc, argv, "hVvxt:l:H:w:c:T:p:a:", longopts,  
&option);
      if (c == -1 || c == EOF)
        break;
@@ -262,6 +264,10 @@
      case 'T':
        record_type = optarg;
        break;
+    case 'x':                 /* reverse_lookup */
+      reverse_query = "-x";
+      record_type = "PTR";
+      break;
      case 'a':
        expected_address = optarg;
        break;
@@ -304,6 +310,7 @@
    print_revision (progname, revision);
    printf ("Copyright (c) 2000 Karl DeBisschop  
<kdebisschop at users.sourceforge.net>\n");
+  printf ("Reverse Lookup Modifications by: Sean P. Kane  
<sean.kane at hp.com>\n");
    printf (COPYRIGHT, copyright, email);
    printf (_("This plugin test the DNS service on the specified host  
using dig"));
@@ -320,6 +327,8 @@
    printf ("    %s\n",_("machine name to lookup"));
    printf (" %s\n","-T, --record_type=STRING");
    printf ("    %s\n",_("record type to lookup (default: A)"));
+  printf (" %s\n","-x, --reverse_query");
+  printf ("    %s\n",_("perform reverse lookup"));
    printf (" %s\n","-a, --expected_address=STRING");
    printf ("    %s\n",_("an address expected to be in the answer  
section.if not set, uses whatever was in -l"));
    printf (_(UT_WARN_CRIT));
@@ -336,5 +345,5 @@
    printf (_("Usage:"));
    printf ("%s -H host -l lookup [-p <server port>] [-T <query  
type>]", progname);
    printf (" [-w <warning interval>] [-c <critical interval>] [-t  
<timeout>]");
-  printf (" [-a <expected answer address>] [-v]\n");
+  printf (" [-a <expected answer address>] [-v] [-x]\n");
} 
  




More information about the Devel mailing list