Add support for large output http://opsview-blog.opsera.com/dotorg/2008/08/enhancing-nrpe.htmlIndex: nrpe-2.14/include/common.h =================================================================== Index: nrpe-2.14/include/common.h =================================================================== --- nrpe-2.14.orig/include/common.h +++ nrpe-2.14/include/common.h @@ -41,7 +41,7 @@ #define DEFAULT_SOCKET_TIMEOUT 10 /* timeout after 10 seconds */ #define DEFAULT_CONNECTION_TIMEOUT 300 /* timeout if daemon is waiting for connection more than this time */ -#define MAX_INPUT_BUFFER 2048 /* max size of most buffers we use */ +#define MAX_INPUT_BUFFER 16384 /* max size of most buffers we use */ #define MAX_FILENAME_LENGTH 256 #define MAX_HOST_ADDRESS_LENGTH 256 /* max size of a host address */ @@ -55,12 +55,14 @@ #define QUERY_PACKET 1 /* id code for a packet containing a query */ #define RESPONSE_PACKET 2 /* id code for a packet containing a response */ +#define RESPONSE_PACKET_WITH_MORE 3 /* id code for a packet containing a response, with more data to follow */ #define NRPE_PACKET_VERSION_3 3 /* packet version identifier */ #define NRPE_PACKET_VERSION_2 2 #define NRPE_PACKET_VERSION_1 1 /* older packet version identifiers (no longer supported) */ #define MAX_PACKETBUFFER_LENGTH 1024 /* max amount of data we'll send in one query/response */ + /* WARNING - do not change this as older clients/servers will not work */ typedef struct packet_struct{ int16_t packet_version; Index: nrpe-2.14/src/check_nrpe.c =================================================================== --- nrpe-2.14.orig/src/check_nrpe.c +++ nrpe-2.14/src/check_nrpe.c @@ -221,6 +221,11 @@ int main(int argc, char **argv){ return STATE_UNKNOWN; } + /* Altinity patch: Allow multiple packets to be received */ + /* Indentation not corrected to allow simpler patching */ + /* START MULTI_PACKET LOOP */ + do { + /* wait for the response packet */ bytes_to_recv=sizeof(receive_packet); if(use_ssl==FALSE) @@ -233,31 +238,24 @@ int main(int argc, char **argv){ /* reset timeout */ alarm(0); - /* close the connection */ -#ifdef HAVE_SSL - if(use_ssl==TRUE){ - SSL_shutdown(ssl); - SSL_free(ssl); - SSL_CTX_free(ctx); - } -#endif - graceful_close(sd,1000); - /* recv() error */ if(rc<0){ printf("CHECK_NRPE: Error receiving data from daemon.\n"); + graceful_close(sd,1000); return STATE_UNKNOWN; } /* server disconnected */ else if(rc==0){ printf("CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.\n"); + graceful_close(sd,1000); return STATE_UNKNOWN; } /* receive underflow */ else if(bytes_to_recv0) + send_packet.packet_type=(int16_t)htons(RESPONSE_PACKET_WITH_MORE); + else + send_packet.packet_type=(int16_t)htons(RESPONSE_PACKET); + /* calculate the crc 32 value of the packet */ send_packet.crc32_value=(u_int32_t)0L; calculated_crc32=calculate_crc32((char *)&send_packet,sizeof(send_packet)); @@ -1303,6 +1319,9 @@ void handle_connection(int sock){ SSL_write(ssl,&send_packet,bytes_to_send); #endif + } while (strlen(pbuffer) > 0); + /* END MULTI_PACKET LOOP */ + #ifdef HAVE_SSL if(ssl){ complete_SSL_shutdown( ssl);