Page 1 of 1

[Nagios-devel] Debug Mode Fix for NRPE

Posted: Sat Feb 12, 2005 7:34 am
by Guest
--0-825088695-1108222489=:57271
Content-Type: text/plain; charset=us-ascii
Content-Id:
Content-Disposition: inline

Good morning,
I am doing some work with NRPE and I ran across a
problem with DEBUG mode (the #define DEBUG, not the
debug configuration directive in nrpe.cfg).

If you #define DEBUG 1 and compile you will get a
compile error for an undeclared variable:
nrpe.c: In function `handle_connection':
nrpe.c:788: error: `fp' undeclared (first use in this
function)
nrpe.c:788: error: (Each undeclared identifier is
reported only once
nrpe.c:788: error: for each function it appears in.)

I have fixed this error, and hopefully made the
program more useful by:
1. Declaring FILE pointers for both sending and
receiving NRPE packets
2. Writing the sent and received NRPE packets for both
nrpe and check_nrpe to the filesystem as:
* /tmp/packet-check_nrpe-send
* /tmp/packet-check_nrpe-receive
* /tmp/packet-nrpe-receive
* /tmp/packet-nrpe-send

These files are very useful for helping implement
applications that interoprate with nrpe and
check_nrpe.

Note that the #define DEBUG is not present in any
header files currently, and I did not add it. I have
been testing with #define DEBUG 1 in common.h, though
this is not included in the patch. Perhaps #define
DEBUG 0 should be set in common.h by default.

The attached patch is in unified diff format. This is
my first time preparing a patch with diff (I usually
work within the happy confines of CVS'
tag/branch/merge structure), so if I have left
something out please let me know. You should be able
to apply the patch with:
patch -p 1 -i nrpe_debug.patch

when you are in the root of an nrpe source
distribution/module.

Regards,
Stephen



__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com


--0-825088695-1108222489=:57271
Content-Type: text/x-patch; name="nrpe_debug.patch"
Content-Description: nrpe_debug.patch
Content-Disposition: inline; filename="nrpe_debug.patch"

--- nrpe-2.0-pristine/src/nrpe.c 2003-09-08 19:52:37.000000000 -0700
+++ nrpe-2.0-sniff/src/nrpe.c 2005-02-11 15:28:07.000000000 -0700
@@ -705,6 +705,8 @@
int x;
#ifdef DEBUG
FILE *errfp;
+ FILE *receive_fp;
+ FILE *send_fp;
#endif
#ifdef HAVE_SSL
SSL *ssl=NULL;
@@ -785,10 +787,11 @@
}

#ifdef DEBUG
- fp=fopen("/tmp/packet","w");
- if(fp){
- fwrite(&receive_packet,1,sizeof(receive_packet),fp);
- fclose(fp);
+ /* Record packet as received from network */
+ receive_fp=fopen("/tmp/packet-nrpe-receive","w");
+ if(receive_fp){
+ fwrite(&receive_packet,1,sizeof(receive_packet),receive_fp);
+ fclose(receive_fp);
}
#endif

@@ -914,6 +917,14 @@
calculated_crc32=calculate_crc32((char *)&send_packet,sizeof(send_packet));
send_packet.crc32_value=(u_int32_t)htonl(calculated_crc32);

+#ifdef DEBUG
+ /* Record packet as sent out on network */
+ send_fp=fopen("/tmp/packet-nrpe-send","w");
+ if(send_fp){
+ fwrite(&send_packet,1,sizeof(send_packet),send_fp);
+ fclose(send_fp);
+ }
+#endif

/***** ENCRYPT RESPONSE *****/

--- nrpe-2.0-pristine/src/check_nrpe.c 2003-09-08 19:52:37.000000000 -0700
+++ nrpe-2.0-sniff/src/check_nrpe.c 2005-02-11 15:36:05.000000000 -0700
@@ -61,6 +61,11 @@
packet receive_packet;
int bytes_to_send;
int bytes_to_recv;
+#ifdef DEBUG
+ FILE *receive_fp;
+ FILE *send_fp;
+#endif
+

result=process_arguments(argc,argv);

@@ -174,7 +179,6 @@

/* we're connected and ready to go */
if(result==STATE_OK){
-
/* clear the packet buffer */
bzero(&send_packet,sizeof(send_packet));

@@ -192,10 +196,17 @@
calculated_crc32=calculate_crc32((char *)&send_packet,sizeof(send_packet));
send_packet.crc32_value=(u_int32_t)htonl(calculated_crc32);

+#ifdef DEBUG
+ /* Record packet as sent out on network */
+ send_fp=fopen("/tmp/packet-check_nrpe-send","w");
+ if(send_fp){
+ fwrite(&send_packet,1,sizeof(send_packet),send_fp);
+ fclose(send_fp);
+ }
+#endif

/***** ENCRYPT REQUEST *****/

-
/* send the packet */
bytes_to_send=sizeof(send_packet);
if(use_ssl==FALSE)
@@ -253,6 +264,14 @@
return STATE_UNKNOWN;
}

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]