mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-03-23 10:53:03 -04:00
- added code to allow check_tcp (via np_net_connect) work with local
unix sockets. some testing would be welcome. based on idea from Alex Samorukov. - also introduced a check_clamd behavior in check_tcp. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1261 f882894a-f735-0410-b71e-b25c423dba1c
This commit is contained in:
parent
ceebd58040
commit
16cd0c8151
9 changed files with 411 additions and 389 deletions
6
COPYING
6
COPYING
|
|
@ -2,7 +2,7 @@
|
|||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
|
@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
|
|||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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
|
||||
|
|
@ -313,7 +313,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
|
|
|||
|
|
@ -533,7 +533,7 @@ dnl
|
|||
AC_HEADER_STDC
|
||||
AC_HEADER_TIME
|
||||
AC_HEADER_SYS_WAIT
|
||||
AC_CHECK_HEADERS(signal.h strings.h string.h syslog.h uio.h errno.h regex.h sys/types.h sys/time.h sys/socket.h sys/loadavg.h)
|
||||
AC_CHECK_HEADERS(signal.h strings.h string.h syslog.h uio.h errno.h regex.h sys/types.h sys/time.h sys/socket.h sys/loadavg.h sys/un.h)
|
||||
AC_CHECK_HEADERS(features.h stdarg.h sys/unistd.h ctype.h stdlib.h)
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ libexec_PROGRAMS = check_disk check_dummy check_http check_load \
|
|||
urlize @EXTRAS@
|
||||
|
||||
check_tcp_programs = check_ftp check_imap check_nntp check_pop \
|
||||
check_udp2 @check_tcp_ssl@
|
||||
check_udp2 check_clamd @check_tcp_ssl@
|
||||
|
||||
EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
|
||||
check_swap check_fping check_ldap check_game check_dig \
|
||||
|
|
|
|||
|
|
@ -177,6 +177,12 @@ main (int argc, char **argv)
|
|||
QUIT = "QUIT\r\n";
|
||||
PORT = 119;
|
||||
}
|
||||
else if (strncmp(SERVICE, "CLAMD", 5)) {
|
||||
SEND = "PING";
|
||||
EXPECT = "PONG";
|
||||
QUIT = NULL;
|
||||
PORT = 3310;
|
||||
}
|
||||
/* fallthrough check, so it's supposed to use reverse matching */
|
||||
else if (strcmp (SERVICE, "TCP"))
|
||||
usage (_("CRITICAL - Generic check_tcp called with unknown service\n"));
|
||||
|
|
@ -318,10 +324,14 @@ main (int argc, char **argv)
|
|||
printf(_("%s %s - "), SERVICE, state_text(result));
|
||||
|
||||
if(match == -2 && len && !(flags & FLAG_HIDE_OUTPUT))
|
||||
printf("Unexpected response from host: %s", status);
|
||||
else
|
||||
printf("%.3f second response time on port %d",
|
||||
elapsed_time, server_port);
|
||||
printf("Unexpected response from host/socket: %s", status);
|
||||
else {
|
||||
printf("%.3f second response time on ", elapsed_time);
|
||||
if(server_address[0] != '/')
|
||||
printf("port %d", server_port);
|
||||
else
|
||||
printf("socket %s", server_address);
|
||||
}
|
||||
|
||||
if (match != -2 && !(flags & FLAG_HIDE_OUTPUT) && len)
|
||||
printf (" [%s]", status);
|
||||
|
|
@ -431,8 +441,6 @@ process_arguments (int argc, char **argv)
|
|||
#endif
|
||||
break;
|
||||
case 'H': /* hostname */
|
||||
if (is_host (optarg) == FALSE)
|
||||
usage2 (_("Invalid hostname/address"), optarg);
|
||||
server_address = optarg;
|
||||
break;
|
||||
case 'c': /* critical */
|
||||
|
|
@ -542,6 +550,8 @@ process_arguments (int argc, char **argv)
|
|||
|
||||
if (server_address == NULL)
|
||||
usage4 (_("You must provide a server address"));
|
||||
else if (is_host (optarg) == FALSE && optarg[0] != '/')
|
||||
usage2 (_("Invalid hostname, address, or socket"), optarg);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -555,7 +565,7 @@ print_help (void)
|
|||
printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
|
||||
printf (COPYRIGHT, copyright, email);
|
||||
|
||||
printf (_("This plugin tests %s connections with the specified host.\n\n"),
|
||||
printf (_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
|
||||
SERVICE);
|
||||
|
||||
print_usage ();
|
||||
|
|
|
|||
|
|
@ -155,42 +155,46 @@ process_request (const char *server_address, int server_port, int proto,
|
|||
}
|
||||
|
||||
|
||||
/* opens a tcp or udp connection to a remote host */
|
||||
/* opens a tcp or udp connection to a remote host or local socket */
|
||||
int
|
||||
np_net_connect (const char *host_name, int port, int *sd, int proto)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *res, *res0;
|
||||
struct addrinfo *r, *res;
|
||||
struct sockaddr_un su;
|
||||
char port_str[6];
|
||||
int result;
|
||||
int socktype, result;
|
||||
|
||||
memset (&hints, 0, sizeof (hints));
|
||||
hints.ai_family = address_family;
|
||||
hints.ai_protocol = proto;
|
||||
hints.ai_socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
|
||||
socktype = (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
|
||||
|
||||
snprintf (port_str, sizeof (port_str), "%d", port);
|
||||
result = getaddrinfo (host_name, port_str, &hints, &res0);
|
||||
/* as long as it doesn't start with a '/', it's assumed a host or ip */
|
||||
if(host_name[0] != '/'){
|
||||
memset (&hints, 0, sizeof (hints));
|
||||
hints.ai_family = address_family;
|
||||
hints.ai_protocol = proto;
|
||||
hints.ai_socktype = socktype;
|
||||
|
||||
if (result != 0) {
|
||||
printf ("%s\n", gai_strerror (result));
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
else {
|
||||
res = res0;
|
||||
while (res) {
|
||||
snprintf (port_str, sizeof (port_str), "%d", port);
|
||||
result = getaddrinfo (host_name, port_str, &hints, &res);
|
||||
|
||||
if (result != 0) {
|
||||
printf ("%s\n", gai_strerror (result));
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
r = res;
|
||||
while (r) {
|
||||
/* attempt to create a socket */
|
||||
*sd = socket (res->ai_family, (proto == IPPROTO_UDP) ?
|
||||
SOCK_DGRAM : SOCK_STREAM, res->ai_protocol);
|
||||
*sd = socket (r->ai_family, socktype, r->ai_protocol);
|
||||
|
||||
if (*sd < 0) {
|
||||
printf (_("Socket creation failed\n"));
|
||||
freeaddrinfo (res);
|
||||
freeaddrinfo (r);
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
/* attempt to open a connection */
|
||||
result = connect (*sd, res->ai_addr, res->ai_addrlen);
|
||||
result = connect (*sd, r->ai_addr, r->ai_addrlen);
|
||||
|
||||
if (result == 0) {
|
||||
was_refused = FALSE;
|
||||
|
|
@ -206,9 +210,25 @@ np_net_connect (const char *host_name, int port, int *sd, int proto)
|
|||
}
|
||||
|
||||
close (*sd);
|
||||
res = res->ai_next;
|
||||
r = r->ai_next;
|
||||
}
|
||||
freeaddrinfo (res0);
|
||||
freeaddrinfo (res);
|
||||
}
|
||||
/* else the hostname is interpreted as a path to a unix socket */
|
||||
else {
|
||||
if(strlen(host_name) >= UNIX_PATH_MAX){
|
||||
die(_("Supplied path too long unix domain socket"));
|
||||
}
|
||||
memset(&su, 0, sizeof(su));
|
||||
su.sun_family = AF_UNIX;
|
||||
strncpy(su.sun_path, host_name, UNIX_PATH_MAX);
|
||||
*sd = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||
if(sd < 0){
|
||||
die(_("Socket creation failed"));
|
||||
}
|
||||
result = connect(*sd, (struct sockaddr *)&su, sizeof(su));
|
||||
if (result < 0 && errno == ECONNREFUSED)
|
||||
was_refused = TRUE;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,14 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
# include <sys/un.h>
|
||||
# ifndef UNIX_PATH_MAX
|
||||
/* linux uses this, on sun it's hard-coded at 108 without a define */
|
||||
# define UNIX_PATH_MAX 108
|
||||
# endif /* UNIX_PATH_MAX */
|
||||
#endif /* HAVE_SYS_UN_H */
|
||||
|
||||
RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
|
||||
|
||||
/* process_request and wrapper macros */
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ char *fperfdata (const char *,
|
|||
|
||||
#define UT_HOST_PORT "\
|
||||
-H, --hostname=ADDRESS\n\
|
||||
Host name or IP Address\n\
|
||||
Host name, IP Address, or unix socket (must be an absolute path)\n\
|
||||
-%c, --port=INTEGER\n\
|
||||
Port number (default: %s)\n"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue