def main():
    # increase the verbosity
    # verbosity Python >= 2.7
    #unittest.main(verbosity=2)
    log.setLevel(logging.DEBUG)
    suite = unittest.TestLoader().loadTestsFromTestCase(RequestBS4HandlerTester)
    unittest.TextTestRunner(verbosity=2).run(suite)
def main():
    # increase the verbosity
    # verbosity Python >= 2.7
    #unittest.main(verbosity=2)
    log.setLevel(logging.DEBUG)
    suite = unittest.TestLoader().loadTestsFromTestCase(RestNagiosPluginTester)
    unittest.TextTestRunner(verbosity=2).run(suite)
def main():
    # increase the verbosity
    # verbosity Python >= 2.7
    #unittest.main(verbosity=2)
    log.setLevel(logging.DEBUG)
    suite = unittest.TestLoader().loadTestsFromTestCase(RestVersionNagiosPluginTester)
    unittest.TextTestRunner(verbosity=2).run(suite)
Example #4
0
 def process_args(self):
     log.setLevel(logging.INFO)
     self.no_args()
     regex = self.get_opt('regex')
     if regex:
         validate_regex(regex)
         self.table_regex = re.compile(regex, re.I)
         log.info('filtering to flush only tables matching regex \'{0}\''.format(regex))
Example #5
0
 def process_args(self):
     log.setLevel(logging.INFO)
     self.no_args()
     regex = self.get_opt('regex')
     if regex:
         validate_regex(regex)
         self.table_regex = re.compile(regex, re.I)
         log.info('filtering to flush only tables matching regex \'{0}\''.format(regex))
Example #6
0
File: cli.py Project: smutel/pylib
 def main(self):
     # log.debug('running main()')
     log.setLevel(logging.WARN)
     self.setup()
     try:
         self.add_options()
         self.add_default_opts()
     except InvalidOptionException as _:
         self.usage(_)
     try:
         self.__parse_args__()
         # broken
         # autoflush()
         # too late
         # os.environ['PYTHONUNBUFFERED'] = "anything"
         self.verbose = self.get_opt('verbose')
         if self.is_option_defined('quiet') and self.get_opt('quiet'):
             self.verbose = 0
         elif self.verbose > 2:
             log.setLevel(logging.DEBUG)
         elif self.verbose > 1:
             log.setLevel(logging.INFO)
         elif self.verbose > 0 and self._prog[0:6] != 'check_':
             log.setLevel(logging.WARN)
         if self.options.debug:
             log.setLevel(logging.DEBUG)  # pragma: no cover
             log.debug('enabling debug logging')
             if self.verbose < 3:
                 self.verbose = 3
         log.info('Hari Sekhon %s', self.version)
         log.info(self._github_repo)
         log.info('verbose level: %s (%s)', self.verbose, logging.getLevelName(log.getEffectiveLevel()))
         if self.timeout is not None:
             validate_int(self.timeout, 'timeout', 0, self.timeout_max)
             log.debug('setting timeout alarm (%s)', self.timeout)
             signal.signal(signal.SIGALRM, self.timeout_handler)
             signal.alarm(int(self.timeout))
         # if self.options.version:
         #     print(self.version)
         #     sys.exit(ERRORS['UNKNOWN'])
         self.process_options()
         self.process_args()
         try:
             self.run()
         except CriticalError as _:
             qquit('CRITICAL', _)
         except WarningError as _:
             qquit('WARNING', _)
         except UnknownError as _:
             qquit('UNKNOWN', _)
         self.__end__()
     except InvalidOptionException as _:
         self.usage(_)  # pragma: no cover
     except KeyboardInterrupt:
         # log.debug('Caught control-c...')
         print('Caught control-c...')  # pragma: no cover
