Page 1 of 2
ACK comment and URL
Posted: Mon Oct 06, 2014 1:32 pm
by isadmin
Hello I am trying to modify our alerts so that they send the username that acknowledged the alert and their comment sent in the alert ACK response and the URL for the response link in our SMS gateway messages...
the commands are listed below....I used to have this working on our old version of nagios.
host-notify-by-sms
$USER1$/notify_eagle_sms.pl -s smsserver.domain.com -u username -p $userpass$ -d $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$ $HOSTSTATE$ Host($HOSTALIAS$) Info($HOSTOUTPUT$) Time($SHORTDATETIME$)" :$HostAckComment$ : "ACK by:User-$NotificationAuthors$"
service-notify-by-sms
$USER1$/notify_eagle_sms.pl -s smsserver.domain.com -u username -p $userpass$ -d $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$ $SERVICESTATE$ $SERVICEDESC$ Host($HOSTNAME$) Info($SERVICEOUTPUT$) Date($SHORTDATETIME$)" : $ServiceAckComment$ : "ACK by:User-$NotificationAuthors$"
Thanks!
Re: ACK comment and URL
Posted: Mon Oct 06, 2014 2:06 pm
by isadmin
heres how our old command worked...
$USER1$/mime_mail "[NG] $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$" "Type: $NOTIFICATIONTYPE$\\nService: $HOSTACKAUTHOR$\\nInfo: $HOSTACKCOMMENT$\\nComment: $SERVICEACKAUTHOR$\\nInfo: $SERVICEACKCOMMENT$\\nComment: $SERVICEDESC$\\nHost: $HOSTNAME$\\nAddress: $HOSTADDRESS$\\nState: $SERVICESTATE$\\nDate/Time: $LONGDATETIME$\\nAdditional Info:\\n$SERVICEOUTPUT$" $CONTACTEMAIL$
Re: ACK comment and URL
Posted: Mon Oct 06, 2014 2:19 pm
by isadmin
It think i have figured out the service and host commands but still not sure how to include the URL to ack the alerts...
$USER1$/notify_eagle_sms.pl -s serveraddress -u username -p $userpass$ -d $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$ $SERVICESTATE$ $SERVICEDESC$ Host($HOSTNAME$) Info($SERVICEOUTPUT$ $HOSTACKAUTHOR$ $HOSTACKCOMMENT$ $SERVICEACKAUTHOR$ $SERVICEACKCOMMENT$ )Date($SHORTDATETIME$)"
$USER1$/notify_eagle_sms.pl -s serveraddress -u username -p $userpass$ -d $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$ $HOSTSTATE$ Host($HOSTALIAS$) Info($HOSTOUTPUT$ $HOSTACKAUTHOR$ $HOSTACKCOMMENT$ $SERVICEACKAUTHOR$ $SERVICEACKCOMMENT$) Time($SHORTDATETIME$) "
Re: ACK comment and URL
Posted: Mon Oct 06, 2014 5:05 pm
by abrist
I am unfamiliar with your notification handler script. How does it put the response url together? Can you sanitize and post the script?
Re: ACK comment and URL
Posted: Tue Oct 07, 2014 6:44 am
by isadmin
Here is the perl script that comes with the SMS device
Code: Select all
============================== SUMMARY =====================================
#
# Summary : This plugin sends SMS alerts with SMSEagle hardware sms gateway
# Program : notify_eagle_sms.pl
# Version : 1.0
# Date : Feb 21 2013
# Author : Radoslaw Janowski / SMSEAGLE.EU
# Forked from: Nagios-SMS-WT (https://github.com/m-r-h/Nagios-SMS-WT)
# License : BSD
# Copyright (c) 2013, SMSEagle http://www.smseagle.eu
#
# ============================= MORE INFO ======================================
#
# Visit: http://www.smseagle.eu
#
# The latest version of this plugin can be found on GitHub at:
# http://bitbucket.org/proximus/smseagle-nagios
#
# ============================= SETUP ==========================================
#
# Copy this file to your Nagios plugin folder
#
# SMSEAGLE SETUP
#
# Create a new user for this script in SMSEagle device.
# This user will be referenced below as: SMSEAGLEUSER and SMSEAGLEPASSWORD
# Replace SMSEAGLEUSER and SMSEAGLEPASSWORD in script below with your values.
#
# NAGIOS SETUP
#
# 1. Create the SMS notification commands. (Commonly found in commands.cfg)
# Replace SMSEAGLEIP with IP Address of your SMSEagle device.
# Replace SMSEAGLEUSER and SMSEAGLEPASSWORD with your user/password to SMSEagle.
#
# Define two commands:
#
# define command {
# command_name notify-by-sms
# command_line $USER1$/notify_eagle_sms.pl -s SMSEAGLEIP -u SMSEAGLEUSER -p SMSEAGLEPASSWORD -d $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$ $SERVICESTATE$ $SERVICEDESC$ Host($HOSTNAME$) Info($SERVICEOUTPUT$) Date($SHORTDATETIME$)"
# }
#
# define command {
# command_name host-notify-by-sms
# command_line $USER1$/notify_eagle_sms.pl -s SMSEAGLEIP -u SMSEAGLEUSER -p SMSEAGLEPASSWORD -d $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$ $HOSTSTATE$ Host($HOSTALIAS$) Info($HOSTOUTPUT$) Time($SHORTDATETIME$)"
# }
#
#
# 2. In your nagios contacts (Commonly found on contacts.cfg) add
# the contact. Field "pager" should contain a mobile number for sms alerts in
# full international format e.g. 48xxxxxxxxx
#
#
# define contact{
# contact_name engineer
# alias Support Engineer
# service_notification_period 24x7
# host_notification_period 24x7
# service_notification_options w,u,c,r
# host_notification_options d,u,r
# service_notification_commands notify-by-email,notify-by-sms
# host_notification_commands host-notify-by-email,host-notify-by-sms
# email [email protected]
# pager 48xxxxxxxx
# }
#
#
# ============================= SCRIPT ==========================================
#
# Script params description:
#
# smseagleip = IP Address of your SMSEagle device (eg.: 192.168.1.150)
# user = SMSEagle user
# password = SMSEagle password
# dstaddr = Destination mobile number (the number to send SMS to)
# txt = the text message body
use strict;
use LWP::Simple;
use LWP::UserAgent;
use URI::Escape;
use Getopt::Long;
use HTTP::Request::Common;
my %args;
GetOptions(
'help' => \$args{help},
'smseagleip=s' => \$args{smseagleip},
'user=s' => \$args{user},
'password=s' => \$args{password},
'dstaddr=s' => \$args{dstaddr},
'txt=s' => \$args{txt}
);
if(defined($args{help}) || !defined($args{smseagleip}) || !defined($args{user}) || !defined($args{password}) || !defined($args{dstaddr}) || !defined($args{txt}) ) {
print "usage: notify_eagle_sms.pl --smseagleip <ip of smsaegle> --user <username> --password <password> --dstaddr <destination number> --txt <message> \n";
exit(0);
}
## URL Encode the message text
my $text = uri_escape($args{txt});
## Build the URL
my $baseurl = "http://".$args{smseagleip}.'/index.php/http_api/';
my $req = GET $baseurl."send_sms?login=$args{user}&pass=$args{password}&to=$args{dstaddr}&message=$text";
## Create the user agent and send the request
my $ua = LWP::UserAgent->new();
my $rsp = $ua->request($req);
## Process the response
if($rsp->content == "OK") {
print "Message sent succesfully to $args{dstaddr}\n";
} else {
print "Sent failure: " . $rsp->content . "\n";
}
Re: ACK comment and URL
Posted: Tue Oct 07, 2014 8:11 am
by isadmin
It is installed as a plugin on Nagios XI....after making the above changes we did start receiving the Ack User and Ack Comments....
The URL link I normally would see comes from the Notification Management Section of the Nagios GUI ....not sure how the handlers input that?
Also another weird thing which may be a bug or something but if we remove the Default Xi Notification handler or just add a second handler we get errors in the user notifcation settings
error is below
Nagios XI notification handlers are not defined for this account. XI notification handlers must be defined in the Core Config Manager for customized notification settings.
this is even with the default handler and the second SMS handler added...
Re: ACK comment and URL
Posted: Tue Oct 07, 2014 4:35 pm
by tmcdonald
Maybe I'm not reading this correctly, but if you try to remove a notification command that another contact/user relies on, it should just error out. If it is letting you remove it, you would certainly get an error message about a contact not having a command defined.
Re: ACK comment and URL
Posted: Wed Oct 08, 2014 6:40 am
by isadmin
Actually we are adding a second alert handler and that causes the error or having the sms handler only and no XI handler gives us the same error....
Re: ACK comment and URL
Posted: Wed Oct 08, 2014 3:49 pm
by abrist
User notification options are dependent on the xi handlers. Removing them will cause issues with the notification options for a user, and can potentially break the linking between the user and their contact object config. You should be able to use the additional handler, as long as it works ok in a vacuum. Does the custom handler script work when configured on a new test contact?
Re: ACK comment and URL
Posted: Thu Oct 09, 2014 8:05 am
by isadmin
Both handlers work but the interface throws an error stating neither are present...and its not possible to set user notification preferences because of the error
I may open ticket so we can get a deeper look at the overall problem