EPN, RRDfiles etc SOLVED

Jamie Baddeley jamie.baddeley at vpc.co.nz
Fri Aug 22 11:52:23 CEST 2003


Nagiosers,

C wrapper worked perfectly. All good.

*very* happy. Thanks Stanley. Thanks Daniel.

incidentally tried perlcc but that failed miserably. (screen sat blankly 
looking at me after a compile)

I will submit a modded version that passes plugin response descriptions & 
units (good for nagios UI) plus also deals with an rrd nan response.

jamie

p.s. plugin now inline. watch out for linebreaks.

#!/usr/bin/perl
#
# Nagios check script to check data in cricket rrd files
# Written by Dan Rich (drich at employees.org)
#
# usage:
#    check_cricket_data -R rrdfile -i dsindex -c crit -w warn
#
# Read a cricket-generated rrd file and return the status of the queried
# data
#
# License: GPL
# $Id: check_cricket_data,v 1.2 2003/06/05 15:27:20 drich Exp $

use strict;
use Getopt::Long;
use IPC::Open3;
use Symbol;
use vars qw($opt_V $opt_h $opt_H $opt_c $opt_w $opt_R $opt_i $verbose $host 
$sta
te $PROGNAME);
use lib "/var/nagios/libexec" ;
use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);

# rrdtool path
my $rrdtool = "/var/cricket/bin/rrdtool";

$PROGNAME = "check_cricket_data";

Getopt::Long::Configure('bundling');
GetOptions
        ("V"   => \$opt_V,   "version"    => \$opt_V,
         "c=s" => \$opt_c,   "critical=s" => \$opt_c,
         "w=s" => \$opt_w,   "warning=s"  => \$opt_w,
         "h"   => \$opt_h,   "help"       => \$opt_h,
         "R=s" => \$opt_R,   "rrdfile=s"  => \$opt_R,
         "i=s" => \$opt_i,   "index=s"    => \$opt_i,
         "v"   => \$verbose, "verbose"    => \$verbose);

if ($opt_V) {
        print_revision($PROGNAME,'$Revision: 1.2 $');
        exit $ERRORS{'OK'};
}

if ($opt_h) {print_help(); exit $ERRORS{'OK'};}

unless ($opt_c and $opt_w and $opt_R and $opt_i) {
  &print_usage;
  exit $ERRORS{'UNKNOWN'};
}

# Just in case of problems, let's not hang Nagios
$SIG{'ALRM'} = sub {
        print "No Answer from Client\n";
        exit 2;
};
alarm($TIMEOUT);


# Set default return
my $status = $ERRORS{"UNKNOWN"};

# Get data from rrd file
my $RDR = gensym();
my $ERR = gensym();
my $WTR = gensym();

# Get the timestamp of the last data in the rrd file
#print "$rrdtool last $opt_R\n";
open3($WTR, $RDR, $ERR, "$rrdtool last $opt_R");
close($WTR);
my $last = <$RDR>;
chomp($last);
if ($last <= 0) {
  printf "CRITICAL: ". <$ERR>;
  exit $ERRORS{'CRITICAL'};
}
close($RDR);
close($ERR);

# Get data
#print "$rrdtool fetch $opt_R AVERAGE -s $last -e $last\n";
open3($WTR, $RDR, $ERR, "$rrdtool fetch $opt_R AVERAGE -s $last -e $last");
close($WTR);

my @data;
while (<$RDR>) {
  chomp;
  my ($timestamp,$data) = split(/:/,$_,2);
  next unless ($timestamp =~ /^\d+$/);          # We only want data line
  @data = split(/\s+/,$data);
  last;
}
close($RDR);
close($ERR);

# Convert from exp format to integer
my $result =  $data[$opt_i];
if ($result =~ /\d+/) {
  #print $result ."\n";
  my ($int,$exp) = split(/e/,$result);
  #print "$int * 10^$exp\n";
  $result = $int * 10**$exp;
  #print $data[$opt_i] ." - $result\n";
}

# Check for warning/crit
if ( $result  > $opt_c ) {
  print "CRITICAL: rrdtool returned ". $result ."\n";
  exit $ERRORS{'CRITICAL'};
} elsif ( $result  > $opt_w or $result !~ /\d+/) {
  print "WARNING: rrdtool returned ". $result ."\n";
  exit $ERRORS{'WARNING'};
} else {
  print "rrdtool returned ". $result ."\n";
  exit $ERRORS{'OK'};
}

sub print_usage () {
        print "Usage:
   $PROGNAME [--verbose]
   $PROGNAME --help
   $PROGNAME --version
   $PROGNAME -R rrdfile -i dsindex -c critical -w warning
";
}

