From ee38d62a03b1723d666622217147adb5cb790773 Mon Sep 17 00:00:00 2001 From: Michael Howe Date: Sat, 22 Jan 2011 16:45:52 +0000 Subject: [PATCH] Added a check_ldaps_ip plugin to nagios-plugins-local --- Makefile | 12 +++++++++- src/check_ldaps_ip.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/check_ldaps_ip.c diff --git a/Makefile b/Makefile index eb62983..f30f7d2 100644 --- 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 index 0000000..7f0c129 --- /dev/null +++ b/src/check_ldaps_ip.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include + +#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; +} + -- 2.39.5