Modified: trunk/patches/nsca_improved_logging.patch
===================================================================
--- trunk/patches/nsca_improved_logging.patch 2013-07-09 17:11:30 UTC (rev 305)
+++ trunk/patches/nsca_improved_logging.patch 2013-07-10 11:14:21 UTC (rev 306)
@@ -1,11 +1,11 @@
diff -ur nsca-2.7.2.orig/src/nsca.c nsca-2.7.2/src/nsca.c
--- nsca-2.7.2.orig/src/nsca.c 2013-05-07 12:13:45.714595673 +0000
-+++ nsca-2.7.2/src/nsca.c 2013-07-05 08:29:44.214598653 +0000
++++ nsca-2.7.2/src/nsca.c 2013-07-10 11:13:27.974636196 +0000
@@ -292,6 +292,8 @@
do_cleanup();
-+ syslog(LOG_ERR,"Exiting with return code: %u\n",return_code);
++ syslog(LOG_DEBUG,"Exiting with return code: %u\n",return_code);
+
exit(return_code);
}
@@ -19,7 +19,7 @@
#ifdef HAVE_LIBWRAP
struct request_info req;
#endif
-+ struct sockaddr_in cli_addr;
++ struct sockaddr_in cli_addr;
+ int clilen;
+ clilen = sizeof (cli_addr);
@@ -67,7 +67,7 @@
/* log info to syslog facility */
if(debug==TRUE)
- syslog(LOG_DEBUG,"Connection from %s port %d",inet_ntoa(nptr->sin_addr),nptr->sin_port);
-+ syslog(LOG_DEBUG,"Accepting connection from %s port %d",inet_ntoa(cli_addr.sin_addr),cli_addr.sin_port);
++ syslog(LOG_DEBUG,"%s: Accepting connection from remote port %d",inet_ntoa(cli_addr.sin_addr),cli_addr.sin_port);
/* handle the connection */
if(mode==SINGLE_PROCESS_DAEMON)
@@ -81,40 +81,56 @@
return;
}
-@@ -876,11 +863,12 @@
+@@ -876,11 +863,21 @@
int flags;
time_t packet_send_time;
struct crypt_instance *CI;
--
+ struct sockaddr addr;
+ struct sockaddr_in *nptr=data; // client info from original socket connection
++ /* ignore connections where sin_port and sin_addr are null */
++ if(nptr->sin_port==0) {
++ syslog(LOG_DEBUG,"Ignoring connection from %s port %d",inet_ntoa(nptr->sin_addr),nptr->sin_port);
++ close(sock);
++ if(mode==MULTI_PROCESS_DAEMON)
++ do_exit(STATE_CRITICAL);
++ return;
++ }
+
/* log info to syslog facility */
if(debug==TRUE)
- syslog(LOG_INFO,"Handling the connection...");
-+ syslog(LOG_DEBUG,"Handling connection from %s port %d",inet_ntoa(nptr->sin_addr),nptr->sin_port);
++ syslog(LOG_DEBUG,"%s: Handling connection from port %d",inet_ntoa(nptr->sin_addr),nptr->sin_port);
/* socket should be non-blocking */
fcntl(sock,F_GETFL,&flags);
-@@ -905,7 +893,7 @@
+@@ -905,7 +902,7 @@
/* there was an error sending the packet */
if(rc==-1){
- syslog(LOG_ERR,"Could not send init packet to client\n");
-+ syslog(LOG_ERR,"Could not send init packet to client %s on port %d\n",inet_ntoa(nptr->sin_addr),nptr->sin_port);
++ syslog(LOG_ERR,"%s: Could not send init packet to client remote port %d\n",inet_ntoa(nptr->sin_addr),nptr->sin_port);
encrypt_cleanup(decryption_method,CI);
close(sock);
if(mode==MULTI_PROCESS_DAEMON)
-@@ -915,7 +903,7 @@
+@@ -915,7 +912,7 @@
/* for some reason we didn't send all the bytes we were supposed to */
else if(bytes_to_send<sizeof(send_packet)){
- syslog(LOG_ERR,"Only able to send %d of %d bytes of init packet to client\n",rc,sizeof(send_packet));
-+ syslog(LOG_ERR,"Only able to send %d of %lu bytes of init packet to client %s on port %d\n",rc,sizeof(send_packet), inet_ntoa(nptr->sin_addr),nptr->sin_port);
++ syslog(LOG_ERR,"%s: Only able to send %d of %lu bytes of init packet to client remote port %d\n",rc,sizeof(send_packet), inet_ntoa(nptr->sin_addr),nptr->sin_port);
encrypt_cleanup(decryption_method,CI);
close(sock);
if(mode==MULTI_PROCESS_DAEMON)
-@@ -963,6 +951,28 @@
+@@ -926,6 +923,7 @@
+ /* open the command file if we're aggregating writes */
+ if(aggregate_writes==TRUE){
+ if(open_command_file()==ERROR){
++ encrypt_cleanup(decryption_method,CI);
+ close(sock);
+ if(mode==MULTI_PROCESS_DAEMON)
+ do_exit(STATE_CRITICAL);
+@@ -963,7 +961,31 @@
CI=data;
@@ -122,6 +138,8 @@
+ struct sockaddr_in *nptr;
+ socklen_t addrlen;
+
++ syslog(LOG_DEBUG,"Reading data from client connection");
++
+ addrlen=sizeof(addr);
+ rc=getpeername(sock,&addr,&addrlen);
+
@@ -139,61 +157,87 @@
+ }
+ nptr=(struct sockaddr_in *)&addr;
+
-+
/* process all data we get from the client... */
++ syslog(LOG_DEBUG,"%s: Processing data from client", inet_ntoa(nptr->sin_addr));
/* read the packet from the client */
-@@ -972,7 +982,7 @@
+ bytes_to_recv=sizeof(receive_packet);
+@@ -972,7 +994,7 @@
/* recv() error or client disconnect */
if(rc<=0){
if(debug==TRUE)
- syslog(LOG_ERR,"End of connection...");
-+ syslog(LOG_ERR,"End of connection from %s...", inet_ntoa(nptr->sin_addr));
++ syslog(LOG_DEBUG,"%s: End of connection from client...", inet_ntoa(nptr->sin_addr));
encrypt_cleanup(decryption_method, CI);
close(sock);
if(mode==SINGLE_PROCESS_DAEMON)
-@@ -983,7 +993,7 @@
+@@ -983,7 +1005,7 @@
/* we couldn't read the correct amount of data, so bail out */
if(bytes_to_recv!=sizeof(receive_packet)){
- syslog(LOG_ERR,"Data sent from client was too short (%d < %d), aborting...",bytes_to_recv,sizeof(receive_packet));
-+ syslog(LOG_ERR,"Data sent from client %s was too short (%d < %lu), aborting...",inet_ntoa(nptr->sin_addr),bytes_to_recv,sizeof(receive_packet));
++ syslog(LOG_ERR,"%s: Data sent from client was too short (%d < %lu), aborting...",inet_ntoa(nptr->sin_addr),bytes_to_recv,sizeof(receive_packet));
encrypt_cleanup(decryption_method, CI);
close(sock);
return;
-@@ -1002,7 +1012,7 @@
+@@ -1002,7 +1024,7 @@
/* make sure this is the right type of packet */
if(ntohs(receive_packet.packet_version)!=NSCA_PACKET_VERSION_3){
- syslog(LOG_ERR,"Received invalid packet type/version from client - possibly due to client using wrong password or crypto algorithm?");
-+ syslog(LOG_ERR,"Received invalid packet type/version from client %s - possibly due to client using wrong password or crypto algorithm?", inet_ntoa(nptr->sin_addr));
++ syslog(LOG_ERR,"%s: Received invalid packet type/version from client - possibly due to client using wrong password or crypto algorithm?", inet_ntoa(nptr->sin_addr));
/*return;*/
close(sock);
if(mode==SINGLE_PROCESS_DAEMON)
-@@ -1016,7 +1026,7 @@
+@@ -1016,7 +1038,7 @@
receive_packet.crc32_value=0L;
calculated_crc32=calculate_crc32((char *)&receive_packet,sizeof(receive_packet));
if(packet_crc32!=calculated_crc32){
- syslog(LOG_ERR,"Dropping packet with invalid CRC32 - possibly due to client using wrong password or crypto algorithm?");
-+ syslog(LOG_ERR,"Dropping packet with invalid CRC32 - possibly due to client %s using wrong password or crypto algorithm?",inet_ntoa(nptr->sin_addr));
++ syslog(LOG_ERR,"%s: Dropping packet with invalid CRC32 - possibly due to client using wrong password or crypto algorithm?",inet_ntoa(nptr->sin_addr));
/*return;*/
close(sock);
if(mode==SINGLE_PROCESS_DAEMON)
-@@ -1029,7 +1039,7 @@
+@@ -1029,18 +1051,21 @@
packet_time=(time_t)ntohl(receive_packet.timestamp);
time(¤t_time);
if(packet_time>current_time){
- syslog(LOG_ERR,"Dropping packet with future timestamp.");
-+ syslog(LOG_ERR,"Dropping packet with future timestamp from client %s.",inet_ntoa(nptr->sin_addr));
- /*return;*/
- close(sock);
- if(mode==SINGLE_PROCESS_DAEMON)
-@@ -1040,7 +1050,7 @@
+- /*return;*/
+- close(sock);
+- if(mode==SINGLE_PROCESS_DAEMON)
+- return;
+- else
+- do_exit(STATE_OK);
+- }
++ packet_age=(unsigned long)(packet_time-current_time);
++ if(max_packet_age>0 && (packet_age>max_packet_age)){
++ syslog(LOG_ERR,"%s: Dropping packet with future timestamp from client - packaet was %lu seconds in the future",inet_ntoa(nptr->sin_addr), packet_age);
++ /*return;*/
++ close(sock);
++ if(mode==SINGLE_PROCESS_DAEMON)
++ return;
++ else
++ do_exit(STATE_OK);
++ }
++ }
else{
packet_age=(unsigned long)(current_time-packet_time);
if(max_packet_age>0 && (packet_age>max_packet_age)){
- syslog(LOG_ERR,"Dropping packet with stale timestamp - packet was %lu seconds old.",packet_age);
-+ syslog(LOG_ERR,"Dropping packet with stale timestamp from client %s- packet was %lu seconds old.",inet_ntoa(nptr->sin_addr),packet_age);
++ syslog(LOG_ERR,"%s: Dropping packet with stale timestamp from client - packet was %lu seconds old.",inet_ntoa(nptr->sin_addr),packet_age);
/*return;*/
close(sock);
if(mode==SINGLE_PROCESS_DAEMON)
+@@ -1070,9 +1095,9 @@
+ /* log info to syslog facility */
+ if(debug==TRUE){
+ if(!strcmp(svc_description,""))
+- syslog(LOG_NOTICE,"HOST CHECK -> Host Name: '%s', Return Code: '%d', Output: '%s'",host_name,return_code,plugin_output);
++ syslog(LOG_DEBUG,"%s: HOST CHECK -> Host Name: '%s', Return Code: '%d', Output: '%s'",inet_ntoa(nptr->sin_addr),host_name,return_code,plugin_output);
+ else
+- syslog(LOG_NOTICE,"SERVICE CHECK -> Host Name: '%s', Service Description: '%s', Return Code: '%d', Output: '%s'",host_name,svc_description,return_code,plugin_output);
++ syslog(LOG_DEBUG,"%s: SERVICE CHECK -> Host Name: '%s', Service Description: '%s', Return Code: '%d', Output: '%s'",inet_ntoa(nptr->sin_addr),host_name,svc_description,return_code,plugin_output);
+ }
+
+ /* write the check result to the external command file.