Shinken email notification plugin

Tired of brut text email notification, want to add more details to them and even make them readable for the common mortals. Then you can use the plugin shipped with Shinken. It can notify as usual in text and also in html in a table with all details needed from the service or host object.

../_images/shinken-html-notification.png

Here it is the command you can use to have a basic html notification. You have to specify usual shinken macros in option. If not specified then it will try to get them from environment variable if you have set option enable_environment_macros in shinken.cfg. It isn’t recommended to use them for large environment. You better use option -c, -o and -s or -h depending upon which object you’ll notify. Each macros is separated by double comma.

Here is commands examples ready to use:

define command {
    command_name    host-by-email
    command_line    $PLUGINSDIR$/notify_by_email.py -n host -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$"" -o ""$HOSTSTATE$,,$HOSTDURATION$"
}

define command {
    command_name    service-by-email
    command_line    $PLUGINSDIR$/notify_by_email.py -n service -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$" -o "$SERVICEDESC$,,$SERVICESTATE$,,$SERVICEOUTPUT$,,$SERVICEDURATION$"
}

Text mail

Despite the nice HTML formatting, you still prefer to use plain old text mail, use the `` -f text`` parameter instead of if html.

Mail sender

Default mail sender is built automatically with current server name and current Shinken user.

If you want to specif the mail sender, use the -s (--sender). For example: -s me@myserver.com.

Example

For example, you can have the below configuration: our service :

define service {
    service_description   Cpu
    use                   20min_long,linux-service
    register              0
    host_name             linux-snmp
    check_command         check_linux_cpu

    _DETAILLEDESC         Detect abnormal CPU usage
    _IMPACT               Slow down applications hosted by the system
    _FIXACTIONS           If recurrent situation then make performance audit
}

Define our detailled notifications commands adding the detailled informations and used with Shinken plugin so you will have an html email :

## Notify Host by Email with detailled informations
# Service have appropriate macros.
define command {
    command_name    detailled-host-by-email
    command_line    $PLUGINSDIR$/notify_by_email.py -n host -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$"" -o ""$HOSTSTATE$,,$HOSTDURATION$" -d "$_HOSTDETAILLEDDESC$" -i "$_HOSTIMPACT$"
}

## Notify Service by Email with detailled informations
# Service have appropriate macros.
define command {
    command_name    detailled-service-by-email
    command_line    $PLUGINSDIR$/notify_by_email.py -n service -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$" -o "$SERVICEDESC$,,$SERVICESTATE$,,$SERVICEOUTPUT$,,$SERVICEDURATION$" -d "$_SERVICEDETAILLEDESC$" -i "$_SERVICEIMPACT$" -a "$_SERVICEFIXACTIONS$"
}

And now define our notification ways:

define notificationway{
   notificationway_name            detailled-email
   service_notification_period     24x7
   host_notification_period        24x7
   service_notification_options    c,w,r
   host_notification_options       d,u,r,f,s
   service_notification_commands   detailled-service-by-email ; send service notifications via email
   host_notification_commands      detailled-host-by-email    ; send host notifications via email
}

Then you’ll receive a nice html mail giving all your details in a table.