Skip to content

Commit

Permalink
Adds channel option and version output
Browse files Browse the repository at this point in the history
  • Loading branch information
André Freitas committed Dec 16, 2015
1 parent 9dcb770 commit 90988e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Assuming you are using Nagios 4, the steps are:

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

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

3. Create the contact:


Expand Down
10 changes: 9 additions & 1 deletion mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import urllib2
import json

VERSION = "0.1.0"

CONFIG = {
"icon_url": "https://slack.global.ssl.fastly.net/7bf4/img/services/nagios_128.png", #noqa
"username": "Nagios"
Expand All @@ -34,7 +36,7 @@


def parse():
parser = argparse.ArgumentParser(description='Send mattermost webhooks')
parser = argparse.ArgumentParser(description='Sends mattermost webhooks')
parser.add_argument('--url', help='Integration URL', required=True)
parser.add_argument('--hostalias', help='Host Alias', required=True)
parser.add_argument('--notificationtype', help='Notification type',
Expand All @@ -44,6 +46,9 @@ def parse():
parser.add_argument('--servicedesc', help='Service Description')
parser.add_argument('--servicestate', help='Service State')
parser.add_argument('--serviceoutput', help='Service Output')
parser.add_argument('--channel', help='Channel to notificate')
parser.add_argument('--version', action='version',
version='%(prog)s {version}'.format(version=VERSION))
args = parser.parse_args()
return args

Expand All @@ -63,6 +68,9 @@ def make_data(args, config):
"text": encode_special_characters(text)
}

if args.channel:
payload["channel"] = args.channel

data = "payload=" + json.dumps(payload)
return data

Expand Down

0 comments on commit 90988e3

Please sign in to comment.