integrations/nagios: Upgrade to argparse.

This commit is contained in:
Eeshan Garg 2017-08-02 00:58:55 -02:30
parent 18a73324a9
commit c4480311d7

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import optparse import argparse
import zulip import zulip
from typing import List, Text, Dict, Any from typing import List, Text, Dict, Any
@ -8,14 +8,14 @@ VERSION = "0.9"
# Nagios passes the notification details as command line options. # Nagios passes the notification details as command line options.
# In Nagios, "output" means "first line of output", and "long # In Nagios, "output" means "first line of output", and "long
# output" means "other lines of output". # output" means "other lines of output".
parser = optparse.OptionParser() # type: optparse.OptionParser parser = zulip.add_default_arguments(argparse.ArgumentParser()) # type: argparse.ArgumentParser
parser.add_option('--output', default='') parser.add_argument('--output', default='')
parser.add_option('--long-output', default='') parser.add_argument('--long-output', default='')
parser.add_option('--stream', default='nagios') parser.add_argument('--stream', default='nagios')
parser.add_option('--config', default='/etc/nagios3/zuliprc') parser.add_argument('--config', default='/etc/nagios3/zuliprc')
for opt in ('type', 'host', 'service', 'state'): for opt in ('type', 'host', 'service', 'state'):
parser.add_option('--' + opt) parser.add_argument('--' + opt)
(opts, args) = parser.parse_args() # type: Any, List[Text] opts = parser.parse_args()
client = zulip.Client(config_file=opts.config, client = zulip.Client(config_file=opts.config,
client="ZulipNagios/" + VERSION) # type: zulip.Client client="ZulipNagios/" + VERSION) # type: zulip.Client