1 changed file
.pylintrc | ||
Add comment 1 Plus #!/usr/bin/env python
Add comment 2 Plus # vim:ts=4:sts=4:sw=4:et
Add comment 3 Plus #
Add comment 4 Plus # Author: Hari Sekhon
Add comment 5 Plus # Date: 2017-06-27 23:14:03 +0200 (Tue, 27 Jun 2017)
Add comment 6 Plus #
Add comment 7 Plus # https://github.com/harisekhon/nagios-plugins
Add comment 8 Plus #
Add comment 9 Plus # License: see accompanying Hari Sekhon LICENSE file
Add comment 10 Plus #
Add comment 11 Plus # If you're using my code you're welcome to connect with me on LinkedIn
Add comment 12 Plus # and optionally send me feedback to help steer this or other code I publish
Add comment 13 Plus #
Add comment 14 Plus # https://www.linkedin.com/in/harisekhon
Add comment 15 Plus #
Add comment 16 Plus
Add comment 17 Plus """
Add comment 18 Plus
Add comment 19 Plus Nagios Plugin to check security is enabled on a Jenkins server via the Rest API
Add comment 20 Plus
Add comment 21 Plus The --password switch accepts either a password or an API token
Add comment 22 Plus
Add comment 23 Plus Tested on Jenkins 2.60.1
Add comment 24 Plus
Add comment 25 Plus """
Add comment 26 Plus
Add comment 27 Plus from __future__ import absolute_import
Add comment 28 Plus from __future__ import division
Add comment 29 Plus from __future__ import print_function
Add comment 30 Plus from __future__ import unicode_literals
Add comment 31 Plus
Add comment 32 Plus import os
Add comment 33 Plus import sys
Add comment 34 Plus import traceback
Add comment 35 Plus srcdir = os.path.abspath(os.path.dirname(__file__))
Add comment 36 Plus libdir = os.path.join(srcdir, 'pylib')
Add comment 37 Plus sys.path.append(libdir)
Add comment 38 Plus try:
Add comment 39 Plus # pylint: disable=wrong-import-position
Add comment 40 Plus from harisekhon import RestNagiosPlugin
Add comment 41 Plus from harisekhon.utils import UnknownError, support_msg_api
Add comment 42 Plus except ImportError as _:
Add comment 43 Plus print(traceback.format_exc(), end='')
Add comment 44 Plus sys.exit(4)
Add comment 45 Plus
Add comment 46 Plus __author__ = 'Hari Sekhon'
Add comment 47 Plus __version__ = '0.1'
Add comment 48 Plus
Add comment 49 Plus
Add comment 50 Plus # pylint: disable=too-few-public-methods
Add comment 51 Plus class CheckJenkinsSecurityEnabled(RestNagiosPlugin):
Add comment 52 Plus
Add comment 53 Plus def __init__(self):
Add comment 54 Plus # Python 2.x
Add comment 55 Plus super(CheckJenkinsSecurityEnabled, self).__init__()
Add comment 56 Plus # Python 3.x
Add comment 57 Plus # super().__init__()
Add comment 58 Plus self.name = 'Jenkins'
Add comment 59 Plus self.default_port = 8080
Add comment 60 Plus self.path = '/api/json'
Add comment 61 Plus self.json = True
Add comment 62 Plus self.msg = self.name + ' security enabled = '
Add comment 63 Plus
Add comment 64 Plus def parse_json(self, json_data):
Add comment 65 Plus use_security = json_data['useSecurity']
Add comment 66 Plus if not isinstance(use_security, bool):
Add comment 67 Plus raise UnknownError('non-boolean returned by Jenkins. {0}'.format(support_msg_api()))
Add comment 68 Plus
Add comment 69 Plus self.msg += '{0}'.format(use_security)
Add comment 70 Plus if not use_security:
Add comment 71 Plus self.msg += ' (expected \'True\')'
Add comment 72 Plus self.critical()
Add comment 73 Plus
Add comment 74 Plus
Add comment 75 Plus if __name__ == '__main__':
Add comment 76 Plus CheckJenkinsSecurityEnabled().main()
Add comment 77 Plus