[collectd] [PATCH] -- fixes notifications to nagios's named pipe

Ioannis Tambouras ioannistambouras at gmail.com
Sat Jan 21 21:17:44 CET 2017


DESCRIPTION
Nagio is expects that passive checks are send to a named pipe, as indicated
by the 'command_file' variable specided configuration file 'nagios.cnf' --  in my configuration,
I have set it to '/var/nagios/rw/nagios.cmd'.  This must be a named pipe and not a regular file.
All attemps by 'notify_nagios.c' to lseek or lock a named pipe will always fail and  notifications
to nagios will, thus, always fail.

This in undesirable. The patch bellow removes locking and lseek: locking is not needed since
POSIX guarantees that writes of size less than PIPE_BUF are atomic; if write(2) fails, the writer
 must attempt again, which notify_nagios.c will do since it writes using swrite() .
The lseek() call always fails on pipes and becomes a problem since we must write to a pipe.

EXPECTED BEHAVIOR
The <notify_nagios> plugin should be able to notify Nagios via the named pipe designated by Nagios server

PRESENT BEHAVIOR
The <notify_nagios> plugin fails to write to a the named pipe since it assumes it must write to a file


Bellow is the patch that fixes these issues and collectd is now able to notify Nagios. Tested to
work on OSX 10.11.6, collectd-5.7.0, and nagios4 .

 Thanks

Ioannis Tambouras <ioannis at akroninc.net>
Postgres DBA

---
 src/notify_nagios.c | 23 -----------------------
 1 file changed, 23 deletions(-)

diff --git a/src/notify_nagios.c b/src/notify_nagios.c
index c95f7cb..3e2c2bd 100644
--- a/src/notify_nagios.c
+++ b/src/notify_nagios.c
@@ -74,29 +74,6 @@ static int nagios_print(char const *buffer) /* {{{ */
     return status;
   }

-  lock.l_type = F_WRLCK;
-  lock.l_whence = SEEK_END;
-
-  status = fcntl(fd, F_GETLK, &lock);
-  if (status != 0) {
-    char errbuf[1024];
-    status = errno;
-    ERROR("notify_nagios plugin: Failed to acquire write lock on \"%s\": %s",
-          file, sstrerror(status, errbuf, sizeof(errbuf)));
-    close(fd);
-    return status;
-  }
-
-  status = (int)lseek(fd, 0, SEEK_END);
-  if (status == -1) {
-    char errbuf[1024];
-    status = errno;
-    ERROR("notify_nagios plugin: Seeking to end of \"%s\" failed: %s", file,
-          sstrerror(status, errbuf, sizeof(errbuf)));
-    close(fd);
-    return status;
-  }
-
   status = (int)swrite(fd, buffer, strlen(buffer));
   if (status != 0) {
     char errbuf[1024];
--
2.7.4 (Apple Git-66)




More information about the collectd mailing list