Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add emoji for ACKNOWLEDGEMENT #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 10 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Nagios Mattermost Plugin
========================

[![langage](https://img.shields.io/badge/Langage-Python-green.svg)](https://www.python.org/)

A plugin for [Nagios](https://www.nagios.org/) and compatible software (e.g. [Icinga](https://www.icinga.org/)) to enable notifications to a [Mattermost](http://www.mattermost.org/) server.

## Plugin Usage
Expand All @@ -23,54 +25,13 @@ The steps below are for a Nagios 4 server but should work with minimal modificat

2. Create an *Incoming Webhook* integration for the approriate team and note the provided URL.

3. Create the command definitions in your Nagios configuration:

```
define command {
command_name notify-service-by-mattermost
command_line /usr/local/nagios/libexec/mattermost.py --url [MATTERMOST-WEBHOOK-URL] \
--channel [OPTIONAL-MATTERMOST-CHANNEL] \
--notificationtype "$NOTIFICATIONTYPE$" \
--hostalias "$HOSTNAME$" \
--hostaddress "$HOSTADDRESS$" \
--servicedesc "$SERVICEDESC$" \
--servicestate "$SERVICESTATE$" \
--serviceoutput "$SERVICEOUTPUT$"
}

define command {
command_name notify-host-by-mattermost
command_line /usr/local/nagios/libexec/mattermost.py --url [MATTERMOST-WEBHOOK-URL] \
--channel [OPTIONAL-MATTERMOST-CHANNEL] \
--notificationtype "$NOTIFICATIONTYPE$" \
--hostalias "$HOSTNAME$" \
--hostaddress "$HOSTADDRESS$" \
--hoststate "$HOSTSTATE$" \
--hostoutput "$HOSTOUTPUT$"
}
```

4. Create the contact definition in your Nagios configuration:

```
define contact {
contact_name mattermost
alias Mattermost
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
host_notification_commands notify-host-by-mattermost
service_notification_commands notify-service-by-mattermost
}
```

5. Add the contact to a contact group in your Nagios configuration:
3. copy configuration `mattermost.cfg` to `/etc/nagios4/conf.d/` and upgrade parameter <MATTERMOSTE_URL>, <MATTERMOSTE_CHANNEL> and <NAGIOS_CGIURL>

```
define contactgroup{
contactgroup_name network-admins
alias Network Administrators
members email, mattermost
}
4. Add the contact to a contact group in your Nagios configuration:
```
define contactgroup{
contactgroup_name network-admins
alias Network Administrators
members email, mattermost
}
```
38 changes: 38 additions & 0 deletions mattermost.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
define contact {
contact_name mattermost
alias Mattermost
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
_mattermoste_url <MATTERMOSTE_URL>
_mattermoste_channel <MATTERMOSTE_CHANNEL>
_nagios_cgiurl <NAGIOS_CGIURL>
host_notification_commands notify-host-by-mattermost
service_notification_commands notify-service-by-mattermost
}

define command {
command_name notify-service-by-mattermost
command_line /usr/local/nagios/libexec/mattermost.py --cgiurl "$_CONTACTNAGIOS_CGIURL$" \
--url "$_CONTACTMATTERMOSTE_URL$" \
--channel "$_CONTACTMATTERMOSTE_CHANNEL$" \
--notificationtype "$NOTIFICATIONTYPE$" \
--hostalias "$HOSTNAME$" \
--hostaddress "$HOSTADDRESS$" \
--servicedesc "$SERVICEDESC$" \
--servicestate "$SERVICESTATE$" \
--serviceoutput "$SERVICEOUTPUT$"
}

define command {
command_name notify-host-by-mattermost
command_line /usr/local/nagios/libexec/mattermost.py --cgiurl "$_CONTACTNAGIOS_URL$" \
--url "$_CONTACTMATTERMOSTE_URL$" \
--channel "$_CONTACTMATTERMISTE_CHANNEL$" \
--notificationtype "$NOTIFICATIONTYPE$" \
--hostalias "$HOSTNAME$" \
--hostaddress "$HOSTADDRESS$" \
--hoststate "$HOSTSTATE$" \
--hostoutput "$HOSTOUTPUT$"
}
21 changes: 13 additions & 8 deletions mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ def parse():
default='Nagios')
parser.add_argument('--iconurl', help='URL of icon to use for username',
default='https://slack.global.ssl.fastly.net/7bf4/img/services/nagios_128.png') # noqa
parser.add_argument('--notificationtype', help='Notification Type',
required=True)
parser.add_argument('--notificationtype', help='Notification Type',required=True)
parser.add_argument('--hostalias', help='Host Alias', required=True)
parser.add_argument('--hostaddress', help='Host Address', required=True)
parser.add_argument('--hoststate', help='Host State')
parser.add_argument('--hostoutput', help='Host Output')
parser.add_argument('--servicedesc', help='Service Description')
parser.add_argument('--servicestate', help='Service State')
parser.add_argument('--serviceoutput', help='Service Output')
parser.add_argument('--cgiurl', help='Link to extinfo.cgi on your Nagios instance')
parser.add_argument('--cgiurl', help='Link to global cgi on your Nagios instance')
parser.add_argument('--version', action='version',
version='% (prog)s {version}'.format(version=VERSION))
args = parser.parse_args()
Expand All @@ -62,17 +61,23 @@ def emoji(notificationtype):
"RECOVERY": ":white_check_mark: ",
"PROBLEM": ":fire: ",
"DOWNTIMESTART": ":clock10: ",
"DOWNTIMEEND": ":sunny: "
"DOWNTIMEEND": ":sunny: ",
"ACKNOWLEDGEMENT": ":ok_hand: "
}.get(notificationtype, "")


def text(args):
template_host = "__{notificationtype}__ {hostalias} is {hoststate}\n{hostoutput}" # noqa
template_service = "__{notificationtype}__ {hostalias} at {hostaddress}/{servicedesc} is {servicestate}\n{serviceoutput}" # noqa
template_host = "__{notificationtype}__ {hostalias} is {hoststate}\n{hostoutput}"
template_service = "__{notificationtype}__ {hostalias} at {hostaddress}/{servicedesc} is {servicestate}\n{serviceoutput}"
if args.hoststate is not None:
template_cgiurl = " [View :link:]({cgiurl}?type=1&host={hostalias})"
template_cgiurl = " [:link: View]({cgiurl}/extinfo.cgi?type=1&host={hostalias})"
elif args.servicestate is not None:
template_cgiurl = " [View :link:]({cgiurl}?type=2&host={hostalias}&service={servicedesc})"
template_cgiurl = " [:link: View]({cgiurl}/extinfo.cgi?type=2&host={hostalias}&service={servicedesc})"
if args.notificationtype == "PROBLEM":
if args.hoststate is not None:
template_cgiurl += " | [Ack]({cgiurl}/cmd.cgi?cmd_typ=34&host={hostalias}&service={servicedesc})"
elif args.servicestate is not None:
template_cgiurl += " | [Ack]({cgiurl}/cmd.cgi?cmd_typ=34&host={hostalias}&service={servicedesc})"
template = template_service if args.servicestate else template_host

text = emoji(args.notificationtype) + template.format(**vars(args))
Expand Down