Passive check pipe problem

Jim Mozley jim.mozley at exponential-e.com
Fri Oct 3 12:59:55 CEST 2003


> > > Should I implement some form of locking for the script that writes to
> the
> > > pipe? Or turn my script into a daemon that queues the messages with a
> > > suitable interval between?
> >
> > If you have any two processes trying to frequently write to the same
file,
> > you're going to get this sort of overwrite.
> >
> > Yes, you do want to implement some sort of file locking.  If the scripts
> doing
> > the writing are on the same machine as the command file (not accessed by
> NFS)
> > then a simple flock() call is enough.

> I intend to give flock a
> go (all process run on the same server) and see if this helps things.

Here are my observations of using flock while writing to the external
command named pipe.

Using a simple (only part of script test_nagios.pl):

open(PIPE, "> /usr/local/nagios/var/rw/nagios.cmd") or warn "Cannot open
$!";
flock(PIPE, 2);
print PIPE "[$epoch]
PROCESS_SERVICE_CHECK_RESULT;$host;$service;$nagios_code;Test $status
@message";
close PIPE or warn "Cannot close pipe $!";

and running this script 20 times by something like:

#!/bin/sh
/usr/local/admin/bin/test_nagios.pl down test 1
/usr/local/admin/bin/test_nagios.pl up test 1
/usr/local/admin/bin/test_nagios.pl down test 2
/usr/local/admin/bin/test_nagios.pl up test 2
/usr/local/admin/bin/test_nagios.pl down test 3
/usr/local/admin/bin/test_nagios.pl up test 3
/usr/local/admin/bin/test_nagios.pl down test 4
/usr/local/admin/bin/test_nagios.pl up test 4
/usr/local/admin/bin/test_nagios.pl down test 5
etc.

still produces the problem where a passive check gets seen as part of the
message section of the previous passive check. In fact it was worse than
that, I had up to 5 passive checks seen as one.

However if I use:

open(PIPE, "> /usr/local/nagios/var/rw/nagios.cmd") or warn "Cannot open
$!";
flock(PIPE, 2);
print PIPE "[$epoch]
PROCESS_SERVICE_CHECK_RESULT;$host;$service;$nagios_code;Test $status
@message";
sleep 1;    # wait a little bit for passive check to be read
close PIPE or warn "Cannot close pipe $!";

Things seem OK i.e. I see each passive check with no overlaps.

I may start running some tests with a smaller sleep interval. Let me know if
this thread is too much about programming(no pun intended)!

Jim



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list