Example #7
0
 def main(self):
     # log.debug('running main()')
     log.setLevel(logging.WARN)
     self.setup()
     try:
         self.add_options()
         self.add_default_opts()
     except InvalidOptionException as _:
         self.usage(_)
     try:
         self.__parse_args__()
         # broken
         # autoflush()
         # too late
         # os.environ['PYTHONUNBUFFERED'] = "anything"
         self.verbose = self.get_opt('verbose')
         if self.is_option_defined('quiet') and self.get_opt('quiet'):
             self.verbose = 0
         elif self.verbose > 2:
             log.setLevel(logging.DEBUG)
         elif self.verbose > 1:
             log.setLevel(logging.INFO)
         elif self.verbose > 0 and self._prog[0:6] != 'check_':
             log.setLevel(logging.WARN)
         if self.options.debug:
             log.setLevel(logging.DEBUG)  # pragma: no cover
             log.debug('enabling debug logging')
             if self.verbose < 3:
                 self.verbose = 3
         log.info('Hari Sekhon %s', self.version)
         log.info(self._github_repo)
         log.info('verbose level: %s (%s)', self.verbose, logging.getLevelName(log.getEffectiveLevel()))
         if self.timeout is not None:
             validate_int(self.timeout, 'timeout', 0, self.timeout_max)
             log.debug('setting timeout alarm (%s)', self.timeout)
             signal.signal(signal.SIGALRM, self.timeout_handler)
             signal.alarm(int(self.timeout))
         # if self.options.version:
         #     print(self.version)
         #     sys.exit(ERRORS['UNKNOWN'])
         self.process_options()
         self.process_args()
         try:
             self.run()
         except CriticalError as _:
             qquit('CRITICAL', _)
         except WarningError as _:
             qquit('WARNING', _)
         except UnknownError as _:
             qquit('UNKNOWN', _)
         self.__end__()
     except InvalidOptionException as _:
         self.usage(_)  # pragma: no cover
     except KeyboardInterrupt:
         # log.debug('Caught control-c...')
         print('Caught control-c...')  # pragma: no cover
 def process_args(self):
     log.setLevel(logging.INFO)
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     regex = self.get_opt('regex')
     if regex:
         validate_regex(regex)
         self.table_regex = re.compile(regex, re.I)
         log.info('filtering to compact only tables matching regex \'{0}\''.format(regex))
 def process_args(self):
     log.setLevel(logging.INFO)
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     regex = self.get_opt('regex')
     if regex:
         validate_regex(regex)
         self.table_regex = re.compile(regex, re.I)
         log.info("filtering to compact only tables matching regex \'%s\'",
                  regex)
Example #10
0
    def __parse_verbose__(self):
        self.verbose += int(self.get_opt('verbose'))
        env_verbose = os.getenv('VERBOSE')
        if isInt(env_verbose):
            if env_verbose > self.verbose:
                log.debug(
                    'environment variable $VERBOSE = %s, increasing verbosity',
                    env_verbose)
                self.verbose = int(env_verbose)
        elif env_verbose is None:
            pass
        else:
            log.warning(
                "$VERBOSE environment variable is not an integer ('%s')",
                env_verbose)

        if self.is_option_defined('quiet') and self.get_opt('quiet'):
            self.verbose = 0
        elif self.verbose > 2:
            log.setLevel(logging.DEBUG)
        elif self.verbose > 1:
            log.setLevel(logging.INFO)
        elif self.verbose > 0 and self._prog[0:6] != 'check_':
            log.setLevel(logging.WARN)
        if self.options.debug:
            log.setLevel(logging.DEBUG)  # pragma: no cover
            log.debug('enabling debug logging')
            if self.verbose < 3:
                self.verbose = 3
