NDrive/nagios-mattermost

notifications fail when output ends with semicolon (;)

apagr opened this issue · 1 comments

apagr commented

[2017-11-13 06:31:33 +0100] warning/PluginNotificationTask: Notification command for object 'blahblahhostname!disk /mnt/backup' (PID: 24573, arguments: '/usr/lib/nagios/plugins/mattermost.py' '--channel' 'monit' '--hostalias' 'blahblahhostname' '--notificationtype' 'PROBLEM' '--servicedesc' 'disk /mnt/backup' '--serviceoutput' 'DISK CRITICAL - free space: /mnt/backup 41212 MB (3% inode=-)];' '--servicestate' 'CRITICAL' '--url' '(valid webhook)') terminated with exit code 1, output: Traceback (most recent call last):
File "/usr/lib/nagios/plugins/mattermost.py", line 107, in
response = request(args.url, payload(args))
File "/usr/lib/nagios/plugins/mattermost.py", line 101, in request
response = urllib2.urlopen(req)
File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 437, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 475, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request

works after removing semicolon of output.

standard plugin output below:

# /usr/lib/nagios/plugins/check_disk /home
DISK OK - free space: / 937211 MB (53% inode=96%);| /=798526MB;;;0;1828650
# 

We noticed a problem with semicolons as well, but I cannot confirm it happens only when they're at the end of a line. I solved it with this trivial patch.