]> git.michaelhowe.org Git - packages/n/nagios-plugins-local.git/commitdiff
Added a check_ldaps_ip plugin to nagios-plugins-local
authorMichael Howe <michael@michaelhowe.org>
Sat, 22 Jan 2011 16:45:52 +0000 (16:45 +0000)
committerMichael Howe <michael@michaelhowe.org>
Sat, 22 Jan 2011 16:45:52 +0000 (16:45 +0000)
Makefile
src/check_ldaps_ip.c [new file with mode: 0644]

index eb6298311045e1aa34bb49b5b173c3ecd8c2f71b..f30f7d2f9b55620f2d230395b9097c26376b630d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,21 @@
 
+CC=gcc
+RM=/bin/rm
+CFLAGS=
 PLUGINDIR=plugins
 INSTALL=/usr/bin/install
 DSTPLUGINDIR=$(DESTDIR)/usr/lib/nagios/plugins
 
-all:
+all: check_ldaps_ip
+
+check_ldaps_ip: src/check_ldaps_ip.c
+       $(CC) -o $(PLUGINDIR)/check_ldaps_ip src/check_ldaps_ip.c
 
 install:
        $(INSTALL) -d $(DSTPLUGINDIR)
        $(INSTALL) -m 0755 $(PLUGINDIR)/check_cert $(DSTPLUGINDIR)
        $(INSTALL) -m 0755 $(PLUGINDIR)/check_md_raid $(DSTPLUGINDIR)
+       $(INSTALL) -m 0755 $(PLUGINDIR)/check_ldaps_ip $(DSTPLUGINDIR)
+
+clean:
+       $(RM) plugins/check_ldaps_ip
diff --git a/src/check_ldaps_ip.c b/src/check_ldaps_ip.c
new file mode 100644 (file)
index 0000000..7f0c129
--- /dev/null
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#ifndef   NI_MAXHOST
+#define   NI_MAXHOST 1025
+#endif
+/* $Id$
+ *
+ * Small program to take an IP address, convert it into its rDNS (the first
+ * returned by the server) and run check_ldaps.
+ */
+int main(int argc, char *argv[])
+{
+    struct addrinfo *result;
+    struct addrinfo *res;
+    int error;
+    if (argc != 3) {
+        fprintf(stderr,"usage: check_ldaps_ip hostname basedn\n");
+        fprintf(stderr,"    Converts ip into the first rDNS returned by the server, and hands it off to check_ldaps\n");
+        return 1;
+    }
+
+    /* resolve the domain name into a list of addresses */
+    error = getaddrinfo(argv[1], NULL, NULL, &result);
+    if (error != 0){   
+        fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
+        return EXIT_FAILURE;
+    }   
+    char hostname[NI_MAXHOST] = "";
+
+    error = getnameinfo(result->ai_addr, result->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0); 
+    if (error != 0){
+        fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
+    }
+    if (*hostname != '\0'){
+//      printf("%s\n", hostname);
+        execl("/usr/lib/nagios/plugins/check_ldaps", "/usr/lib/nagios/plugins/check_ldaps", "--ssl", "--ver3", "-H", hostname, "--base", argv[2], (char*) 0);
+    } else {
+        return EXIT_FAILURE;
+    }
+    freeaddrinfo(result);
+
+    return EXIT_SUCCESS;
+}
+