Icinga icon   Icinga – Notification template with notes support



I have just configured an Icinga2 notification template for hosts and services to replace the ugly and impractical default one.

Features

Not big things but useful in my opinion

Clear and nicely formatted layout

State based colors

State based icons

UTF Icons are included depending on the state of the host or service

Notes support

This notifications scripts can include the text configured in the notes field of the host or service (check this post for more information about configuring notes in icinga:  Icinga – Notes section in markdown language)

Enable “Notes” support

To enable it, the following configurations must be done:

Modify /etc/icinga2/conf.d/notifications.conf

apply Notification "mail" to Host {
   ...  
   ...

  if (host.notes != "") {
    vars.notification_notes = host.notes
  }

   
   ...
   ...
}


apply Notification "mail" to Service {
   ...
   ...

  if (service.notes != "") {
    vars.notification_notes = service.notes
  }

   ...
   ...
}

Modify /etc/icinga2/conf.d/commands.conf

object NotificationCommand "mail-host-notification" {
   command = [ SysconfDir + "/icinga2/scripts/mail-host-notification.sh" ]
   arguments += {
      …
      …
      "-x" = "$notification_notes$"
   }

 
   vars += {
      …
      …
      notification_notes = "$host.notes$"
   }
}

object NotificationCommand "mail-service-notification" {
   command = [ SysconfDir + "/icinga2/scripts/mail-service-notification.sh" ]
   arguments += {
      …
      …
      "-x" = "$notification_notes$"
   }

 
   vars += {
      …
      …
      notification_notes = "$service.notes$"
   }
}

Install Pandoc markdown parser

To convert the markdown code to html we need a parser like pandoc.

apt-get install pandoc

This is how it works:

$ cat > text.md
# Header one

## Header two

### Header three


Text with **bold** word.

_this is italic_

You can find related documentation in this link... blablablabla...

**https://doc.domain.com/blablabla**

[Visit SomoIT.net!](https://somoit.net)

$ pandoc < text.md
<h1 id="header-one">Header one</h1>
<h2 id="header-two">Header two</h2>
<h3 id="header-three">Header three</h3>
<p>Text with <strong>bold</strong> word.</p>
<p><em>this is italic</em></p>
<p>You can find related documentation in this link… blablablabla…</p>
<p><strong>https://doc.domain.com/blablabla</strong></p>
<p><a href="https://somoit.net">Visit SomoIT.net!</a></p>

Scripts

Download both host and service scripts in these links:
Download mail-host-notification.sh
Download mail-service-notification.sh

 

One thought on “Icinga – Notification template with notes support

  1. Hi, this is a very nice script, thanks for sharing.

    My Icinga runs on a Centos8 and the mail/mailx does not understand the -a ‘Content-Type: text/html’ … but I was able to adapt it.

    First:

    – Change MAILTO from mailx to sendmail
    – Change the last lines (where the actual mail transfer is happening:

    if [ -n “$MAILFROM” ] ; then
    #/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE” | $MAILBIN -a “From: $MAILFROM” -s “$SUBJECT” -a ‘Content-Type: text/html’ $USEREMAIL
    /usr/bin/printf “%b” “Content-Type: text/html\nSubject: $SUBJECT\nTo: $USEREMAIL\nFrom: $MAILFROM\n$NOTIFICATION_MESSAGE\n” | $MAILBIN $USEREMAIL
    else
    #/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE” | $MAILBIN -s “$SUBJECT” -a ‘Content-Type: text/html’ $USEREMAIL
    /usr/bin/printf “%b” “Content-Type: text/html\nSubject: $SUBJECT\nTo: $USEREMAIL\n$NOTIFICATION_MESSAGE\n” | $MAILBIN $USEREMAIL
    fi

    Thanks and best regards
    Volker

Leave a Reply

Your email address will not be published. Required fields are marked *