Re: [Nagios-devel] Piped OCHP/OCSP daemon
Posted: Tue Feb 27, 2007 8:58 pm
This is a multi-part message in MIME format.
--------------040001060803060501080008
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
On 24/02/07 04:06 AM, Thomas Guyot-Sionnest wrote:
> Hi list, hi Ethan,
>
> Here's what I came up with. This is a perl daemon that use Eventlib and
> Event::Lib. A lot of code comes from a perl daemon for processing
> performance data I talked about in another (or the same?) thread. You
> can find the original daemon here:
> http://www.control-alt-del.org/code/NPDaemon/.
>
> Since I do not use OCHP/OCSP yet and I haven't had time to set up a test
> environment, this is untested (actually I tested every single part, not
> the whole thing).
It's still not "wholly" tested but I fixed a bug and improved/cleaned
the code a bit.
Thomas
--------------040001060803060501080008
Content-Type: text/plain;
name="OCHP_daemon"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="OCHP_daemon"
#!/usr/bin/perl
# OCHP_daemon - Obsessive Compulsive Host Processor daemon for Nagios
#
# Copyright (C) 2007 Thomas Guyot-Sionnest
# Original code Copyright (C) 2007 Mark Steele
# http://www.control-alt-del.org/code
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
use Event::Lib;
use Getopt::Std;
use POSIX;
use strict;
use warnings;
use vars qw($PROGNAME $VERSION $READ_SIZE $MAX_LINE_LENGTH %args);
$PROGNAME = 'OCHP_daemon';
$VERSION = '1.0rc2';
$READ_SIZE = 4096;
$MAX_LINE_LENGTH = 4096;
getopts("f:n:H:p:t:c:r
h", \%args);
# Print usage if missing options or -h
if (!$args{'f'} || !$args{'H'} || $args{'h'}) {
usage();
}
# Process options
my $fifo = $args{'f'};
my $nsca = $args{'n'} || '/usr/local/nagios/bin/send_nsca';
my $host = $args{'H'};
my $reaper_delay = $args{'r'} || 1;
my $max_queue = $args{'m'} || 0;
my $nsca_extra_args = '';
$nsca_extra_args .= " -p $args{'p'}" if $args{'p'};
$nsca_extra_args .= " -to $args{'t'}" if $args{'t'};
$nsca_extra_args .= " -c $args{'c'}" if $args{'c'};
# Construct send_nsca command
$nsca .= " -H $host" . $nsca_extra_args;
# Sanity checks
if ($reaper_delay !~ /^\d+$/) {
print "reaper_delay must be an integer greater or equal to 0!\n\n";
usage();
}
if ($max_queue !~ /^\d+$/) {
print "max_queue must be an integer greater or equal to 0!\n\n";
usage();
}
if ($reaper_delay == 0) {
$max_queue = 0;
}
# send_nsca test run
system ("$nsca /dev/null 2>/dev/null");
if ($? != 0) {
print "Failed to run '$nsca', bailing out!\n";
exit 1;
}
# Now the fun stuff
$0 = $PROGNAME;
# Set up a zombie reaper
my $signal = signal_new(SIGCHLD, \&reap_chld);
$signal->add;
my @queue;
## VERY IMPORTANT: You have to open the pipe in O_RDWR, POSIX has rules about
## using polling calls on pipes, and can't do any on O_RDONLY
##
sysopen(FIFO, $fifo, O_RDWR | O_NONBLOCK) || die "couldn't open fifo: $!";
my $reader = event_new(\*FIFO, EV_READ, \&reader);
$reader->add;
my $timer;
if ($reaper_delay > 0) {
$timer = timer_new(\&reaper);
$timer->add($reaper_delay);
}
event_mainloop();
sub reap_chld {
while (waitpid(-1, WNOHANG) > 0) {
}
}
sub reaper {
my $event = shift;
if (@queue > 0) {
my $fork;
if (($fork = fork) == 0) {
# We're a child, make sure we don't stay around too long...
alarm(60);
$0 = "$0 child";
open(NSCA, "|$nsca >/dev/null 2>/dev/null") or die "Failed to spawn send_nsca: $!";
for(@queue) {
print NSCA $_;
}
close(NSCA);
exit;
} elsif (
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
--------------040001060803060501080008
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
On 24/02/07 04:06 AM, Thomas Guyot-Sionnest wrote:
> Hi list, hi Ethan,
>
> Here's what I came up with. This is a perl daemon that use Eventlib and
> Event::Lib. A lot of code comes from a perl daemon for processing
> performance data I talked about in another (or the same?) thread. You
> can find the original daemon here:
> http://www.control-alt-del.org/code/NPDaemon/.
>
> Since I do not use OCHP/OCSP yet and I haven't had time to set up a test
> environment, this is untested (actually I tested every single part, not
> the whole thing).
It's still not "wholly" tested but I fixed a bug and improved/cleaned
the code a bit.
Thomas
--------------040001060803060501080008
Content-Type: text/plain;
name="OCHP_daemon"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="OCHP_daemon"
#!/usr/bin/perl
# OCHP_daemon - Obsessive Compulsive Host Processor daemon for Nagios
#
# Copyright (C) 2007 Thomas Guyot-Sionnest
# Original code Copyright (C) 2007 Mark Steele
# http://www.control-alt-del.org/code
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
use Event::Lib;
use Getopt::Std;
use POSIX;
use strict;
use warnings;
use vars qw($PROGNAME $VERSION $READ_SIZE $MAX_LINE_LENGTH %args);
$PROGNAME = 'OCHP_daemon';
$VERSION = '1.0rc2';
$READ_SIZE = 4096;
$MAX_LINE_LENGTH = 4096;
getopts("f:n:H:p:t:c:r
# Print usage if missing options or -h
if (!$args{'f'} || !$args{'H'} || $args{'h'}) {
usage();
}
# Process options
my $fifo = $args{'f'};
my $nsca = $args{'n'} || '/usr/local/nagios/bin/send_nsca';
my $host = $args{'H'};
my $reaper_delay = $args{'r'} || 1;
my $max_queue = $args{'m'} || 0;
my $nsca_extra_args = '';
$nsca_extra_args .= " -p $args{'p'}" if $args{'p'};
$nsca_extra_args .= " -to $args{'t'}" if $args{'t'};
$nsca_extra_args .= " -c $args{'c'}" if $args{'c'};
# Construct send_nsca command
$nsca .= " -H $host" . $nsca_extra_args;
# Sanity checks
if ($reaper_delay !~ /^\d+$/) {
print "reaper_delay must be an integer greater or equal to 0!\n\n";
usage();
}
if ($max_queue !~ /^\d+$/) {
print "max_queue must be an integer greater or equal to 0!\n\n";
usage();
}
if ($reaper_delay == 0) {
$max_queue = 0;
}
# send_nsca test run
system ("$nsca /dev/null 2>/dev/null");
if ($? != 0) {
print "Failed to run '$nsca', bailing out!\n";
exit 1;
}
# Now the fun stuff
$0 = $PROGNAME;
# Set up a zombie reaper
my $signal = signal_new(SIGCHLD, \&reap_chld);
$signal->add;
my @queue;
## VERY IMPORTANT: You have to open the pipe in O_RDWR, POSIX has rules about
## using polling calls on pipes, and can't do any on O_RDONLY
##
sysopen(FIFO, $fifo, O_RDWR | O_NONBLOCK) || die "couldn't open fifo: $!";
my $reader = event_new(\*FIFO, EV_READ, \&reader);
$reader->add;
my $timer;
if ($reaper_delay > 0) {
$timer = timer_new(\&reaper);
$timer->add($reaper_delay);
}
event_mainloop();
sub reap_chld {
while (waitpid(-1, WNOHANG) > 0) {
}
}
sub reaper {
my $event = shift;
if (@queue > 0) {
my $fork;
if (($fork = fork) == 0) {
# We're a child, make sure we don't stay around too long...
alarm(60);
$0 = "$0 child";
open(NSCA, "|$nsca >/dev/null 2>/dev/null") or die "Failed to spawn send_nsca: $!";
for(@queue) {
print NSCA $_;
}
close(NSCA);
exit;
} elsif (
...[email truncated]...
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]