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

sean finney seanius at seanius.net
Mon Dec 11 10:08:12 CET 2006


hi ric,

thanks for the info.  i've been aware of this problem for a bit via the
debian bts, but the original patch i was given caused more problems than
it solved.  this patch looks much better, i'll check it out.


thanks,
	sean

On Sat, 2006-12-09 at 08:31 -0700, Ric Anderson wrote:
> 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.
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________________
> Nagios Plugin Development Mailing List Nagiosplug-devel at lists.sourceforge.net
> Unsubscribe at https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
> ::: Please include plugins version (-v) and OS when reporting any issue. 
> ::: Messages without supporting info will risk being sent to /dev/null
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20061211/e6297be5/attachment.sig>


More information about the Devel mailing list