summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e01c91d)
raw | patch | inline | side by side (parent: e01c91d)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Thu, 17 Apr 2003 05:36:20 +0000 (05:36 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Thu, 17 Apr 2003 05:36:20 +0000 (05:36 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@495 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_dig.c | patch | blob | history | |
plugins/check_tcp.c | patch | blob | history | |
plugins/netutils.c | patch | blob | history |
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index 8eb2b9b3230e92013cceba79acde5c42f40c7099..f80a9dc2f145caec6c6eb265fe481e616fe6bf49 100644 (file)
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
-/******************************************************************************
- *
- * Program: SNMP plugin for Nagios
- * License: GPL
- *
- * License Information:
- *
- * 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *****************************************************************************/
+/*****************************************************************************
+*
+* 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, write to the Free Software
+* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*
+*****************************************************************************/
+
+const char *progname = "check_dig";
+const char *revision = "$Revision$";
+const char *copyright = "2002-2003";
+const char *authors = "Nagios Plugin Development Team";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
+const char *summary = "Test the DNS service on the specified host using dig\n";
+
+const char *option_summary = "-H host -l lookup [-t timeout] [-v]";
+
+const char *options = "\
+ -H, --hostname=STRING or IPADDRESS\n\
+ Check server on the indicated host\n\
+ -l, --lookup=STRING\n\
+ machine name to lookup\n\
+ -t, --timeout=INTEGER\n\
+ Seconds before connection attempt times out (default: %d)\n\
+ -v, --verbose\n\
+ Print extra information (command-line use only)\n\
+ -h, --help\n\
+ Print detailed help screen\n\
+ -V, --version\n\
+ Print version information\n\n";
#include "config.h"
#include "common.h"
#include "utils.h"
#include "popen.h"
-const char *progname = "check_dig";
-#define REVISION "$Revision$"
-#define COPYRIGHT "2000-2002"
-#define AUTHOR "Karl DeBisschop"
-#define EMAIL "karl@debisschop.net"
-#define SUMMARY "Test the DNS service on the specified host using dig\n"
-
int process_arguments (int, char **);
int validate_arguments (void);
void print_help (void);
}
}
else {
- asprintf (&dns_server, "127.0.0.1");
+ dns_server = strdup ("127.0.0.1");
}
}
void
print_help (void)
{
- print_revision (progname, "$Revision$");
+ print_revision (progname, revision);
printf
("Copyright (c) %s %s <%s>\n\n%s\n",
- COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
+ copyright, authors, email, summary);
print_usage ();
- printf
- ("\nOptions:\n"
- " -H, --hostname=STRING or IPADDRESS\n"
- " Check server on the indicated host\n"
- " -l, --lookup=STRING\n"
- " machine name to lookup\n"
- " -t, --timeout=INTEGER\n"
- " Seconds before connection attempt times out (default: %d)\n"
- " -v, --verbose\n"
- " Print extra information (command-line use only)\n"
- " -h, --help\n"
- " Print detailed help screen\n"
- " -V, --version\n"
- " Print version information\n\n", DEFAULT_SOCKET_TIMEOUT);
+ printf ("\nOptions:\n");
+ printf (options, DEFAULT_SOCKET_TIMEOUT);
support ();
}
void
print_usage (void)
{
- printf
- ("Usage: %s -H host -l lookup [-t timeout] [-v]\n"
- " %s --help\n"
- " %s --version\n", progname, progname, progname);
+ printf ("Usage: %s %s\n", progname, option_summary);
+ printf (" %s (-h|--help)\n", progname);
+ printf (" %s (-V|--version)\n", progname);
}
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index 5bec2915108cb52f66a44cc5b954791cce462a63..62efc8c7e4bd80e730424677f071d42792eab868 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
-/******************************************************************************
+/*****************************************************************************
*
* 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
-r, --refuse=ok|warn|crit\n\
Accept tcp refusals with states ok, warn, crit (default: crit)\n\
-v\n\
- Show details for command-line debugging (do not use with nagios server)\n\
+ Show details for command-line debugging (do not use with nagios server)\n";
+
+const char *standard_options = "\
-h, --help\n\
Print detailed help screen\n\
-V, --version\n\
#include "utils.h"
#ifdef HAVE_SSL_H
-#include <rsa.h>
-#include <crypto.h>
-#include <x509.h>
-#include <pem.h>
-#include <ssl.h>
-#include <err.h>
-#endif
-
-#ifdef HAVE_OPENSSL_SSL_H
-#include <openssl/rsa.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
+# include <rsa.h>
+# include <crypto.h>
+# include <x509.h>
+# include <pem.h>
+# include <ssl.h>
+# include <err.h>
+#else
+# ifdef HAVE_OPENSSL_SSL_H
+# include <openssl/rsa.h>
+# include <openssl/crypto.h>
+# include <openssl/x509.h>
+# include <openssl/pem.h>
+# include <openssl/ssl.h>
+# include <openssl/err.h>
+# endif
#endif
#ifdef HAVE_SSL
struct timeval tv;
if (strstr (argv[0], "check_udp")) {
- asprintf (&progname, "check_udp");
- asprintf (&SERVICE, "UDP");
+ progname = strdup ("check_udp");
+ SERVICE = strdup ("UDP");
SEND = NULL;
EXPECT = NULL;
QUIT = NULL;
PORT = 0;
}
else if (strstr (argv[0], "check_tcp")) {
- asprintf (&progname, "check_tcp");
- asprintf (&SERVICE, "TCP");
+ progname = strdup ("check_tcp");
+ SERVICE = strdup ("TCP");
SEND = NULL;
EXPECT = NULL;
QUIT = NULL;
PORT = 0;
}
else if (strstr (argv[0], "check_ftp")) {
- asprintf (&progname, "check_ftp");
- asprintf (&SERVICE, "FTP");
+ progname = strdup ("check_ftp");
+ SERVICE = strdup ("FTP");
SEND = NULL;
- asprintf (&EXPECT, "220");
- asprintf (&QUIT, "QUIT\r\n");
+ EXPECT = strdup ("220");
+ QUIT = strdup ("QUIT\r\n");
PROTOCOL = TCP_PROTOCOL;
PORT = 21;
}
else if (strstr (argv[0], "check_smtp")) {
- asprintf (&progname, "check_smtp");
- asprintf (&SERVICE, "SMTP");
+ progname = strdup ("check_smtp");
+ SERVICE = strdup ("SMTP");
SEND = NULL;
- asprintf (&EXPECT, "220");
- asprintf (&QUIT, "QUIT\r\n");
+ EXPECT = strdup ("220");
+ QUIT = strdup ("QUIT\r\n");
PROTOCOL = TCP_PROTOCOL;
PORT = 25;
}
else if (strstr (argv[0], "check_pop")) {
- asprintf (&progname, "check_pop");
- asprintf (&SERVICE, "POP");
+ progname = strdup ("check_pop");
+ SERVICE = strdup ("POP");
SEND = NULL;
- asprintf (&EXPECT, "+OK");
- asprintf (&QUIT, "QUIT\r\n");
+ EXPECT = strdup ("+OK");
+ QUIT = strdup ("QUIT\r\n");
PROTOCOL = TCP_PROTOCOL;
PORT = 110;
}
else if (strstr (argv[0], "check_imap")) {
- asprintf (&progname, "check_imap");
- asprintf (&SERVICE, "IMAP");
+ progname = strdup ("check_imap");
+ SERVICE = strdup ("IMAP");
SEND = NULL;
- asprintf (&EXPECT, "* OK");
- asprintf (&QUIT, "a1 LOGOUT\r\n");
+ EXPECT = strdup ("* OK");
+ QUIT = strdup ("a1 LOGOUT\r\n");
PROTOCOL = TCP_PROTOCOL;
PORT = 143;
}
#ifdef HAVE_SSL
else if (strstr(argv[0],"check_simap")) {
- asprintf (&progname, "check_simap");
- asprintf (&SERVICE, "SIMAP");
+ progname = strdup ("check_simap");
+ SERVICE = strdup ("SIMAP");
SEND=NULL;
- asprintf (&EXPECT, "* OK");
- asprintf (&QUIT, "a1 LOGOUT\r\n");
+ EXPECT = strdup ("* OK");
+ QUIT = strdup ("a1 LOGOUT\r\n");
PROTOCOL=TCP_PROTOCOL;
use_ssl=TRUE;
PORT=993;
}
else if (strstr(argv[0],"check_spop")) {
- asprintf (&progname, "check_spop");
- asprintf (&SERVICE, "SPOP");
+ progname = strdup ("check_spop");
+ SERVICE = strdup ("SPOP");
SEND=NULL;
- asprintf (&EXPECT, "+OK");
- asprintf (&QUIT, "QUIT\r\n");
+ EXPECT = strdup ("+OK");
+ QUIT = strdup ("QUIT\r\n");
PROTOCOL=TCP_PROTOCOL;
use_ssl=TRUE;
PORT=995;
}
#endif
else if (strstr (argv[0], "check_nntp")) {
- asprintf (&progname, "check_nntp");
- asprintf (&SERVICE, "NNTP");
+ progname = strdup ("check_nntp");
+ SERVICE = strdup ("NNTP");
SEND = NULL;
EXPECT = NULL;
server_expect = realloc (server_expect, ++server_expect_count);
usage ("ERROR: Generic check_tcp called with unknown service\n");
}
- asprintf (&server_address, "127.0.0.1");
+ server_address = strdup ("127.0.0.1");
server_port = PORT;
server_send = SEND;
server_quit = QUIT;
}
}
- if (server_quit != NULL)
+ if (server_quit != NULL) {
#ifdef HAVE_SSL
if (use_ssl) {
- SSL_write (ssl, QUIT, strlen (QUIT));
+ SSL_write (ssl, server_quit, strlen (server_quit));
SSL_shutdown (ssl);
SSL_free (ssl);
SSL_CTX_free (ctx);
}
- else
+ else {
+#endif
+ send (sd, server_quit, strlen (server_quit), 0);
+#ifdef HAVE_SSL
+ }
#endif
- send (sd, server_quit, strlen (server_quit), 0);
+ }
/* close the connection */
if (sd)
void
print_help (void)
{
- print_revision (progname, revision);
- printf ("Copyright (c) %s %s\n\t<%s>\n\n",
- copyright, authors, email);
+ print_revision (progname, revision);
+ printf ("Copyright (c) %s %s\n\t<%s>\n\n",
+ copyright, authors, email);
printf (summary, SERVICE);
- print_usage ();
- printf ("\nOptions:\n");
- printf (options, DEFAULT_SOCKET_TIMEOUT);
- support ();
+ print_usage ();
+ printf ("\nOptions:\n");
+ printf (options, DEFAULT_SOCKET_TIMEOUT);
+ printf (standard_options);
+ support ();
}
void
print_usage (void)
{
- printf
- ("Usage: %s %s\n"
- " %s (-h|--help)\n"
- " %s (-V|--version)\n", progname, option_summary, progname, progname);
+ printf ("Usage: %s %s\n", progname, option_summary);
+ printf (" %s (-h|--help)\n", progname);
+ printf (" %s (-V|--version)\n", progname);
}
#ifdef HAVE_SSL
diff --git a/plugins/netutils.c b/plugins/netutils.c
index ce8b428b2ec8009680c8d36f980bb8e3e2a9d425..926547e4ebe6387e8454fa8972a623944a340117 100644 (file)
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
void
socket_timeout_alarm_handler (int sig)
{
-
- printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout);
+ if (sig == SIGALRM)
+ printf ("CRITICAL - Socket timeout after %d seconds\n", socket_timeout);
+ else
+ printf ("CRITICAL - Abnormal timeout after %d seconds\n", socket_timeout);
exit (STATE_CRITICAL);
}
return STATE_CRITICAL;
send_result = send (sd, send_buffer, strlen (send_buffer), 0);
- if (send_result != strlen (send_buffer)) {
+ if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
printf ("send() failed\n");
result = STATE_WARNING;
}
return STATE_CRITICAL;
send_result = send (sd, send_buffer, strlen (send_buffer), 0);
- if (send_result != strlen (send_buffer)) {
+ if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
printf ("send() failed\n");
result = STATE_WARNING;
}
{
struct addrinfo hints;
struct addrinfo *res;
- struct addrinfo *ptrp;
char port_str[6];
int result;
while (res) {
/* attempt to create a socket */
*sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
- SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
+ SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
if (*sd < 0) {
printf ("Socket creation failed\n");
if (result < 0) {
switch (errno) {
- case ECONNREFUSED:
- switch (econn_refuse_state) {
- case STATE_OK:
- case STATE_WARNING:
- was_refused = TRUE;
- }
- break;
+ case ECONNREFUSED:
+ switch (econn_refuse_state) {
+ case STATE_OK:
+ case STATE_WARNING:
+ was_refused = TRUE;
+ }
+ break;
}
}
int
is_host (char *address)
{
- if (is_addr (address) || is_hostname (address))
- return (TRUE);
+ if (is_addr (address) || is_hostname (address))
+ return (TRUE);
- return (FALSE);
+ return (FALSE);
}
int
is_addr (char *address)
{
+ if (is_inet_addr (address))
+ return (TRUE);
+
#ifdef USE_IPV6
- if (is_inet_addr (address) || is_inet6_addr (address))
-#else
- if (is_inet_addr (address))
+ if (is_inet6_addr (address))
+ return (TRUE);
#endif
- return (TRUE);
- return (FALSE);
+ return (FALSE);
}
int
resolve_host_or_addr (char *address, int family)
{
- struct addrinfo hints;
- struct addrinfo *res;
- int retval;
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_family = family;
- retval = getaddrinfo (address, NULL, &hints, &res);
-
- if (retval != 0)
- return FALSE;
- else {
- freeaddrinfo (res);
- return TRUE;
- }
+ struct addrinfo hints;
+ struct addrinfo *res;
+ int retval;
+
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_family = family;
+ retval = getaddrinfo (address, NULL, &hints, &res);
+
+ if (retval != 0)
+ return FALSE;
+ else {
+ freeaddrinfo (res);
+ return TRUE;
+ }
}
int
is_inet_addr (char *address)
{
- return resolve_host_or_addr (address, AF_INET);
+ return resolve_host_or_addr (address, AF_INET);
}
#ifdef USE_IPV6
int
is_inet6_addr (char *address)
{
- return resolve_host_or_addr (address, AF_INET6);
+ return resolve_host_or_addr (address, AF_INET6);
}
#endif
is_hostname (char *s1)
{
#ifdef USE_IPV6
- return resolve_host_or_addr (s1, AF_UNSPEC);
+ return resolve_host_or_addr (s1, AF_UNSPEC);
#else
- return resolve_host_or_addr (s1, AF_INET);
+ return resolve_host_or_addr (s1, AF_INET);
#endif
}