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

Support for semicolon and new --insecure option #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import json
import urllib2

VERSION = "0.3.1"
VERSION = "0.3.2"


def parse():
parser = argparse.ArgumentParser(description='Sends alerts to Mattermost')
parser.add_argument('--url', help='Incoming Webhook URL', required=True)
parser.add_argument('-k', '--insecure', help='Do not check SSL certificate validity', action='store_true')
parser.add_argument('--channel', help='Channel to notify')
parser.add_argument('--username', help='Username to notify as',
default='Nagios')
Expand Down Expand Up @@ -93,17 +94,23 @@ def payload(args):
if args.channel:
payload["channel"] = args.channel

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


def request(url, data):
req = urllib2.Request(url, data)
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
response = urllib2.urlopen(req)
return response.read()


if __name__ == "__main__":
args = parse()

# Ignore certificate check if --insecure argument is used
if args.insecure:
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None)):
ssl._create_default_https_context = ssl._create_unverified_context

response = request(args.url, payload(args))
print response