Example #11
0
 def main(self):
     # DEBUG env var is picked up immediately in pylib utils, do not override it here if so
     if os.getenv('DEBUG'):
         log.setLevel(logging.DEBUG)
     if not log.isEnabledFor(logging.DEBUG) and \
        not log.isEnabledFor(logging.ERROR): # do not downgrade logging either
         log.setLevel(logging.WARN)
     self.setup()
     try:
         self.add_options()
         self.add_default_opts()
     except InvalidOptionException as _:
         self.usage(_)
     try:
         self.__parse_args__()
         # broken
         # autoflush()
         # too late
         # os.environ['PYTHONUNBUFFERED'] = "anything"
         log.info('Hari Sekhon %s', self.version)
         log.info(self._github_repo)
         log.info('verbose level: %s (%s)', self.verbose,
                  logging.getLevelName(log.getEffectiveLevel()))
         if self.timeout is not None:
             validate_int(self.timeout, 'timeout', 0, self.timeout_max)
             log.debug('setting timeout alarm (%s)', self.timeout)
             signal.signal(signal.SIGALRM, self.timeout_handler)
             signal.alarm(int(self.timeout))
         # if self.options.version:
         #     print(self.version)
         #     sys.exit(ERRORS['UNKNOWN'])
         self.process_options()
         self.process_args()
         try:
             self.run()
         except CriticalError as _:
             qquit('CRITICAL', _)
         except WarningError as _:
             qquit('WARNING', _)
         except UnknownError as _:
             qquit('UNKNOWN', _)
         self.__end__()
     except InvalidOptionException as _:
         if log.isEnabledFor(logging.DEBUG):
             log.debug(traceback.format_exc())
         self.usage(_)  # pragma: no cover
     except KeyboardInterrupt:
         # log.debug('Caught control-c...')
         print('Caught control-c...')  # pragma: no cover
Example #12
0
 def __init__(self):
     # Python 2.x
     super(GeneosWrapper, self).__init__()
     # Python 3.x
     # super().__init__()
     # special case to make all following args belong to the passed in command and not to this program
     self._CLI__parser.disable_interspersed_args()
     self._CLI__parser.set_usage('{prog} [options] <check_nagios_plugin_name> <plugin_args> ...'.format(prog=prog))
     self.timeout_default = 60
     log.setLevel(logging.ERROR)
     self.returncodes = {}
     for key in ERRORS:
         self.returncodes[ERRORS[key]] = key
     self.perfdata_regex = re.compile(r'(\d+(?:\.\d+)?)([A-Za-z]{1,2}|%)?')
     self.status = "UNKNOWN"
     self.detail = "<None>"
     self.perfdata = []
     self.headers = ["STATUS", "DETAIL"]
Example #13
0
 def __init__(self):
     # Python 2.x
     super(AdapterCSV, self).__init__()
     # Python 3.x
     # super().__init__()
     # special case to make all following args belong to the passed in command and not to this program
     self._CLI__parser.disable_interspersed_args()
     self._CLI__parser.set_usage('{prog} [options] <nagios_plugin> <plugin_args> ...'.format(prog=prog))
     self.timeout_default = 60
     log.setLevel(logging.ERROR)
     self.returncodes = {}
     for key in ERRORS:
         self.returncodes[ERRORS[key]] = key
     self.perfdata_regex = re.compile(r'(\d+(?:\.\d+)?)([A-Za-z]{1,2}|%)?')
     self._status = 'UNKNOWN'
     self.message = '<None>'
     self.perfdata = []
     self.headers = ['STATUS', 'MESSAGE']
     self.separator = ','
Example #14
0
 def __init__(self):
     # Python 2.x
     super(GeneosWrapper, self).__init__()
     # Python 3.x
     # super().__init__()
     # special case to make all following args belong to the passed in command and not to this program
     self._CLI__parser.disable_interspersed_args()
     self._CLI__parser.set_usage(
         '{prog} [options] <check_nagios_plugin_name> <plugin_args> ...'.
         format(prog=prog))
     self.timeout_default = 60
     log.setLevel(logging.ERROR)
     self.returncodes = {}
     for key in ERRORS:
         self.returncodes[ERRORS[key]] = key
     self.perfdata_regex = re.compile(r'(\d+(?:\.\d+)?)([A-Za-z]{1,2}|%)?')
     self.status = "UNKNOWN"
     self.detail = "<None>"
     self.perfdata = []
     self.headers = ["STATUS", "DETAIL"]
