mirror of
https://github.com/bashclub/check_mk_matrix_notifications.git
synced 2024-11-07 17:01:58 +01:00
Replaced urllib.request by requests
This commit is contained in:
parent
c167d9cf8b
commit
3149478363
11
matrix.py
11
matrix.py
@ -28,7 +28,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
import urllib.request
|
import requests
|
||||||
|
|
||||||
MATRIXHOST = os.environ["NOTIFY_PARAMETER_1"]
|
MATRIXHOST = os.environ["NOTIFY_PARAMETER_1"]
|
||||||
MATRIXTOKEN = os.environ["NOTIFY_PARAMETER_2"]
|
MATRIXTOKEN = os.environ["NOTIFY_PARAMETER_2"]
|
||||||
@ -86,12 +86,9 @@ matrixData = matrixData.encode("utf-8")
|
|||||||
# Random transaction ID for Matrix Homeserver.
|
# Random transaction ID for Matrix Homeserver.
|
||||||
txnId = ''.join(random.SystemRandom().choice(
|
txnId = ''.join(random.SystemRandom().choice(
|
||||||
string.ascii_uppercase + string.digits) for _ in range(16))
|
string.ascii_uppercase + string.digits) for _ in range(16))
|
||||||
|
|
||||||
# Authorization headers and etc.
|
# Authorization headers and etc.
|
||||||
matrixHeaders = {"Authorization": "Bearer " + MATRIXTOKEN,
|
matrixHeaders = {"Authorization": "Bearer " + MATRIXTOKEN,
|
||||||
"Content-Type": "application/json", "Content-Length": len(matrixData)}
|
"Content-Type": "application/json", "Content-Length": str(len(matrixData))}
|
||||||
# Request.
|
# Request.
|
||||||
req = urllib.request.Request(url=MATRIXHOST + "/_matrix/client/r0/rooms/" + MATRIXROOM +
|
req = requests.put(url=MATRIXHOST + "/_matrix/client/r0/rooms/" + MATRIXROOM +
|
||||||
"/send/m.room.message/" + txnId, data=matrixData, headers=matrixHeaders, method="PUT")
|
"/send/m.room.message/" + txnId, data=matrixData, headers=matrixHeaders)
|
||||||
# Exec.
|
|
||||||
urllib.request.urlopen(req)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user