Notification with 2 command

Marc Powell marc at ena.com
Wed Oct 11 16:16:32 CEST 2006



> -----Original Message-----
> From: nagios-users-bounces at lists.sourceforge.net [mailto:nagios-users-
> bounces at lists.sourceforge.net] On Behalf Of Nicola Paltani
> Sent: Wednesday, October 11, 2006 7:20 AM
> To: nagios-users at lists.sourceforge.net
> Subject: [Nagios-users] Notification with 2 command
> 
> Hi list
> 
> I'm checking a big number of printers with my nagios server (more then
> 300) , in detail i'm checking the toner level through snmp , what i
need
> is to send a notification via mail when the toner is law but this
> message it must contain the model of the printers form which I get the
> error , so i have made this notification command
> 
> snmpwalk -v 1 -c public -Ov $HOSTADDRESS$
> HOST-RESOURCES-MIB::hrDeviceDescr.1 >
> /usr/local/nagios/libexec/printername |
> 
> mail -s "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is
> $SERVICESTATE$ **" < /usr/local/nagios/libexec/printername
$CONTACTEMAIL$
> 
> the first command create a file with the printer model and the second
> send an email having as body the contents of the file
> 
> but unluckely it doesn't work , i have discovered that the " | "
create
> some problem , with this command i receive an empty body it ignore the
> file (printername) generated, but if i divide the command in 2
separate
> and associate all of them to a specific user it works

[chop]

> 
> how i can merge the 2 command or at least tell nagios to execute first
> command 1 and then 2

Make your notification command a real script instead of trying to do it
all in one shot. That'll also give you greater flexibility to include
additional information should you want it. Note that this is untested
but it's very straightforward --

#!/bin/sh

# printer-notify-by-email example script
# $1 = $HOSTADDRESS$
# $2 = $NOTIFICATIONTYPE$
# $3 = $HOSTALIAS$
# $4 = $SERVICEDESC$
# $5 = $SERVICESTATE$
# $6 = $CONTACTEMAIL$
#
# Matching notification command command_line --
#  command_line $USER1$/printer-notify-by-email $HOSTADDRESS$
$NOTIFICATIONTYPE$ "$HOSTALIAS$" "$SERVICEDESC" $SERVICESTATE$
$CONTACTEMAIL$

# Get the printer info
/path/to/snmpwalk -v 1 -c public -Ov $1
HOST-RESOURCES-MIB::hrDeviceDescr.1 >
/usr/local/nagios/libexec/printername

# E-mail it to the contact
/path/to/mail -s "** $2 alert - $3/$4 is $5 **" <
/usr/local/nagios/libexec/printername $6

# Remove the printer info
/bin/rm /usr/local/nagios/libexec/printername

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
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