1 changed file
check_opentsdb_version.py + | ||
Add comment 1 Plus #!/usr/bin/env python
Add comment 2 Plus # coding=utf-8
Add comment 3 Plus # vim:ts=4:sts=4:sw=4:et
Add comment 4 Plus #
Add comment 5 Plus # Author: Hari Sekhon
Add comment 6 Plus # Date: 2018-01-15 17:59:23 +0000 (Mon, 15 Jan 2018)
Add comment 7 Plus #
Add comment 8 Plus # https://github.com/harisekhon/nagios-plugins
Add comment 9 Plus #
Add comment 10 Plus # License: see accompanying Hari Sekhon LICENSE file
Add comment 11 Plus #
Add comment 12 Plus # If you're using my code you're welcome to connect with me on LinkedIn
Add comment 13 Plus # and optionally send me feedback to help steer this or other code I publish
Add comment 14 Plus #
Add comment 15 Plus # https://www.linkedin.com/in/harisekhon
Add comment 16 Plus #
Add comment 17 Plus
Add comment 18 Plus """
Add comment 19 Plus
Add comment 20 Plus Nagios Plugin to check the version of OpenTSDB via its Rest API
Add comment 21 Plus
Add comment 22 Plus Tested on OpenTSDB 2.2
Add comment 23 Plus
Add comment 24 Plus """
Add comment 25 Plus
Add comment 26 Plus from __future__ import absolute_import
Add comment 27 Plus from __future__ import division
Add comment 28 Plus from __future__ import print_function
Add comment 29 Plus from __future__ import unicode_literals
Add comment 30 Plus
Add comment 31 Plus import os
Add comment 32 Plus import sys
Add comment 33 Plus import traceback
Add comment 34 Plus srcdir = os.path.abspath(os.path.dirname(__file__))
Add comment 35 Plus libdir = os.path.join(srcdir, 'pylib')
Add comment 36 Plus sys.path.append(libdir)
Add comment 37 Plus try:
Add comment 38 Plus # pylint: disable=wrong-import-position
Add comment 39 Plus #from harisekhon.utils import support_msg_api
Add comment 40 Plus from harisekhon import RestVersionNagiosPlugin
Add comment 41 Plus except ImportError as _:
Add comment 42 Plus print(traceback.format_exc(), end='')
Add comment 43 Plus sys.exit(4)
Add comment 44 Plus
Add comment 45 Plus __author__ = 'Hari Sekhon'
Add comment 46 Plus __version__ = '0.1'
Add comment 47 Plus
Add comment 48 Plus
Add comment 49 Plus # pylint: disable=too-few-public-methods
Add comment 50 Plus class CheckOpenTSDBVersion(RestVersionNagiosPlugin):
Add comment 51 Plus
Add comment 52 Plus def __init__(self):
Add comment 53 Plus # Python 2.x
Add comment 54 Plus super(CheckOpenTSDBVersion, self).__init__()
Add comment 55 Plus # Python 3.x
Add comment 56 Plus # super().__init__()
Add comment 57 Plus self.name = 'OpenTSDB'
Add comment 58 Plus self.default_port = 4242
Add comment 59 Plus self.path = '/api/version'
Add comment 60 Plus self.json = True
Add comment 61 Plus self.auth = False
Add comment 62 Plus self.json_data = None
Add comment 63 Plus self.ok()
Add comment 64 Plus
Add comment 65 Plus def parse_json(self, json_data):
Add comment 66 Plus self.json_data = json_data
Add comment 67 Plus version = json_data['version']
Add comment 68 Plus #version = version.split('-')[0]
Add comment 69 Plus #if not self.verbose:
Add comment 70 Plus # version = '.'.join(version.split('.')[0:3])
Add comment 71 Plus return version
Add comment 72 Plus
Add comment 73 Plus
Add comment 74 Plus if __name__ == '__main__':
Add comment 75 Plus CheckOpenTSDBVersion().main()
Add comment 76 Plus