caronc / nzb-notify

Push Notifications to a large number of supported services for NZBGet and SABnzbd (based on Apprise)
GNU General Public License v3.0
129 stars 15 forks source link

Add MatterMost Support #19

Closed seanvree closed 7 years ago

seanvree commented 7 years ago

I'm wondering if this works with MatterMost?

Looking over the Notify.py file, The Webhook that is generated from a self-hosted MatterMost installation doesn't look like the example in the notify.py file:

# You need to focus on the 3 Tokens at the end of the URL
#  * https://hooks.slack.com/services/TokenA/TokenB/TokenC

When I generate a webhook with MM, it looks like this:

URL: https://hooks.domain.com:8065/hooks/wireaom5w7gfmek1jkr6znqfww

Any Ideas?

Thanks for this! SLICK!

caronc commented 7 years ago

I personally never used MattersMost; thanks for sharing it!

When i get home I'll have a look at their API documentation and see how it works. If it's anything like every other API out there (including Slack's) it shouldn't be too hard to implement.

Perhaps this Notify tool could be updated to support a URL such as: mmost://hostname:port/key/ ?

That would get substituted for a URL like you suggested (https://hostname:port/hooks/key)? We could make the default port be 8065, so you could also just write the url as: mmost://hostname/key/? Sound good?

So in your case (with respect to your ticket), you'd use the URL mmost://hooks.domain.com/wireaom5w7gfmek1jkr6znqfww/ which would do the translation for you.

Anyway, I will keep you posted (as i learn more) and poke at it's implementation as the week goes by. If you have any info to share to speed the process along; it will always be welcome.

caronc commented 7 years ago

Linking ticket to https://github.com/sabnzbd/sabnzbd/issues/435

seanvree commented 7 years ago

@caronc ,

Yeah, it should be no problem with an incoming webook. Are you familiar with Sonarr or Radarr, they both have it, pretty simple code.

Yes, the format is exactly how you mentioned:

https://mydomain.com:8065/hooks/g3mjakha57gsxyob8a3jmn1wxo

(Obviously, the hostname is the server which is running Mattermost)

So, as long as I have local DNS setup, I don't even need to be connected to the WAN...This script would send the notification to the MM server via hostname (mydomain.com)

But yeah, not sure how to edit the config file to work without the 3 tokens.

Anyway, let me know if you get anywhere with this!!

THANKS!

caronc commented 7 years ago

If you wouldn't mind; could you please check out the master branch and giver a whirl?

Since the API works via a secure method too (https), you can use mmost:// for insecure (http://) and mmosts:// for secure. In both cases, the default port is 8065 so it is not necessary to specify it as part of the URL. Does this seem reasonable?

Please let me know your results. With respect to your last post, the following should work from the command line:

python Notify.py -b body -s mmosts://mydomain.com/g3mjakha57gsxyob8a3jmn1wxo

At the moment, i don't use/support the --title (-t) switch. Well... specifying it just doesn't do anything with it (yet). I was thinking about placing the title on the first line of the body, and then appending the body after that. Would that make sense? The API message doesn't support a title or heading type entry; just a body.

seanvree commented 7 years ago

@caronc - THANKS!

WIll do in a bit and report back!

seanvree commented 7 years ago

@caronc -

OKay, I think we are ALMOST there

So, my install of MM is on TLS port 8065.

so here is the output when I send:
(FYI, I've changed the host and the hook info on here for security:

C:\Program Files\SABnzbd\scripts>python notify.py -b "test" -s mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmq000 -D
[INFO] [DEBUG] Script mode forced off.
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(default) SERVERS=None
2017-07-05 01:25:13,871 - 29288 - DEBUG - set(config) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmq000"
2017-07-05 01:25:13,871 - 29288 - DEBUG - set(environment) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(default) TITLE=None
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(default) BODY=None
2017-07-05 01:25:13,871 - 29288 - DEBUG - set(config) BODY="test"
2017-07-05 01:25:13,871 - 29288 - DEBUG - set(environment) BODY="test"
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(config) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(config) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(default) TITLE="Test Notify Title"
2017-07-05 01:25:13,871 - 29288 - DEBUG - get(config) BODY="test"
2017-07-05 01:25:13,872 - 29288 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 01:25:13,872 - 29288 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 01:25:13,872 - 29288 - DEBUG - get(config) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"
2017-07-05 01:25:13,874 - 29288 - DEBUG - Server parsed to: {'host': 'mydomain.com', 'user': None, 'query': 'wireapm5w7gfmek1jkr6zmqfww', 'url': '"mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"', 'path': '/', 'fullpath': '/wireapm5w7gfmek1jkr6zmqfww', 'password': None, 'port': None, 'qsd': {}, 'schema': 'mmosts'}
2017-07-05 01:25:13,881 - 29288 - DEBUG - MatterMost POST URL: "mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"
2017-07-05 01:25:13,881 - 29288 - DEBUG - MatterMost Payload: {'payload': {'text': 'test', 'icon_url': 'http://nzbget.lead2gold.org/notify/nzbget-notify-info-72x72.png'}}
2017-07-05 01:25:13,914 - 29288 - WARNING - A Connection error occured sending MatterMost notification.
2017-07-05 01:25:13,914 - 29288 - DEBUG - Socket Exception: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
2017-07-05 01:25:13,915 - 29288 - DEBUG - Exiting with return code: 93

C:\Program Files\SABnzbd\scripts>

NOW, if I send via non-TLS:

C:\Program Files\SABnzbd\scripts>python notify.py -b "test" -s mmost://mydomain.com/wireapm5w7gfmek1jkr6zmq000 -D
[INFO] [DEBUG] Script mode forced off.
2017-07-05 01:25:54,575 - 25676 - DEBUG - get(default) SERVERS=None
2017-07-05 01:25:54,575 - 25676 - DEBUG - set(config) SERVERS="mmost://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"
2017-07-05 01:25:54,575 - 25676 - DEBUG - set(environment) SERVERS="mmost://mydomain.com/wireapm5w7gfmek1jkr6zmqf000"
2017-07-05 01:25:54,575 - 25676 - DEBUG - get(default) TITLE=None
2017-07-05 01:25:54,575 - 25676 - DEBUG - get(default) BODY=None
2017-07-05 01:25:54,575 - 25676 - DEBUG - set(config) BODY="test"
2017-07-05 01:25:54,575 - 25676 - DEBUG - set(environment) BODY="test"
2017-07-05 01:25:54,575 - 25676 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 01:25:54,575 - 25676 - DEBUG - get(config) SERVERS="mmost://mydomain.com/wireapm5w7gfmek1jkr6zmq000"
2017-07-05 01:25:54,576 - 25676 - DEBUG - get(config) SERVERS="mmost://mydomain.com/wireapm5w7gfmek1jkr6zmq000"
2017-07-05 01:25:54,578 - 25676 - DEBUG - get(default) TITLE="Test Notify Title"
2017-07-05 01:25:54,578 - 25676 - DEBUG - get(config) BODY="test"
2017-07-05 01:25:54,578 - 25676 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 01:25:54,578 - 25676 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 01:25:54,578 - 25676 - DEBUG - get(config) SERVERS="mmost://mydomain.com/wireapm5w7gfmek1jkr6zmq000"
2017-07-05 01:25:54,579 - 25676 - DEBUG - Server parsed to: {'host': 'mydomain.com', 'user': None, 'query': 'wireapm5w7gfmek1jkr6zmqfww', 'url': '"mmost://mydomain.com/wireapm5w7gfmek1jkr6zmq000"', 'path': '/', 'fullpath': '/wireapm5w7gfmek1jkr6zmqfww', 'password': None, 'port': None, 'qsd': {}, 'schema': 'mmost'}
2017-07-05 01:25:54,594 - 25676 - DEBUG - MatterMost POST URL: "mmost://mydomain.com/wireapm5w7gfmek1jkr6zmq000"
2017-07-05 01:25:54,594 - 25676 - DEBUG - MatterMost Payload: {'payload': {'text': 'test', 'icon_url': 'http://nzbget.lead2gold.org/notify/nzbget-notify-info-72x72.png'}}
2017-07-05 01:25:54,624 - 25676 - INFO - Sent MatterMost notification.
2017-07-05 01:25:54,624 - 25676 - DEBUG - Exiting with return code: 93

C:\Program Files\SABnzbd\scripts>

SO, it with TLS, it says bad socket...not sure why that would be, certs are good, and I have a couple other applications sending via TLS that work fine (sonarr, radarr, Plexpy)

but, it says notification sent on non-TSL? But the notification never arrives.

Any ideas?

caronc commented 7 years ago

I accidentally closed this issue with previous commit that was not meant to go against this ticket (meant for #20 instead). Sorry about that.

That said, #20 is applicable to your situation. You'll need to check out the master branch again.

Then try adding a ?verify=No at the end of your URL when using the mmosts:// (secure) method. This should fix your SSL error you were getting.

I adjusted the payload (submitted to your server) which may solve the 'why nothing is happening' issue. This part is a bit confusing to me though because the payload appears correct already according to the documentation. However the documentation also states that this changed method is valid as well.

On a side note: The only confusing thing about your last post was this line:

2017-07-05 01:25:54,594 - 25676 - DEBUG - MatterMost POST URL: "mmost://mydomain.com/wireapm5w7gfmek1jkr6zmq000"

Did it really say that? Or did you just mask some values for obvious reasons? The part that has me confused is that that URL should have read the following (for secure):

https://mydomain.com:8065/hooks/wireapm5w7gfmek1jkr6zmqf000

Your logs don't show the /hooks, the port, or the https:// which has me concerned.

seanvree commented 7 years ago

@caronc IT WORKED!

c:\Program Files\SABnzbd\scripts>git pull
Already up-to-date.

c:\Program Files\SABnzbd\scripts>python notify.py -b "test" -s mmosts://domain.com/wireapm5w7gfmek1jkr6zm0000?verify=False -D
[INFO] [DEBUG] Script mode forced off.
2017-07-05 17:58:52,582 - 41176 - DEBUG - get(default) SERVERS=None
2017-07-05 17:58:52,582 - 41176 - DEBUG - set(config) SERVERS="mmosts://domain.com/wireapm5w7gfmek1jkr6zmq0000?verify=False"
2017-07-05 17:58:52,582 - 41176 - DEBUG - set(environment) SERVERS="mmosts://domain.com/wireapm5w7gfmek1jkr6zm0000?verify=False"
2017-07-05 17:58:52,582 - 41176 - DEBUG - get(default) TITLE=None
2017-07-05 17:58:52,582 - 41176 - DEBUG - get(default) BODY=None
2017-07-05 17:58:52,582 - 41176 - DEBUG - set(config) BODY="test"
2017-07-05 17:58:52,582 - 41176 - DEBUG - set(environment) BODY="test"
2017-07-05 17:58:52,582 - 41176 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 17:58:52,582 - 41176 - DEBUG - get(config) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zm0000?verify=False"
2017-07-05 17:58:52,582 - 41176 - DEBUG - get(config) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmq0000?verify=False"
2017-07-05 17:58:52,584 - 41176 - DEBUG - get(default) TITLE="Test Notify Title"
2017-07-05 17:58:52,584 - 41176 - DEBUG - get(config) BODY="test"
2017-07-05 17:58:52,585 - 41176 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 17:58:52,585 - 41176 - DEBUG - get(default) INCLUDEIMAGE=None
2017-07-05 17:58:52,585 - 41176 - DEBUG - get(config) SERVERS="mmosts://mydomain.com/wireapm5w7gfmek1jkr6zmqfww?verify=False"
2017-07-05 17:58:52,585 - 41176 - DEBUG - Server parsed to: {'host': 'mydomain.com', 'user': None, 'query': 'wireapm5w7gfmek1jkr6zmqfww', 'url': 'mmosts://domain.com/wireapm5w7gfmek1jkr6zm0000', 'path': '/', 'fullpath': '/wireapm5w7gfmek1jkr6zmqfww', 'password': None, 'port': None, 'qsd': {'verify': 'False'}, 'schema': 'mmosts'}
2017-07-05 17:58:52,611 - 41176 - DEBUG - MatterMost POST URL: https://domain.com:8065/hooks/wireapm5w7gfmek1jkr6zm000 (cert_verify=False)
2017-07-05 17:58:52,611 - 41176 - DEBUG - MatterMost Payload: {'text': 'test', 'icon_url': 'http://nzbget.lead2gold.org/notify/nzbget-notify-info-72x72.png'}
2017-07-05 17:58:52,648 - 41176 - INFO - Sent MatterMost notification.
2017-07-05 17:58:52,650 - 41176 - DEBUG - Exiting with return code: 93

c:\Program Files\SABnzbd\scripts>
seanvree commented 7 years ago

FYI: Yes, I did change the hook info to mask the data.

sabnzbdnotify

seanvree commented 7 years ago

@caronc -

Hey buddy! Thanks so much for this. The ONLY issue I"m having is that the BOT nick says webhook any way to change that?

caronc commented 7 years ago

Try mmost://newbotname@hostname/key and let me know! :)

seanvree commented 7 years ago

@caronc - Nope:

using : mmosts://sabnzbd@domain.com/wireapm5w7gfmek1jkr6zm0000?verify=False

 Notification script returned exit code 1 and output "2017-07-06 17:01:22,434 - 36664 - ERROR - Fatal Exception:
 Traceback (most recent call last):
 File "C:\Program Files\SABnzbd\scripts\Notify\nzbget\ScriptBase.py", line 2873, in run
 exit_code = main_function(*args, **kwargs)
 File "C:\Program Files\SABnzbd\scripts\Notify.py", line 1172, in main
 notify_type=notify_type,
 File "C:\Program Files\SABnzbd\scripts\Notify.py", line 964, in notify
 nobj.notify(body=body, title=title, notify_type=notify_type)
 File "C:\Program Files\SABnzbd\scripts\Notify\pnotify\NotifyBase.py", line 444, in notify
 **kwargs):
 File "C:\Program Files\SABnzbd\scripts\Notify\pnotify\NotifyMatterMost.py", line 110, in _notify
 payload['payload']['username'] = self.user
 KeyError: 'payload'

 "
caronc commented 7 years ago

Please check out the master and try again. Please keep me posted. Sorry about that and thanks for all of your patients and testing!

seanvree commented 7 years ago

@caronc - WORKED!

you're the man!