-
Notifications
You must be signed in to change notification settings - Fork 38
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 python3 #21
Comments
import urllib.request |
It's not that simple:
However, i asked ChatGPT to convert it, here is the diff: diff --git a/mattermost.py b/mattermost.py
index 627b3fd..160f00d 100755
--- a/mattermost.py
+++ b/mattermost.py
@@ -1,28 +1,10 @@
#!/usr/bin/env python
# coding: utf-8
import argparse
import json
-import urllib2
+import urllib.request
+from urllib.parse import quote
VERSION = "0.3.1"
@@ -33,7 +15,7 @@ def parse():
parser.add_argument('--username', help='Username to notify as',
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
+ default='https://slack.global.ssl.fastly.net/7bf4/img/services/nagios_128.png')
parser.add_argument('--notificationtype', help='Notification Type',
required=True)
parser.add_argument('--hostalias', help='Host Alias', required=True)
@@ -53,13 +35,11 @@ def parse():
args = parser.parse_args()
return args
-
def encode_special_characters(text):
text = text.replace("%", "%25")
text = text.replace("&", "%26")
return text
-
def emoji(notificationtype):
return {
"ACKNOWLEDGEMENT": ":thumbsup: ",
@@ -69,10 +49,9 @@ def emoji(notificationtype):
"DOWNTIMEEND": ":sunny: "
}.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.notificationtype == "ACKNOWLEDGEMENT":
template_host += "\n{hostackcomment}\nacked by: {hostackauthor}"
template_service += "\n{serviceackcomment}\nacked by: {serviceackauthor}"
@@ -87,7 +66,6 @@ def text(args):
return encode_special_characters(text)
-
def payload(args):
payload = {
"username": args.username,
@@ -101,14 +79,13 @@ def payload(args):
data = "payload=" + json.dumps(payload)
return data
-
def request(url, data):
- req = urllib2.Request(url, data)
- response = urllib2.urlopen(req)
+ data = data.encode('utf-8')
+ req = urllib.request.Request(url, data)
+ response = urllib.request.urlopen(req)
return response.read()
-
if __name__ == "__main__":
args = parse()
response = request(args.url, payload(args))
- print response
+ print(response.decode('utf-8')) I tested and it is working in my environment. |
Good deal! I had to make the same changes to get it to work too. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: