service_check.py (1820B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\datadog\dogshell\service_check.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 ServiceCheckClient(object): 9 10 @classmethod 11 def setup_parser(cls, subparsers): 12 parser = subparsers.add_parser('service_check', help='Perform service checks') 13 verb_parsers = parser.add_subparsers(title='Verbs', dest='verb') 14 verb_parsers.required = True 15 check_parser = verb_parsers.add_parser('check', help='text for the message') 16 check_parser.add_argument('check', help='text for the message') 17 check_parser.add_argument('host_name', help='name of the host submitting the check') 18 check_parser.add_argument('status', help="integer for the status of the check. i.e: '0': OK, '1': WARNING, '2': CRITICAL, '3': UNKNOWN") 19 check_parser.add_argument('--timestamp', help='POSIX timestamp of the event', default=None) 20 check_parser.add_argument('--message', help='description of why this status occurred', default=None) 21 check_parser.add_argument('--tags', help='comma separated list of tags', default=None) 22 check_parser.set_defaults(func=cls._check) 23 24 @classmethod 25 def _check(cls, args): 26 api._timeout = args.timeout 27 format = args.format 28 res = api.ServiceCheck.check(check=args.check, host_name=args.host_name, status=int(args.status), timestamp=args.timestamp, message=args.message, tags=args.tags) 29 report_warnings(res) 30 report_errors(res) 31 if format == 'pretty': 32 print(pretty_json(res)) 33 else: 34 print(json.dumps(res))