host.py (2115B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\datadog\dogshell\host.py 2 from __future__ import print_function 3 from datadog.util.format import pretty_json 4 from datadog import api 5 from datadog.dogshell.common import report_errors, report_warnings 6 from datadog.util.compat import json 7 8 class HostClient(object): 9 10 @classmethod 11 def setup_parser(cls, subparsers): 12 parser = subparsers.add_parser('host', help='Mute, unmute hosts') 13 verb_parsers = parser.add_subparsers(title='Verbs', dest='verb') 14 verb_parsers.required = True 15 mute_parser = verb_parsers.add_parser('mute', help='Mute a host') 16 mute_parser.add_argument('host_name', help='host to mute') 17 mute_parser.add_argument('--end', help='POSIX timestamp, if omitted, host will be muted until explicitly unmuted', default=None) 18 mute_parser.add_argument('--message', help='string to associate with the muting of this host', default=None) 19 mute_parser.add_argument('--override', help='true/false, if true and the host is already muted, will overwrite existing end on the host', action='store_true') 20 mute_parser.set_defaults(func=cls._mute) 21 unmute_parser = verb_parsers.add_parser('unmute', help='Unmute a host') 22 unmute_parser.add_argument('host_name', help='host to mute') 23 unmute_parser.set_defaults(func=cls._unmute) 24 25 @classmethod 26 def _mute(cls, args): 27 api._timeout = args.timeout 28 format = args.format 29 res = api.Host.mute(args.host_name, end=args.end, message=args.message, override=args.override) 30 report_warnings(res) 31 report_errors(res) 32 if format == 'pretty': 33 print(pretty_json(res)) 34 else: 35 print(json.dumps(res)) 36 37 @classmethod 38 def _unmute(cls, args): 39 api._timeout = args.timeout 40 format = args.format 41 res = api.Host.unmute(args.host_name) 42 report_warnings(res) 43 report_errors(res) 44 if format == 'pretty': 45 print(pretty_json(res)) 46 else: 47 print(json.dumps(res))