Example #15
0
    def process_args(self):
        options, args = self.options, self.args

        log.setLevel(logging.WARN)
        if options.verbose > 1:
            log.setLevel(logging.DEBUG)
        elif options.verbose:
            log.setLevel(logging.INFO)
        # log.info('verbose level: %s' % options.verbose)

        try:
            validate_host(options.host)
            validate_port(options.port)
            validate_user(options.user)
            validate_password(options.password)
            if options.dir:
                validate_dirname(options.dir, 'blueprints')
            if options.file:
                if options.push:
                    validate_file(options.file, 'blueprint')
                if options.create_cluster:
                    validate_file(options.file, 'cluster hosts mapping')
        except InvalidOptionException as _:
            self.usage(_)

        if self.args:
            self.usage('additional args detected')

        if options.get and options.blueprint and options.cluster:
            self.usage(
                '--blueprint/--cluster are mutually exclusive when using --get'
            )
        elif options.push and options.create_cluster:
            self.usage('--push and --create-cluster are mutually exclusive')
        elif options.create_cluster and not options.cluster:
            self.usage(
                '--create-cluster requires specifying the name via --cluster')
        elif options.list_blueprints + options.list_clusters + options.list_hosts > 1:
            self.usage('can only use one --list switch at a time')
        elif options.file and (options.get
                               and not (options.blueprint or options.cluster)):
            self.usage("cannot specify --file without --blueprint/--cluster as it's only used " + \
                       "when getting or pushing a single blueprint")
        elif options.file and (options.push and not (options.create_cluster
                                                     or options.blueprint)):
            self.usage("cannot specify --file without --blueprint/--create-cluster as it's only used " + \
                       "when getting or pushing a single blueprint or creating a cluster based on the blueprint")
        return options, args
Example #16
0
    def process_args(self):
        options, args = self.options, self.args

        log.setLevel(logging.WARN)
        if options.verbose > 1:
            log.setLevel(logging.DEBUG)
        elif options.verbose:
            log.setLevel(logging.INFO)
        # log.info('verbose level: %s' % options.verbose)

        try:
            validate_host(options.host)
            validate_port(options.port)
            validate_user(options.user)
            validate_password(options.password)
            if options.dir:
                validate_dirname(options.dir, 'blueprints')
            if options.file:
                if options.push:
                    validate_file(options.file, 'blueprint')
                if options.create_cluster:
                    validate_file(options.file, 'cluster hosts mapping')
        except InvalidOptionException as _:
            self.usage(_)

        if self.args:
            self.usage('additional args detected')

        if options.get and options.blueprint and options.cluster:
            self.usage('--blueprint/--cluster are mutually exclusive when using --get')
        elif options.push and options.create_cluster:
            self.usage('--push and --create-cluster are mutually exclusive')
        elif options.create_cluster and not options.cluster:
            self.usage('--create-cluster requires specifying the name via --cluster')
        elif options.list_blueprints + options.list_clusters + options.list_hosts > 1:
            self.usage('can only use one --list switch at a time')
        elif options.file and (options.get and not (options.blueprint or options.cluster)):
            self.usage("cannot specify --file without --blueprint/--cluster as it's only used " + \
                       "when getting or pushing a single blueprint")
        elif options.file and (options.push and not (options.create_cluster or options.blueprint)):
            self.usage("cannot specify --file without --blueprint/--create-cluster as it's only used " + \
                       "when getting or pushing a single blueprint or creating a cluster based on the blueprint")
        return options, args
Example #17
0
 def setup(self):  # pylint: disable=no-self-use
     log.setLevel(logging.ERROR)
 def setup(self):  # pylint: disable=no-self-use
     log.setLevel(logging.ERROR)