Page 1 of 1

Formatting text messages?

Posted: Sun Oct 07, 2018 12:37 pm
by t3dus
Is there a special way to format my sms messages from Nagios Core?

Currently if I have them text me they show up as 3 separate messages vs 1 which is super annoying so I simply don't have them going there at all which is a big issue as far as seeing alerts right away.

Re: Formatting text messages?

Posted: Mon Oct 08, 2018 8:18 am
by mcapra
It would probably depend on the specific messaging service you're using. I don't have this problem with Twilio:
2018_10_08_08_16_42_Inbox_5_Gmail.png
2018_10_08_08_16_42_Inbox_5_Gmail.png (20.57 KiB) Viewed 2075 times
My implementation:
https://support.nagios.com/forum/viewto ... 94#p252294

Re: Formatting text messages?

Posted: Mon Oct 08, 2018 12:34 pm
by t3dus
I simply have nagios core e-mailing my phone through the provided e-mail to text provided by my phone provider.

Since I currently use US Cellular it looks something like "YOURNUMBERHERE@e-mail.uscc.net" which then sends e-mails to me via text.

I'm not sure i'd be interested in using something like Twilio that costs money.

What I am asking is if there is someway to format the e-mails to be shorter within nagios config files

Re: Formatting text messages?

Posted: Mon Oct 08, 2018 12:52 pm
by ssax
If you want to shorten the message you may want to create a separate contact for SMS and then set the contacts host/service_notification_handler_commands to new commands that only sends what you want:

From the default:

Code: Select all

define command {
        command_name    notify-host-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

define command {
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
To a custom command:

Code: Select all

define command {
        command_name    notify-host-by-sms
        command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

define command {
        command_name    notify-service-by-sms
        command_line    /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
Unfortunately, we'd need to know where your SMS provider is splitting the messages in order to determine what to change in the custom commands but that's how you'd do it.

Re: Formatting text messages?

Posted: Mon Oct 08, 2018 1:01 pm
by cdienger
Notification command definitions are in /usr/local/nagios/etc/objects/commands.cfg by default and these dictate the format. The notify-host-by-email andnotify-service-by-email definitions for example:

define command {

command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/sbin/sendmail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}


define command {

command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/sbin/sendmail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}


Information on macros that can be used can be found at https://assets.nagios.com/downloads/nag ... olist.html