We have moved to Git. This repository is only provided for compatibility with old installations. Learn how to migrate your installation here.

comparison net-analyzer/nrpe/files/nrpe-2.14-multiline.patch @ 54:90a7a9dbfafb

importing net-analyzer/nrpe-2.14 from official portage tree
author Daniel Neugebauer <dneuge@energiequant.de>
date Mon, 17 Mar 2014 16:09:30 +0100
parents
children
comparison
equal deleted inserted replaced
53:5cc622037103 54:90a7a9dbfafb
1 Add support for large output
2
3 http://opsview-blog.opsera.com/dotorg/2008/08/enhancing-nrpe.htmlIndex: nrpe-2.14/include/common.h
4 ===================================================================
5 Index: nrpe-2.14/include/common.h
6 ===================================================================
7 --- nrpe-2.14.orig/include/common.h
8 +++ nrpe-2.14/include/common.h
9 @@ -41,7 +41,7 @@
10 #define DEFAULT_SOCKET_TIMEOUT 10 /* timeout after 10 seconds */
11 #define DEFAULT_CONNECTION_TIMEOUT 300 /* timeout if daemon is waiting for connection more than this time */
12
13 -#define MAX_INPUT_BUFFER 2048 /* max size of most buffers we use */
14 +#define MAX_INPUT_BUFFER 16384 /* max size of most buffers we use */
15 #define MAX_FILENAME_LENGTH 256
16
17 #define MAX_HOST_ADDRESS_LENGTH 256 /* max size of a host address */
18 @@ -55,12 +55,14 @@
19
20 #define QUERY_PACKET 1 /* id code for a packet containing a query */
21 #define RESPONSE_PACKET 2 /* id code for a packet containing a response */
22 +#define RESPONSE_PACKET_WITH_MORE 3 /* id code for a packet containing a response, with more data to follow */
23
24 #define NRPE_PACKET_VERSION_3 3 /* packet version identifier */
25 #define NRPE_PACKET_VERSION_2 2
26 #define NRPE_PACKET_VERSION_1 1 /* older packet version identifiers (no longer supported) */
27
28 #define MAX_PACKETBUFFER_LENGTH 1024 /* max amount of data we'll send in one query/response */
29 + /* WARNING - do not change this as older clients/servers will not work */
30
31 typedef struct packet_struct{
32 int16_t packet_version;
33 Index: nrpe-2.14/src/check_nrpe.c
34 ===================================================================
35 --- nrpe-2.14.orig/src/check_nrpe.c
36 +++ nrpe-2.14/src/check_nrpe.c
37 @@ -221,6 +221,11 @@ int main(int argc, char **argv){
38 return STATE_UNKNOWN;
39 }
40
41 + /* Altinity patch: Allow multiple packets to be received */
42 + /* Indentation not corrected to allow simpler patching */
43 + /* START MULTI_PACKET LOOP */
44 + do {
45 +
46 /* wait for the response packet */
47 bytes_to_recv=sizeof(receive_packet);
48 if(use_ssl==FALSE)
49 @@ -233,31 +238,24 @@ int main(int argc, char **argv){
50 /* reset timeout */
51 alarm(0);
52
53 - /* close the connection */
54 -#ifdef HAVE_SSL
55 - if(use_ssl==TRUE){
56 - SSL_shutdown(ssl);
57 - SSL_free(ssl);
58 - SSL_CTX_free(ctx);
59 - }
60 -#endif
61 - graceful_close(sd,1000);
62 -
63 /* recv() error */
64 if(rc<0){
65 printf("CHECK_NRPE: Error receiving data from daemon.\n");
66 + graceful_close(sd,1000);
67 return STATE_UNKNOWN;
68 }
69
70 /* server disconnected */
71 else if(rc==0){
72 printf("CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.\n");
73 + graceful_close(sd,1000);
74 return STATE_UNKNOWN;
75 }
76
77 /* receive underflow */
78 else if(bytes_to_recv<sizeof(receive_packet)){
79 printf("CHECK_NRPE: Receive underflow - only %d bytes received (%d expected).\n",bytes_to_recv,sizeof(receive_packet));
80 + graceful_close(sd,1000);
81 return STATE_UNKNOWN;
82 }
83
84 @@ -271,21 +269,21 @@ int main(int argc, char **argv){
85 calculated_crc32=calculate_crc32((char *)&receive_packet,sizeof(receive_packet));
86 if(packet_crc32!=calculated_crc32){
87 printf("CHECK_NRPE: Response packet had invalid CRC32.\n");
88 - close(sd);
89 + graceful_close(sd,1000);
90 return STATE_UNKNOWN;
91 }
92
93 /* check packet version */
94 if(ntohs(receive_packet.packet_version)!=NRPE_PACKET_VERSION_2){
95 printf("CHECK_NRPE: Invalid packet version received from server.\n");
96 - close(sd);
97 + graceful_close(sd,1000);
98 return STATE_UNKNOWN;
99 }
100
101 /* check packet type */
102 - if(ntohs(receive_packet.packet_type)!=RESPONSE_PACKET){
103 + if(ntohs(receive_packet.packet_type)!=RESPONSE_PACKET && ntohs(receive_packet.packet_type)!=RESPONSE_PACKET_WITH_MORE){
104 printf("CHECK_NRPE: Invalid packet type received from server.\n");
105 - close(sd);
106 + graceful_close(sd,1000);
107 return STATE_UNKNOWN;
108 }
109
110 @@ -297,8 +295,18 @@ int main(int argc, char **argv){
111 if(!strcmp(receive_packet.buffer,""))
112 printf("CHECK_NRPE: No output returned from daemon.\n");
113 else
114 - printf("%s\n",receive_packet.buffer);
115 - }
116 + printf("%s",receive_packet.buffer);
117 +
118 + } while (ntohs(receive_packet.packet_type)==RESPONSE_PACKET_WITH_MORE);
119 + /* END MULTI_PACKET LOOP */
120 +
121 + /* Finish output with newline */
122 + printf("\n");
123 +
124 + /* close the connection */
125 + graceful_close(sd,1000);
126 +
127 + }
128
129 /* reset the alarm */
130 else
131 @@ -434,6 +442,14 @@ int graceful_close(int sd, int timeout){
132 struct timeval tv;
133 char buf[1000];
134
135 +#ifdef HAVE_SSL
136 + if(use_ssl==TRUE){
137 + SSL_shutdown(ssl);
138 + SSL_free(ssl);
139 + SSL_CTX_free(ctx);
140 + }
141 +#endif
142 +
143 /* send FIN packet */
144 shutdown(sd,SHUT_WR);
145 for(;;){
146 Index: nrpe-2.14/src/nrpe.c
147 ===================================================================
148 --- nrpe-2.14.orig/src/nrpe.c
149 +++ nrpe-2.14/src/nrpe.c
150 @@ -1056,6 +1056,8 @@ void handle_connection(int sock){
151 char processed_command[MAX_INPUT_BUFFER];
152 int result=STATE_OK;
153 int early_timeout=FALSE;
154 + int bytes_copied=0;
155 + char *pbuffer=&buffer[0];
156 int rc;
157 int x;
158 #ifdef DEBUG
159 @@ -1272,6 +1274,14 @@ void handle_connection(int sock){
160 if(buffer[strlen(buffer)-1]=='\n')
161 buffer[strlen(buffer)-1]='\x0';
162
163 + /* Altinity patch to allow multi packet responses */
164 + /* Loop not indented to allow easier patching */
165 + /* START MULTI_PACKET LOOP */
166 + do {
167 +
168 + if(debug==TRUE)
169 + syslog(LOG_DEBUG,"Sending response - bytes left: %d", strlen(pbuffer));
170 +
171 /* clear the response packet buffer */
172 bzero(&send_packet,sizeof(send_packet));
173
174 @@ -1280,11 +1290,17 @@ void handle_connection(int sock){
175
176 /* initialize response packet data */
177 send_packet.packet_version=(int16_t)htons(NRPE_PACKET_VERSION_2);
178 - send_packet.packet_type=(int16_t)htons(RESPONSE_PACKET);
179 send_packet.result_code=(int16_t)htons(result);
180 - strncpy(&send_packet.buffer[0],buffer,MAX_PACKETBUFFER_LENGTH);
181 + strncpy(&send_packet.buffer[0],pbuffer,MAX_PACKETBUFFER_LENGTH);
182 send_packet.buffer[MAX_PACKETBUFFER_LENGTH-1]='\x0';
183 -
184 +
185 + bytes_copied = strlen(&send_packet.buffer[0]);
186 + pbuffer = pbuffer+bytes_copied;
187 + if(strlen(pbuffer)>0)
188 + send_packet.packet_type=(int16_t)htons(RESPONSE_PACKET_WITH_MORE);
189 + else
190 + send_packet.packet_type=(int16_t)htons(RESPONSE_PACKET);
191 +
192 /* calculate the crc 32 value of the packet */
193 send_packet.crc32_value=(u_int32_t)0L;
194 calculated_crc32=calculate_crc32((char *)&send_packet,sizeof(send_packet));
195 @@ -1303,6 +1319,9 @@ void handle_connection(int sock){
196 SSL_write(ssl,&send_packet,bytes_to_send);
197 #endif
198
199 + } while (strlen(pbuffer) > 0);
200 + /* END MULTI_PACKET LOOP */
201 +
202 #ifdef HAVE_SSL
203 if(ssl){
204 complete_SSL_shutdown( ssl);