[Nagiosplug-devel] check_ups causes disconnect errors (nagios-plugins-HEAD-200612091252)

Ric Anderson ric at DragonElf.NET
Sat Dec 9 16:31:29 CET 2006


When check_ups (either the one from plugins 1.4.3, or the one from
nagios-plugins-HEAD-200612091252) is used, NUT's upsd logs
 Dec  9 08:06:22 moose upsd[5136]: Host 127.0.0.1 disconnected (read failure)
This is because of a protocol botch in talking to upsd, which expects
to get a "LOGOUT\n" before the socket is closed.  check_ups uses the
normal process_tcp_request which doesn't send the "LOGOUT\n", but
does close the socket.

The patch below is based on
  nagios-plugins-HEAD-200612091252/plugins/check_ups.c
and fixes this problem by having check_ups do a little more work itself.

FWIW,
Ric
--
--- check_ups.c.orig	2006-10-19 16:53:28.000000000 -0700
+++ check_ups.c	2006-12-09 08:26:03.000000000 -0700
@@ -98,6 +98,8 @@
 int get_ups_variable (const char *, char *, size_t);
 
 int process_arguments (int, char **);
+int talk2nut( const char *, int , const char *, char *, int);
+
 int validate_arguments (void);
 void print_help (void);
 void print_usage (void);
@@ -405,7 +407,7 @@
 	sprintf (send_buffer, "GET VAR %s %s\n", ups_name, varname);
 
 	/* send the command to the daemon and get a response back */
-	if (process_tcp_request
+	if (talk2nut
 			(server_address, server_port, send_buffer, temp_buffer,
 			 sizeof (temp_buffer)) != STATE_OK) {
 		printf ("%s\n", _("Invalid response received from host"));
@@ -653,3 +655,24 @@
   printf (_("Usage:"));
 	printf ("%s -H host -u ups [-p port] [-v variable] [-w warn_value] [-c crit_value] [-to to_sec] [-T]\n", progname);
 }
+
+int 
+talk2nut(const char *server_address, int server_port,
+ const char *send_buffer, char *recv_buffer, int recv_size)
+{ char buf[32];
+  int result;
+  int sd;
+ 
+  result = np_net_connect(server_address, server_port, &sd,
+   IPPROTO_TCP);
+  if(result != STATE_OK)
+   return STATE_CRITICAL;
+  result = send_request(sd, IPPROTO_TCP, send_buffer, recv_buffer,
+   recv_size);
+  if(result == STATE_OK) {
+    strcpy(buf,"LOGOUT\n");
+    (void) send(sd, buf, strlen(buf), 0);
+  }
+  close(sd);
+  return(result);
+}
--
Ric Anderson, Opus One Systems, 1404 E Lind Road, Tucson, AZ 85719
Phone: +1 520 324 0494 (v) +1 520 324 0495 FAX
ric at Opus1.COM (RA90-ARIN)  Personal Email: ric at DragonElf.NET
UNIX *is* user friendly. It's just selective about who its friends are.




More information about the Devel mailing list