summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5316da0)
raw | patch | inline | side by side (parent: 5316da0)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sun, 29 Feb 2004 04:09:34 +0000 (04:09 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sun, 29 Feb 2004 04:09:34 +0000 (04:09 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@831 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_nwstat.c | patch | blob | history | |
plugins/netutils.c | patch | blob | history | |
plugins/netutils.h | patch | blob | history |
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index 4ceb58fcc8770372be3264ec1147f78c29cdea5e..dc8ce2104b6f7f76526117b5eb9847ac5e429847 100644 (file)
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
int
main(int argc, char **argv) {
int result;
+ int sd;
char *send_buffer=NULL;
char recv_buffer[MAX_INPUT_BUFFER];
char *output_message=NULL;
/* set socket timeout */
alarm(socket_timeout);
-
+
+ /* open connection */
+ my_tcp_connect (server_address, server_port, &sd);
+
/* get OS version string */
if (check_netware_version==TRUE) {
send_buffer = strdup ("S19\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
if (!strcmp(recv_buffer,"-1\n"))
}
asprintf (&send_buffer,"UTIL%s\r\n",temp_buffer);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
utilization=strtoul(recv_buffer,NULL,10);
send_buffer = strdup ("UPTIME\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
recv_buffer[strlen(recv_buffer)-1]=0;
} else if (vars_to_check==CONNS) {
send_buffer = strdup ("CONNECT\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
current_connections=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==LTCH) {
send_buffer = strdup ("S1\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
cache_hits=atoi(recv_buffer);
} else if (vars_to_check==CBUFF) {
send_buffer = strdup ("S2\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
cache_buffers=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==CDBUFF) {
send_buffer = strdup ("S3\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
cache_buffers=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==LRUM) {
send_buffer = strdup ("S5\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
lru_time=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==VKF) {
asprintf (&send_buffer,"VKF%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==VPF) {
asprintf (&send_buffer,"VKF%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
free_disk_space=strtoul(recv_buffer,NULL,10);
asprintf (&send_buffer,"VKS%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
total_disk_space=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==DSDB) {
send_buffer = strdup ("S11\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
if (atoi(recv_buffer)==1)
result=STATE_WARNING;
send_buffer = strdup ("S13\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
temp_buffer=strtok(recv_buffer,"\r\n");
asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer);
} else if (vars_to_check==LOGINS) {
send_buffer = strdup ("S12\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
if (atoi(recv_buffer)==1)
} else if (vars_to_check==UPRB || vars_to_check==PUPRB) {
asprintf (&send_buffer,"S15\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
used_packet_receive_buffers=atoi(recv_buffer);
asprintf (&send_buffer,"S16\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
asprintf (&send_buffer,"S9\r\n");
else
asprintf (&send_buffer,"S9.%d\r\n",sap_number);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==VKP) {
asprintf (&send_buffer,"VKP%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==VPP) {
asprintf (&send_buffer,"VKP%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
purgeable_disk_space=strtoul(recv_buffer,NULL,10);
asprintf (&send_buffer,"VKS%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
total_disk_space=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==VKNP) {
asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==VPNP) {
asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
asprintf (&send_buffer,"VKS%s\r\n",volume_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
total_disk_space=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==OFILES) {
asprintf (&send_buffer,"S18\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==ABENDS) {
asprintf (&send_buffer,"S17\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==CSPROCS) {
asprintf (&send_buffer,"S20\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
max_service_processes=atoi(recv_buffer);
asprintf (&send_buffer,"S21\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==TSYNC) {
asprintf (&send_buffer,"S22\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==LRUS) {
send_buffer = strdup ("S4\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
lru_time=strtoul(recv_buffer,NULL,10);
} else if (vars_to_check==DCB) {
send_buffer = strdup ("S6\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
dirty_cache_buffers=atoi(recv_buffer);
} else if (vars_to_check==TCB) {
send_buffer = strdup ("S7\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
total_cache_buffers=atoi(recv_buffer);
} else if (vars_to_check==DSVER) {
asprintf (&send_buffer,"S13\r\n");
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
asprintf (&output_message,_("NDS Version %s"),recv_buffer);
} else if (vars_to_check==UPTIME) {
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
} else if (vars_to_check==NLM) {
asprintf (&send_buffer,"S24:%s\r\n",nlm_name);
- result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
+ result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
if (result!=STATE_OK)
return result;
}
+ close (sd);
+
/* reset timeout */
alarm(0);
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 55f02cadd62b57a32b341c7d2b823d6ff55e7fac..5017eb9e9651fe754aadc4473b7cd82b213d8bdb 100644 (file)
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
const char *send_buffer, char *recv_buffer, int recv_size)
{
int result;
- int send_result;
- int recv_result;
int sd;
- struct timeval tv;
- fd_set readfds;
result = STATE_OK;
if (result != STATE_OK)
return STATE_CRITICAL;
- send_result = send (sd, send_buffer, strlen (send_buffer), 0);
- if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
- printf ("send() failed\n");
- result = STATE_WARNING;
- }
-
- /* wait up to the number of seconds for socket timeout minus one
- for data from the host */
- tv.tv_sec = socket_timeout - 1;
- tv.tv_usec = 0;
- FD_ZERO (&readfds);
- FD_SET (sd, &readfds);
- select (sd + 1, &readfds, NULL, NULL, &tv);
-
- /* make sure some data has arrived */
- if (!FD_ISSET (sd, &readfds)) {
- strcpy (recv_buffer, "");
- printf ("No data was received from host!\n");
- result = STATE_WARNING;
- }
-
- else {
- recv_result = recv (sd, recv_buffer, (size_t)recv_size - 1, 0);
- if (recv_result == -1) {
- strcpy (recv_buffer, "");
- if (proto != IPPROTO_TCP)
- printf ("recv() failed\n");
- result = STATE_WARNING;
- }
- else
- recv_buffer[recv_result] = 0;
-
- /* die returned string */
- recv_buffer[recv_size - 1] = 0;
- }
+ result = send_request (sd, proto, send_buffer, recv_buffer, recv_size);
close (sd);
}
}
+
+int
+send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
+{
+ return send_request (sd, IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
+}
+
+
+int
+send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
+{
+ return send_request (sd, IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
+}
+
+
+int
+send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size)
+{
+ int result;
+ int send_result;
+ int recv_result;
+ struct timeval tv;
+ fd_set readfds;
+
+ send_result = send (sd, send_buffer, strlen (send_buffer), 0);
+ if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
+ printf ("send() failed\n");
+ result = STATE_WARNING;
+ }
+
+ /* wait up to the number of seconds for socket timeout minus one
+ for data from the host */
+ tv.tv_sec = socket_timeout - 1;
+ tv.tv_usec = 0;
+ FD_ZERO (&readfds);
+ FD_SET (sd, &readfds);
+ select (sd + 1, &readfds, NULL, NULL, &tv);
+
+ /* make sure some data has arrived */
+ if (!FD_ISSET (sd, &readfds)) {
+ strcpy (recv_buffer, "");
+ printf ("No data was received from host!\n");
+ result = STATE_WARNING;
+ }
+
+ else {
+ recv_result = recv (sd, recv_buffer, (size_t)recv_size - 1, 0);
+ if (recv_result == -1) {
+ strcpy (recv_buffer, "");
+ if (proto != IPPROTO_TCP)
+ printf ("recv() failed\n");
+ result = STATE_WARNING;
+ }
+ else
+ recv_buffer[recv_result] = 0;
+
+ /* die returned string */
+ recv_buffer[recv_size - 1] = 0;
+ }
+ return result;
+}
+
+
int
is_host (const char *address)
{
diff --git a/plugins/netutils.h b/plugins/netutils.h
index 88a5162e7082059a45a2ceba271f9b4639fac30d..b2c2a2f5584665e0208207c74ddebaf532d3fff0 100644 (file)
--- a/plugins/netutils.h
+++ b/plugins/netutils.h
int my_tcp_connect (const char *address, int port, int *sd);
int my_udp_connect (const char *address, int port, int *sd);
+int send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
+int send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
+int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
+
int is_host (const char *);
int is_addr (const char *);
int resolve_host_or_addr (const char *, int);