sub print_help () {
        print_revision($PROGNAME,'$Revision: 1.2 $');
        print "Copyright (c) 2002 Daniel Rich

Read data from an rrd file and return the result

";
        print_usage();
        print "
-v, --verbose
   Print some extra debugging information (not advised for normal operation)
-V, --version
   Show version and license information
-h, --help
   Show this help screen
-w, --warning=INTEGER
   load / performance level at which a warning message will be gererated.
-c, --critical=INTEGER
   load / performance level at which a critical message will be gererated.
-R, --rrdfile=FILE
   RRD file to read
-i, --index=INTEGER
   index of data set to check

";
        support();
}

On Thu, 21 Aug 2003 01:35, Stanley Hopcroft wrote:
> > From: Jamie Baddeley <jamie.baddeley at vpc.co.nz>
> > Reply-To: jamie.baddeley at vpc.co.nz
> > To: nagios-users at lists.sourceforge.net
> > Date: Wed, 20 Aug 2003 19:55:09 +1200
> > Subject: [Nagios-users] EPN, RRDfiles etc
>
> <yelp>
> Aaargh ! Multi-part in the digest .. is indegistible
>
> > --------------Boundary-00=_XBRWNLL92J52KZPYCQNI
> > Content-Type: text/plain;
> >   charset="iso-8859-1"
> > Content-Transfer-Encoding: 8bit
>
> </yelp>
>
> > Hi All,
> >
> > I'm working on getting a new plugin sorted out. Ages ago Daniel Rich
> > posted a plugin to read RRD files generated by Cricket. It's an awesome
> > little plugin designed to read RRD files. This means you can use your
> > favourite rrd based system to go out and get the info from the network,
> > and Nagios can poll the resultant RRD's locally. Nice. A Nice efficient
> > way of doing things.
> >
> > Anyway, I'm testing Daniel's plugin, and I've come up against a problem.
> > The plugin uses perl's IPC::Open3 module to call rrdtool to get the info.
> > Unfortunately there appears to be a problem with Nagios that has EPN
> > compiled and Open3.
>
> It may not be Open3; try a hello world sort of test program that uses
> this module - maybe the synopsis from the perldoc Open3.
>
> > Ref:
> > http://www.mail-archive.com/embperl@perl.apache.org/msg05441.html
> >
> > When I use the plugin I get nothing but (no output!).
> >
> > Debugging, I'm getting this:
> > Can't locate object method "OPEN" via package "OutputTrap" (perhaps you
> > forgot to load "OutputTrap"?) at /usr/lib/perl5/5.6.1/IPC/Open3.pm line
> > 136.
> >
> > ...when I run Nagios (run in foreground to debug).
> >
> > My question is what do people think are sensible ways around this?
> > - Recompile Nagios without EPN support?
> > - Find_another_way with the plugin?
> > - Discover some other magic fix?
> >
> > I've attached the plugin, as I think it's a great way of doing what a lot
> > of people are trying to do with Apan etc, except that it takes advantage
> > of tried and true time-series trending systems such as cricket or perhaps
> > cacti etc.
>
> Unfortunately, your mailer has base-64 encoded the plugin (in digest
> format anyway) so that it's hard to see what is causing ePN to choke.
>
> > I'm hesitant to walk away from EPN, as we have the learned Mr Hopcroft
> > often extolling the virtues of EPN.
>
> Noisy and extremely non politically correct, non mixed company
> raspberry. ePN buys somethings but you lose others; I like it but YMMV.
>
> Some modules simply don't work with ePN (eg Parse::HTML); there are some
> things that cannot be done with an embedded Perl interpreter (there's
> some notes on the Nag web site about the definitely verboten stuff but
> Stas Beckmans __book__ [his notes finally ended up as an ORA
> publication] on mod_perl [the free HTML version of the book is linked on
> the mod_perl site - thoroughly recommended if you are interested in
> getting to grips with Perl] is the authority).
>
> You may need to hack the plugin and then try it out with the mini_epn.c
> in the contrib directory (you may need the version in the CVS if you
> have a threaded Perl)
>
> But there is always more than one way to do it.
>
> In this case
>
> 1 make a C wrapper for your plugin eg
>
> /* $Id: check_pams.c,v 1.2 2002-12-04 15:55:23+11 anwsmh Exp anwsmh $ */
>
> /* $Log: check_pams.c,v $
>  * */
>
> int
> main(int argc, char *argv) {
>   execv("/usr/local/nagios/libexec/check_pams.pl", argv) ;
> }
>
>
> 2 s/check_pams\.pl/your_plugin.pl/
>
> 3 gcc -o your_plugin your_plugin_wrapper.c
>
> /* also handly for Perl plugins that need to be suid */
>
> > Thoughts?
> >
> > jamie


-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines
at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0
_______________________________________________
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