--------------090809010509050207080301
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi Ethan, list,
I made a patch to make Nagios handle nicely perfdata_file as pipes. What
it does is add a new file mode; i.e.:
host_perfdata_file_mode=p
service_perfdata_file_mode=p
When set to "p", it will use open with O_NONBLOCK | O_RDWR, then fdopen
on the fd, so that the fd will be left with O_NONBLOCK. This will allow
Nagios to open the pipe without blocking even if there's no reader. It
will also avoid loosing data if the reader goes away for a short period
of time (ex. performance data daemon restart)
While testing it I also found out there's a bug in the argument
processing. strstr returns the pointer to the search string. so that
if(!strstr(...)) is like saying if(string not there). The original code
looked like this:
if(!strstr(varvalue,"w"))
xpddefault_host_perfdata_file_append=FALSE;
So I changed that to explicitly check if the value is not NULL. This
explains why with "w" I was seeing O_APPEND from strace
If you accept this patch I'll submit a complete patch including doc and
sample config modifications. I can also backport it to the 2-x branch if
you're willing to accept it.
Thanks,
Thomas
--------------090809010509050207080301
Content-Type: text/x-patch;
name="nagios-3-HEAD.piped-perfdata.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="nagios-3-HEAD.piped-perfdata.patch"
Index: xdata/xpddefault.c
===================================================================
RCS file: /cvsroot/nagios/nagios/xdata/xpddefault.c,v
retrieving revision 1.27
diff -u -r1.27 xpddefault.c
--- xdata/xpddefault.c 6 Mar 2007 13:19:37 -0000 1.27
+++ xdata/xpddefault.c 9 Mar 2007 08:13:51 -0000
@@ -51,6 +51,8 @@
int xpddefault_host_perfdata_file_append=TRUE;
int xpddefault_service_perfdata_file_append=TRUE;
+int xpddefault_host_perfdata_file_pipe=FALSE;
+int xpddefault_service_perfdata_file_pipe=FALSE;
unsigned long xpddefault_host_perfdata_file_processing_interval=0L;
unsigned long xpddefault_service_perfdata_file_processing_interval=0L;
@@ -159,14 +161,18 @@
xpddefault_service_perfdata_file=(char *)strdup(varvalue);
else if(!strcmp(varname,"host_perfdata_file_mode")){
- if(!strstr(varvalue,"w"))
+ if(strstr(varvalue,"p")!=NULL)
+ xpddefault_host_perfdata_file_pipe=TRUE;
+ else if(strstr(varvalue,"w")!=NULL)
xpddefault_host_perfdata_file_append=FALSE;
else
xpddefault_host_perfdata_file_append=TRUE;
}
else if(!strcmp(varname,"service_perfdata_file_mode")){
- if(!strstr(varvalue,"w"))
+ if(strstr(varvalue,"p")!=NULL)
+ xpddefault_service_perfdata_file_pipe=TRUE;
+ else if(strstr(varvalue,"w")!=NULL)
xpddefault_service_perfdata_file_append=FALSE;
else
xpddefault_service_perfdata_file_append=TRUE;
@@ -515,7 +521,13 @@
if(xpddefault_host_perfdata_file!=NULL){
- xpddefault_host_perfdata_fp=fopen(xpddefault_host_perfdata_file,(xpddefault_host_perfdata_file_append==TRUE)?"a":"w");
+ if(xpddefault_host_perfdata_file_pipe==TRUE) {
+ /* must open reaw-write to avoid failure if the other end isn't ready yet */
+ xpddefault_host_perfdata_fp=open(xpddefault_host_perfdata_file,O_NONBLOCK | O_RDWR);
+ xpddefault_host_perfdata_fp=fdopen(xpddefault_host_perfdata_fp,"w");
+ }
+ else
+ xpddefault_host_perfdata_fp=fopen(xpddefault_host_perfdata_file,(xpddefault_host_perfdata_file_append==TRUE)?"a":"w");
if(xpddefault_host_perfdata_fp==NULL){
asprintf(&buffer,"Warning: File '%s' could not be opened - host performance data will not be written to file!\n",xpddefault_host_perfdata_file);
@@ -534,8 +546,13 @@
char *buffer=NULL;
if(xpddefault_service_perfdata_file!=NULL){
-
- xpddefault_service_perfdata_fp=fopen(xpddefault_service_perfdata_file,(xpddefault_service_perfdata_file_append==TRUE)?"a":"w");
+ if(xpddefault_service_perfdata_file_pipe==TRUE) {
+ /* must open reaw-write to avoid failure if the other end isn't ready yet */
+ xpddefault_service_perfdata_fp=open(xpddefault_service_perfdata_file,O_
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]