[Nagiosplug-help] Help with passing Nagios variables tocustomplugin
Ralph.Grothe at itdz-berlin.de
Ralph.Grothe at itdz-berlin.de
Mon Oct 1 16:04:18 CEST 2007
There's your typo in your check command definition:
command_line $USER1$/check_ambtempF -H $HOSTADDRES$ -w
$ARG1$
Just correct the spelling of the $HOSTADDRESS$ macro
(I know the trailing dollar sign makes it look as if misspelled
with tripple S ;-)
and nagios should evaluate it correctly...
> -----Original Message-----
> From: nagiosplug-help-bounces at lists.sourceforge.net
> [mailto:nagiosplug-help-bounces at lists.sourceforge.net]On Behalf
Of
> Zembower, Kevin
> Sent: Monday, October 01, 2007 3:32 PM
> To: nagiosplug-help at lists.sourceforge.net
> Subject: Re: [Nagiosplug-help] Help with passing Nagios
variables
> tocustomplugin
>
>
> Hello, Ralph, thanks for writing again.
>
> No, it's not a typo; it really says, " hostaddress is
$HOSTADDRES$".
> This also shows up in two (related) locations. In the dump of
the
> NAGIOS_* variables, I also get
"NAGIOS_SERVICEOUTPUT=Temperature
> UNKNOWN: CCP server room temperature could not be determined
with host
> HOSTADDRES. Probable communications or host failure." This
> also shows up
> on the Nagios web page for this service in the 'status
information'
> columm, "Temperature UNKNOWN: CCP server room temperature could
not be
> determined with host $HOSTADDRES$. Probable communications or
host
> failure."
>
> The check-command for this service from
> /etc/nagios2/conf.d/services-nagios2.cfg is:
> # check that ambient temperature from Dell sensor is less
> than 80 and 90
> degree F.
> # Notify the 'temp' group only.
> define service {
> hostgroup_name temp_sensor
> service_description Ambient Temperature
> check_command check_ambtempF!80!90
> use generic-service
> notification_interval 0 ; set > 0 if you want
to be
> renotified
> contact_groups temp
> }
>
> The command-line in/etc/nagios2/services.cfg is:
> # Define command for check_ambtempF to check the ambient
temperature
> using the Dell PC SNMP sensor.
> define command {
> command_name check_ambtempF
> command_line $USER1$/check_ambtempF -H
> $HOSTADDRES$ -w $ARG1$
> -c $ARG2$
> }
>
> For anyone who's interested, I've pasted in the complete
> /usr/lib/nagios/plugins/check_ambtempF perl script at the end
of this
> note.
>
> Thanks, again, Ralph, for your advice and suggestions.
>
> -Kevin
>
>
> '-----Original Message-----
> From: Ralph.Grothe at itdz-berlin.de
> [mailto:Ralph.Grothe at itdz-berlin.de]
> Sent: Monday, October 01, 2007 5:29 AM
> To: Zembower, Kevin; nagiosplug-help at lists.sourceforge.net
> Subject: RE: [Nagiosplug-help] Help with passing Nagios
variables to
> customplugin
>
> Hi Kevin,
>
> > -----Original Message-----
> > From: nagiosplug-help-bounces at lists.sourceforge.net
> > [mailto:nagiosplug-help-bounces at lists.sourceforge.net]On
Behalf
> Of
> > Zembower, Kevin
> > Sent: Friday, September 28, 2007 9:13 PM
> > To: nagiosplug-help at lists.sourceforge.net
> > Subject: [Nagiosplug-help] Help with passing Nagios variables
> to
> > customplugin
> >
> >
> > Following advice from a user here, I used this code to dump
> > the contents
> > of the NAGIOS_* variables to a file when the perl plugin I
> wrote was
> > called:
> >
> > # Use this line below to dump the environment variables for
> debugging
> > system "env|sort >/tmp/plugins_env.$$";
> >
> > This seems to work correctly, and I end up with:
> > ...
> > NAGIOS_HOSTADDRESS=10.253.192.204
> > NAGIOS_HOSTALIAS=www.jhuccp.org
> > ...
> >
> > which is exactly what I expected. Then I tried to use this
> value with:
> > my %NAGIOS_ENV = map { $_ => $ENV{$_} } grep /^NAGIOS_/, keys
> %ENV;
> > ...
> > } elsif (defined($NAGIOS_ENV{NAGIOS_HOSTADDRESS})) {
> > $hostaddress = $NAGIOS_ENV{NAGIOS_HOSTADDRESS};
> > ...
> > print DMP "hostaddress is $hostaddress.\n";
> >
> > This outputs:
> > hostaddress is $HOSTADDRES$.
>
> is this just a typo (one missing S of the macro name)?
>
> What does your check command definition look like?
>
> =============================================================
> nagios at cn2:/etc/nagios2$ cat
/usr/lib/nagios/plugins/check_ambtempF
> #! /usr/bin/perl -w
>
> # check_ambtempF is a perl wrapper around the Nagios check_snmp
plugin
> # to check the ambient temperature sensor in Dell PowerEdge
servers.
>
> # Written by Kevin Zembower, 13-Sep-2007
>
> use strict;
> use Getopt::Std;
>
> my %opts;
> getopts('dhc:w:H:',\%opts);
>
> # Use this line below to dump the environment variables for
debugging
> system "env|sort >/tmp/plugins_env.$$";
>
> my %NAGIOS_ENV = map { $_ => $ENV{$_} } grep /^NAGIOS_/, keys
%ENV;
>
> if ( defined($opts{h}) ) {
> print <<EOF;
> Test ambient temperaure in Farenheit plugin for Nagios
> Copyright (c) 2007 Kevin Zembower
>
> This plugin is used to check the ambient temperature in
degrees
> Farenheit on Dell PowerEdge servers using SNMP.
>
> Requirements:
> This plugin requires /usr/lib/nagios/plugins/check_snmp.
>
> usage: $0 [-h] [-d] [-H hostaddress] [-w warn] [-c crit]
>
> -h print this short help message
> hostaddress address of host to check
> warn Warning threshold value in degrees Farenheit
> crit Critical threshold value in degrees Farenheit
> -d Turn on debugging output
>
> EOF
> exit;
> }
>
> # for debugging
> open(DMP, ">/tmp/temperature.dmp");
>
> my $warn= $opts{w};
> my $crit= $opts{c};
> my $debug = $opts{d};
> my $hostaddress;
> if (defined $opts{H}) {
> $hostaddress=$opts{H};
> } elsif (defined($NAGIOS_ENV{NAGIOS_HOSTADDRESS})) {
> $hostaddress = $NAGIOS_ENV{NAGIOS_HOSTADDRESS};
> } else {
> $hostaddress="127.0.0.1"
> };
>
> print DMP "hostaddress is $hostaddress.\n";
>
> my $output = "Temperature ";
>
> $_ = `/usr/lib/nagios/plugins/check_snmp -H $hostaddress -o
> .1.3.6.1.4.1.674.10892.1.700.20.1.6.1.3 -w 267 -c 332`;
>
> print DMP $_;
> close(DMP);
>
> if ($? != 0) { #There was an error calling the check_snmp
routine...
> $output .= "UNKNOWN: CCP server room temperature could not
be
> determined with host $hostaddress. Probable communications or
host
> failure.\n";
> print $output;
> exit 3;
> }
> print "Error code: $?\n" if $debug;
>
> print $_ if $debug;
>
> (my $tempC) = /=(\d+)/; #All the digits after the equals sign
are the
> temperature in tenths of a degree Celsius
> $tempC /= 10; #Divide the returned value by 10
> print "${tempC}C\n" if $debug;
> my $tempF = (9/5*$tempC + 32);
> print "${tempF}F\n" if $debug;
>
>
> if ( defined $crit && $tempF >= $crit ) {
> $output .= "CRITICAL: CCP server room temperature of
${tempF}F
> exceeds critical temperature of $crit\n";
> print $output;
> exit 2;
> } elsif ( defined $warn && $tempF >= $warn ) {
> $output .= "WARNING: CCP server room temperature of
${tempF}F
> exceeds warning temperature of $warn\n";
> print $output;
> exit 1;
> } else {
> $output .= "OK: CCP server room temperature is
${tempF}F\n";
> print $output;
> exit 0;
> }
>
>
> nagios at cn2:/etc/nagios2$
>
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Nagiosplug-help mailing list
> Nagiosplug-help at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagiosplug-help
> ::: Please include plugins version (-v) and OS when reporting
> any issue.
> ::: Messages without supporting info will risk being sent to
/dev/null
>
More information about the Help
mailing list