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