From a6d56283e1d32481154888628abf45a8fc65252c Mon Sep 17 00:00:00 2001 From: Akom Date: Thu, 3 Oct 2019 11:55:11 -0400 Subject: [PATCH] Do not show redundant hostaddress if equals hostalias --- mattermost.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mattermost.py b/mattermost.py index 9a96302..e250964 100755 --- a/mattermost.py +++ b/mattermost.py @@ -40,10 +40,10 @@ def parse(): parser.add_argument('--hostalias', help='Host Alias', required=True) parser.add_argument('--hostaddress', help='Host Address', required=True) parser.add_argument('--hoststate', help='Host State') - parser.add_argument('--hostoutput', help='Host Output') + parser.add_argument('--hostoutput', help='Host Output', default='') parser.add_argument('--servicedesc', help='Service Description') parser.add_argument('--servicestate', help='Service State') - parser.add_argument('--serviceoutput', help='Service Output') + parser.add_argument('--serviceoutput', help='Service Output', default='') parser.add_argument('--cgiurl', help='Link to extinfo.cgi on your Nagios instance') parser.add_argument('--version', action='version', version='% (prog)s {version}'.format(version=VERSION)) @@ -68,7 +68,10 @@ def emoji(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_service_with_alias = "__{notificationtype}__ {hostalias} at {hostaddress}/{servicedesc} is {servicestate}\n{serviceoutput}" # noqa + template_service_without_alias = "__{notificationtype}__ {hostaddress}/{servicedesc} is {servicestate}\n{serviceoutput}" # noqa + template_service = template_service_without_alias if args.hostalias == args.hostaddress else template_service_with_alias + if args.hoststate is not None: template_cgiurl = " [View :link:]({cgiurl}?type=1&host={hostalias})" elif args.servicestate is not None: