Reputation: 73
I'm trying to send out a different style of notification for a specific service in Nagios, namely, when a user account gets locked out from AD. I don't need all the excess information associated with the usual emails (e.g. Host the service pertains to, IP address, service status, etc), as all the information I need is given in the SNMP trap sent from Windows in $SERVICEOUTPUT
. However, I can't just change the notify-service-by-email command because I need to use the full output for all the other services.
I need to find a way to either:
Send out an email notification customized to this service
define command{
command_name notify-service-by-email
command_line $~LongOutputCommand~$
}
define command{
command_name notify-lockouts-by-email
command_line $-ShortOutputCommand~$
}
define service{
service_description Account Lockouts
service_notification notify-lockouts-by-email
...
}
Execute an if statement inside the command_line section of the Nagios command:
define command{
command_name notify-service-by-email
command_line if [ "$SERVICEDESC" == "Account Lockouts" ]; then $-ShortOutputCommand~$; else $~LongOutputCommand~$; fi
}
I don't believe it's possible for Nagios to do the first way because of the way it is programmed, but no matter how I try the second way it doesn't process it as a proper command ("if not recognized", etc).
Upvotes: 2
Views: 684
Reputation: 26
You cannot put a "script" syntax on a command_line definition. Think the command_line as an handler to call a script in action: the logic, and a if statement is "logic", must be moved in the script you are calling. Inside the script just use the if statement on $1 (the positional variable for the first argument passed to the script) and then process the value of $1. So, if $1 (in our case if you pass $SERVICEDESC is to the script as first argument, inside the script it is referenced as $1) equal to...
Upvotes: 1