def run(self):
     self.no_args()
     directory = self.get_opt('directory')
     validate_directory(directory)
     directory = os.path.abspath(directory)
     expected_branch = self.get_opt('branch')
     if expected_branch is None:
         self.usage('expected branch not defined')
     if not re.match(r'^[\w\s-]+$', expected_branch):
         self.usage('Invalid branch name given, must be alphanumeric' + \
                    ', may contain dashes and spaces for detached HEADs')
     log_option('expected branch', expected_branch)
     try:
         repo = git.Repo(directory)
     except InvalidGitRepositoryError as _:
         raise CriticalError("directory '{}' does not contain a valid Git repository!".format(directory))
     try:
         current_branch = repo.active_branch.name
     # happens with detached HEAD checkout like Travis CI does
     except TypeError as _:
         raise CriticalError(_)
     if current_branch == expected_branch:
         self.ok()
         self.msg = "git branch '{0}' currently checked out in directory '{1}'"\
                    .format(current_branch, directory)
     else:
         raise CriticalError("git branch '{0}' checked out, expecting '{1}' in directory '{2}'"
                             .format(current_branch, expected_branch, directory))
 def run(self):
     if not self.args:
         self.usage('no Dockerfile / directory args given')
     args = uniq_list_ordered(self.args)
     self.tag_prefix = self.get_opt('tag_prefix')
     if self.tag_prefix is not None:
         validate_regex(self.tag_prefix, 'tag prefix')
         self.tag_prefix = re.compile(self.tag_prefix)
     for arg in args:
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory"
                 % arg)
     for arg in args:
         self.check_git_tags_dockerfiles(arg)
     if self.failed:
         log.error('Dockerfile validation FAILED')
         sys.exit(ERRORS['CRITICAL'])
     log.info('Dockerfile validation SUCCEEDED')
 def run(self):
     if not self.args:
         self.usage('no git directory args given')
     self.origin = self.get_opt('origin')
     args = uniq_list_ordered(self.args)
     self.branch_prefix = self.get_opt('branch_prefix')
     if self.branch_prefix is not None:
         validate_regex(self.branch_prefix, 'branch prefix')
         self.branch_prefix = re.compile(self.branch_prefix)
     for arg in args:
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory" % arg)
     for arg in args:
         self.check_git_branches_upstream(arg)
     if self.status == "OK":
         log.info('SUCCESS - All Git branches are tracking the expected upstream origin branches')
     else:
         log.critical('FAILED')
         sys.exit(ERRORS['CRITICAL'])
    def process_args(self):
        # this resets DEBUG env var
        #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)

        self.table = self.get_opt('table')
        self.num_rows = self.get_opt('num')
        self.key_length = self.get_opt('key_length')
        self.value_length = self.get_opt('value_length')

        validate_database_tablename(self.table)
        validate_int(self.num_rows, 'num rows', 1, 1000000000)
        validate_int(self.key_length, 'key length', 10, 1000)
        validate_int(self.value_length, 'value length', 1, 1000000)

        self.num_rows = int(self.num_rows)

        self.skew = self.get_opt('skew')
        log_option('skew data', self.skew)
        self.skew_pc = self.get_opt('skew_percentage')
        validate_int(self.skew_pc, 'skew percentage', 0, 100)
        self.skew_pc = int(self.skew_pc)
        self.drop_table = self.get_opt('drop_table')
        self.use_existing_table = self.get_opt('use_existing_table')

        if self.drop_table and self.table != self.default_table_name:
            die("not allowed to use --drop-table if using a table name other than the default table '{0}'"\
                .format(self.default_table_name))
Exemple #5
0
 def run(self):
     self.no_args()
     directory = self.get_opt('directory')
     validate_directory(directory)
     directory = os.path.abspath(directory)
     expected_branch = self.get_opt('branch')
     if expected_branch is None:
         self.usage('expected branch not defined')
     if not re.match(r'^[\w-]+$', expected_branch):
         self.usage(
             'Invalid branch name given, must be alphanumeric, may contain dashes'
         )
     log_option('expected branch', expected_branch)
     repo = git.Repo(directory)
     current_branch = repo.active_branch.name
     if current_branch == expected_branch:
         qquit(
             'OK',
             "branch '{0}' currently checked out in directory '{1}'".format(
                 current_branch, directory))
     else:
         qquit(
             'CRITICAL',
             "branch '{0}' checked out, expecting '{1}' in directory '{2}'".
             format(current_branch, expected_branch, directory))
Exemple #6
0
    def process_args(self):
        # this resets DEBUG env var
        #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)
        # happybase socket requires an integer
        self.port = int(self.port)

        self.table = self.get_opt('table')
        self.num_rows = self.get_opt('num')
        self.key_length = self.get_opt('key_length')
        self.value_length = self.get_opt('value_length')

        validate_database_tablename(self.table)
        validate_int(self.num_rows, 'num rows', 1, 1000000000)
        validate_int(self.key_length, 'key length', 10, 1000)
        validate_int(self.value_length, 'value length', 1, 1000000)

        self.num_rows = int(self.num_rows)

        self.skew = self.get_opt('skew')
        log_option('skew data', self.skew)
        self.skew_pc = self.get_opt('skew_percentage')
        validate_int(self.skew_pc, 'skew percentage', 0, 100)
        self.skew_pc = int(self.skew_pc)
        self.drop_table = self.get_opt('drop_table')
        self.use_existing_table = self.get_opt('use_existing_table')

        if self.drop_table and self.table != self.default_table_name:
            die("not allowed to use --drop-table if using a table name other than the default table '{0}'"\
                .format(self.default_table_name))
 def run(self):
     args = self.process_args()
     for arg in args:
         if not os.path.exists(arg):
             _ = "'%s' not found" % arg
             if self.skip_errors:
                 print(_)
                 self.failed = True
             else:
                 die(_)
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory" % arg)
     for arg in args:
         try:
             self.check_path(arg)
         except OSError as _:
             if self.skip_errors:
                 print(_)
                 self.failed = True
             else:
                 die(_)
     if self.failed:
         sys.exit(2)
Exemple #8
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     if self.auth:
         self.user = self.get_opt('user')
         self.password = self.get_opt('password')
         if self.auth == 'optional':
             if self.user and self.password:
                 validate_user(self.user)
                 validate_password(self.password)
         else:
             validate_user(self.user)
             validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl and self.protocol == 'http':
         self.protocol = 'https'
     if self.json:
         # recommended for many systems like CouchDB
         # but breaks Ambari API calls
         #self.headers['Accept'] = 'application/json'
         self.headers['Content-Type'] = 'application/json'
 def process_args(self):
     args = uniq_list_ordered(self.args)
     if not args:
         self.usage('no directories specified as arguments')
     log_option('directories', args)
     self.compare_by_name = self.get_opt('name')
     self.compare_by_size = self.get_opt('size')
     self.compare_by_checksum = self.get_opt('checksum')
     self.regex = self.get_opt('regex')
     self.quiet = self.get_opt('quiet')
     self.no_short_circuit = self.get_opt('no_short_circuit')
     self.include_dot_dirs = self.get_opt('include_dot_dirs')
     if self.regex:
         if '(' not in self.regex:
             log.info('regex no capture brackets specified, will capture entire given regex')
             self.regex = '(' + self.regex + ')'
         validate_regex(self.regex)
         self.re_compiled = re.compile(self.regex, re.I)
     if not (self.compare_by_name or self.compare_by_size or self.compare_by_checksum or self.regex):
         self.compare_by_name = True
         #self.compare_by_size = True
         self.compare_by_checksum = True
     log_option('compare by name', self.compare_by_name)
     log_option('compare by size', self.compare_by_size)
     log_option('compare by checksum', self.compare_by_checksum)
     log_option('compare by regex', True if self.regex else False)
     return args
 def run(self):
     if not self.args:
         self.usage('no git directory args given')
     self.origin = self.get_opt('origin')
     args = uniq_list_ordered(self.args)
     self.branch_prefix = self.get_opt('branch_prefix')
     if self.branch_prefix is not None:
         validate_regex(self.branch_prefix, 'branch prefix')
         self.branch_prefix = re.compile(self.branch_prefix)
     for arg in args:
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory"
                 % arg)
     for arg in args:
         self.check_git_branches_upstream(arg)
     if self.status == "OK":
         log.info(
             'SUCCESS - All Git branches are tracking the expected upstream origin branches'
         )
     else:
         log.critical('FAILED')
         sys.exit(ERRORS['CRITICAL'])
 def run(self):
     self.no_args()
     directory = self.get_opt('directory')
     validate_directory(directory)
     directory = os.path.abspath(directory)
     expected_branch = self.get_opt('branch')
     if expected_branch is None:
         self.usage('expected branch not defined')
     if not re.match(r'^[\w\s-]+$', expected_branch):
         self.usage('Invalid branch name given, must be alphanumeric' + \
                    ', may contain dashes and spaces for detached HEADs')
     log_option('expected branch', expected_branch)
     try:
         repo = git.Repo(directory)
     except git.InvalidGitRepositoryError as _:
         raise CriticalError(
             "directory '{}' does not contain a valid Git repository!".
             format(directory))
     try:
         current_branch = repo.active_branch.name
     # happens with detached HEAD checkout like Travis CI does
     except TypeError as _:
         raise CriticalError(_)
     if current_branch == expected_branch:
         self.ok()
         self.msg = "git branch '{0}' currently checked out in directory '{1}'"\
                    .format(current_branch, directory)
     else:
         raise CriticalError(
             "git branch '{current_branch}' checked out".format(
                 current_branch=current_branch) +
             ", expecting branch '{expected_branch}' in directory '{directory}'"
             .format(expected_branch=expected_branch, directory=directory))
Exemple #12
0
 def process_args(self):
     args = uniq_list_ordered(self.args)
     if not args:
         self.usage('no directories specified as arguments')
     log_option('directories', args)
     self.compare_by_name = self.get_opt('name')
     self.compare_by_size = self.get_opt('size')
     self.compare_by_checksum = self.get_opt('checksum')
     self.regex = self.get_opt('regex')
     self.quiet = self.get_opt('quiet')
     self.no_short_circuit = self.get_opt('no_short_circuit')
     self.include_dot_dirs = self.get_opt('include_dot_dirs')
     if self.regex:
         if '(' not in self.regex:
             log.info(
                 'regex no capture brackets specified, will capture entire given regex'
             )
             self.regex = '(' + self.regex + ')'
         validate_regex(self.regex)
         self.re_compiled = re.compile(self.regex, re.I)
     if not (self.compare_by_name or self.compare_by_size
             or self.compare_by_checksum or self.regex):
         self.compare_by_name = True
         #self.compare_by_size = True
         self.compare_by_checksum = True
     log_option('compare by name', self.compare_by_name)
     log_option('compare by size', self.compare_by_size)
     log_option('compare by checksum', self.compare_by_checksum)
     log_option('compare by regex', True if self.regex else False)
     return args
 def process_options(self):
     super(CheckAtlasEntity, self).process_options()
     self.entity_name = self.get_opt('entity_name')
     self.entity_id = self.get_opt('entity_id')
     self.list_entities = self.get_opt('list')
     if not self.list_entities:
         if not self.entity_name and not self.entity_id:
             self.usage('must supply an --entity-id/--entity-name to find or --list-entities')
         if self.entity_name and self.entity_id:
             self.usage('cannot specify both --entity-id and --entity-name as the search criteria ' +
                        'at the same time, prefer --entity-id it\'s more efficient')
         if self.entity_name:
             # this can contain pretty much anything including /haritest
             #validate_chars(self.entity_name, 'entity name', r'A-Za-z0-9\.\,_-')
             log_option('entity_name', self.entity_name)
         if self.entity_id:
             validate_chars(self.entity_id, 'entity id', r'A-Za-z0-9-')
             # v1
             self.path += '/{0}'.format(self.entity_id)
             # v2
             #self.path += '/guids?guid={0}'.format(self.entity_id)
     self._type = self.get_opt('type')
     self.tags = self.get_opt('tags')
     #self.traits = self.get_opt('traits')
     if self._type:
         validate_chars(self._type, 'type', r'A-Za-z0-9_-')
     if self.tags:
         self.tags = sorted(self.tags.split(','))
         for tag in self.tags:
             validate_chars(tag, 'tag', r'A-Za-z0-9\.\,_-')
     if self.traits:
         self.traits = sorted(self.traits.split(','))
         for trait in self.traits:
             validate_chars(trait, 'trait', r'A-Za-z0-9\.\,_-')
 def process_options(self):
     super(CheckAtlasEntity, self).process_options()
     self.entity_name = self.get_opt('entity_name')
     self.entity_id = self.get_opt('entity_id')
     self.list_entities = self.get_opt('list')
     if not self.list_entities:
         if not self.entity_name and not self.entity_id:
             self.usage('must supply an --entity-id/--entity-name to find or --list-entities')
         if self.entity_name and self.entity_id:
             self.usage('cannot specify both --entity-id and --entity-name as the search criteria ' +
                        'at the same time, prefer --entity-id it\'s more efficient')
         if self.entity_name:
             # this can contain pretty much anything including /haritest
             #validate_chars(self.entity_name, 'entity name', r'A-Za-z0-9\.\,_-')
             log_option('entity_name', self.entity_name)
         if self.entity_id:
             validate_chars(self.entity_id, 'entity id', r'A-Za-z0-9-')
             # v1
             self.path += '/{0}'.format(self.entity_id)
             # v2
             #self.path += '/guids?guid={0}'.format(self.entity_id)
     self._type = self.get_opt('type')
     self.tags = self.get_opt('tags')
     #self.traits = self.get_opt('traits')
     if self._type:
         validate_chars(self._type, 'type', r'A-Za-z0-9_-')
     if self.tags:
         self.tags = sorted(self.tags.split(','))
         for tag in self.tags:
             validate_chars(tag, 'tag', r'A-Za-z0-9\.\,_-')
     if self.traits:
         self.traits = sorted(self.traits.split(','))
         for trait in self.traits:
             validate_chars(trait, 'trait', r'A-Za-z0-9\.\,_-')
 def add_common_opts(self):
     if self.is_option_defined('ssl'):
         if self.get_opt('ssl'):
             self.protocol = 'https'
             log_option('SSL', 'true')
         else:
             log_option('SSL', 'false')
     self.add_opt('-q', '--quiet', action='store_true', help='Returns no output instead of NO_AVAILABLE_SERVER '\
                                                           + '(convenience for scripting)')
     self.add_opt('-n', '--num-threads', default=self.default_num_threads, type='int',
                  help='Number or parallel threads to speed up processing ' + \
                       '(default is 4 times number of cores: {}), '.format(self.default_num_threads) + \
                       'use -n=1 for deterministic host preference order [slower])')
     self.add_opt(
         '-T',
         '--request-timeout',
         metavar='secs',
         type='int',
         default=os.getenv('REQUEST_TIMEOUT', 2),
         help=
         'Timeout for each individual server request in seconds ($REQUEST_TIMEOUT, default: 2 secs)'
     )
     self.add_opt('-R',
                  '--random',
                  action='store_true',
                  help='Randomize order of hosts tested ' +
                  '(for use with --num-threads=1)')
 def run(self):
     args = self.process_args()
     for arg in args:
         if not os.path.exists(arg):
             _ = "'%s' not found" % arg
             if self.skip_errors:
                 print(_)
                 self.failed = True
             else:
                 die(_)
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory"
                 % arg)
     for arg in args:
         try:
             self.check_path(arg)
         except OSError as _:
             if self.skip_errors:
                 print(_)
                 self.failed = True
             else:
                 die(_)
     if self.failed:
         sys.exit(2)
Exemple #17
0
 def run(self):
     self.no_args()
     directory = self.get_opt('directory')
     validate_directory(directory)
     directory = os.path.abspath(directory)
     expected_branch = self.get_opt('branch')
     if expected_branch is None:
         self.usage('expected branch not defined')
     if not re.match(r'^[\w-]+$', expected_branch):
         self.usage(
             'Invalid branch name given, must be alphanumeric, may contain dashes'
         )
     log_option('expected branch', expected_branch)
     repo = git.Repo(directory)
     try:
         current_branch = repo.active_branch.name
     # happens with detached HEAD checkout like Travis CI does
     except TypeError as _:
         raise CriticalError(_)
     if current_branch == expected_branch:
         self.ok()
         self.msg = "branch '{0}' currently checked out in directory '{1}'"\
                    .format(current_branch, directory)
     else:
         raise CriticalError(
             "branch '{0}' checked out, expecting '{1}' in directory '{2}'".
             format(current_branch, expected_branch, directory))
Exemple #18
0
 def process_docker_options(self):
     # should look like unix:///var/run/docker.sock or tcp://127.0.0.1:1234
     self.base_url = self.get_opt('base_url')
     if self.base_url:
         validate_chars(self.base_url, 'base url', r'A-Za-z0-9\/\:\.')
     self.tls = self.get_opt('tls')
     if not self.tls and os.getenv('DOCKER_TLS_VERIFY'):
         self.tls = True
     log_option('tls', self.tls)
     if self.tls:
         ca_file = self.get_opt('tlscacert')
         cert_file = self.get_opt('tlscert')
         key_file = self.get_opt('tlskey')
         tls_verify = self.get_opt('tlsverify')
         docker_cert_path = os.getenv('DOCKER_CERT_PATH')
         if docker_cert_path:
             if not ca_file:
                 ca_file = os.path.join(docker_cert_path, 'ca.pem')
             if not cert_file:
                 cert_file = os.path.join(docker_cert_path, 'cert.pem')
             if not key_file:
                 key_file = os.path.join(docker_cert_path, 'key.pem')
             if not tls_verify and os.getenv('DOCKER_TLS_VERIFY'):
                 tls_verify = True
         validate_file(ca_file, 'TLS CA cert file')
         validate_file(cert_file, 'TLS cert file')
         validate_file(key_file, 'TLS key file')
         log_option('TLS verify', tls_verify)
         self.tls_config = docker.tls.TLSConfig(
             ca_cert=ca_file,  # pylint: disable=redefined-variable-type
             verify=tls_verify,
             client_cert=(cert_file, key_file))
 def local_main(self, table_conn):
     self.no_region_col = self.get_opt('no_region_name')
     self.sort = self.get_opt('sort')
     self.sort_desc = self.get_opt('desc')
     if self.sort is not None:
         self.sort = self.sort.lower()
         if self.sort not in self.valid_sorts:
             self.usage(
                 'invalid --sort option given, must be one of: {0}'.format(
                     ', '.join(self.valid_sorts)))
     log_option('no region name', self.no_region_col)
     log_option('sort', self.sort)
     if self.no_region_col:
         self.total_width -= self.region_width
     num_regions = len(self._regions)
     # sanity check and protect against division by zero in summary stats
     if num_regions < 1:
         die('number of regions detected = {0:d} (< 1)'.format(num_regions))
     self.populate_region_metadata()
     self.calculate_widths()
     self.populate_row_counts(table_conn)
     self.calculate_row_count_widths()
     self.calculate_row_percentages()
     self.print_table_region_row_counts()
     self.print_summary()
 def process_broker_args(self):
     self.brokers = self.get_opt('brokers')
     host = self.get_opt('host')
     port = self.get_opt('port')
     host_env = os.getenv('KAFKA_HOST')
     port_env = os.getenv('KAFKA_PORT')
     if not host:
         # protect against blank strings in env vars
         if host_env:
             host = host_env
         else:
             host = self.default_host
     if not port:
         # protect against blank strings in env vars
         if port_env:
             port = port_env
         else:
             port = self.default_port
     brokers_env = os.getenv('KAFKA_BROKERS')
     if not self.brokers:
         if brokers_env:
             self.brokers = brokers_env
         else:
             self.brokers = '{0}:{1}'.format(host, port)
     brokers = ''
     for broker in self.brokers.split(','):
         if ':' not in broker:
             broker += ':{0}'.format(port)
         validate_hostport(broker)
         brokers += '{0}, '.format(broker)
     brokers = brokers.rstrip(', ')
     self.brokers = brokers
     log_option('brokers', self.brokers)
Exemple #21
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        user = self.get_opt('user')
        password = self.get_opt('password')
        if self.get_opt('ssl'):
            self.protocol = 'https'
        history_mins = self.get_opt('history_mins')
        num = self.get_opt('num')
        #inventory_id = self.get_opt('id')
        source = self.get_opt('source')
        dest = self.get_opt('dest')
        max_age = self.get_opt('max_age')
        max_runtime = self.get_opt('max_runtime')
        validate_host(host)
        validate_port(port)
        validate_user(user)
        validate_password(password)
        validate_float(history_mins, 'history mins')
        self.history_mins = float(history_mins)
        filter_opts = {}
        if self.history_mins:
            now = datetime.now()
            filter_opts['dateRangeStart'] = datetime.strftime(now - timedelta(minutes=self.history_mins), '%F %H:%M:%S')
            filter_opts['dateRangeEnd'] = datetime.strftime(now, '%F %H:%M:%S')
        if num is not None:
            validate_int(num, 'num ingestions', 1)
        #if inventory_id is not None:
        #    validate_chars(inventory_id, 'ingestion id', r'\w-')
        #    filter_opts['inventoryId'] = inventory_id
        if source is not None:
            log_option('source', source)
            filter_opts['fileName'] = source
        if dest is not None:
            log_option('dest', dest)
            filter_opts['destinationPath'] = dest
        if max_age is not None:
            validate_float(max_age, 'max age', 1)
            max_age = float(max_age)
        if max_runtime is not None:
            validate_float(max_runtime, 'max incomplete runtime', 1)
            max_runtime = float(max_runtime)

        self.url_base = '{protocol}://{host}:{port}/bedrock-app/services/rest'.format(host=host,
                                                                                      port=port,
                                                                                      protocol=self.protocol)
        # auth first, get JSESSIONID cookie
        # cookie jar doesn't work in Python or curl, must extract JSESSIONID to header manually
        #self.jar = cookielib.CookieJar()
        log.info('authenticating to Zaloni Bedrock')
        (_, self.auth_time) = self.req(url='{url_base}/admin/getUserRole'.format(url_base=self.url_base),
                                       # using json instead of constructing string manually,
                                       # this correctly escapes backslashes in password
                                       body=json.dumps({"username": user, "password": password}))
        if self.get_opt('list'):
            self.list_ingestions(num=num)

        self.check_ingestion(num=num, filter_opts=filter_opts, max_age=max_age, max_runtime=max_runtime)
 def process_options(self):
     super(CheckSeleniumHubNodes, self).process_options()
     if int(self.port) == 443:
         log_option('ssl inferred by port', True)
         self.protocol = 'https'
     self.browser = self.get_opt('browser')
     log_option('browser filter', self.browser)
     self.validate_thresholds(simple='lower')
 def process_options(self):
     super(CheckJenkinsPlugin, self).process_options()
     self.plugin = self.get_opt('plugin')
     self.list_plugins = self.get_opt('list')
     if not self.list_plugins:
         validate_chars(self.plugin, 'plugin', r'A-Za-z0-9\s\.,_-')
     self.check_update = self.get_opt('check_update')
     log_option('check for updates', self.check_update)
Exemple #24
0
def validate_hbase_table(arg, name=''):
    if name:
        name += ' '
    if not arg:
        raise InvalidOptionException('%(name)shbase table not defined' % locals())
    if isHBaseTable(arg):
        log_option('%(name)shbase table' % locals(), arg)
        return True
    raise InvalidOptionException("invalid %(name)shbase table '%(arg)s' defined" % locals())
Exemple #25
0
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
Exemple #26
0
def validate_hbase_rowkey(arg, name=''):
    if name:
        name += ' '
    if not arg:
        raise InvalidOptionException('%(name)shbase row key not defined' % locals())
    if isHBaseRowKey(arg):
        log_option('%(name)shbase row key' % locals(), arg)
        return True
    raise InvalidOptionException("invalid %(name)shbase row key '%(arg)s' defined" % locals())
Exemple #27
0
def validate_hbase_column_qualifier(arg, name=''):
    if name:
        name += ' '
    if not arg:
        raise InvalidOptionException('%(name)shbase column qualifier not defined' % locals())
    if isHBaseColumnQualifier(arg):
        log_option('%(name)shbase column' % locals(), arg)
        return True
    raise InvalidOptionException("invalid %(name)shbase column '%(arg)s' defined" % locals())
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
Exemple #29
0
 def _validate_filenames(self):
     for filename in self.file_list:
         if filename == '-':
             log_option('file', '<STDIN>')
         else:
             validate_file(filename)
     # use stdin
     if not self.file_list:
         self.file_list.add('-')
 def run(self):
     if not self.args:
         self.usage('no Dockerfile / directory args given')
     args = uniq_list_ordered(self.args)
     self.branch_prefix = self.get_opt('branch_prefix')
     if self.branch_prefix is not None:
         validate_regex(self.branch_prefix, 'branch prefix')
         self.branch_prefix = re.compile(self.branch_prefix)
     for arg in args:
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory"
                 % arg)
     for arg in args:
         self.check_git_branches_dockerfiles(arg)
     log.info('Total Branches: %s', len(self.branches))
     log.info('Selected Branches: %s', len(self.selected_branches))
     log.info('Branches checked: %s', self.branches_checked)
     log.info('Branches with Dockerfile checked: %s',
              len(self.branches_dockerfile_checked))
     branches_skipped = len(self.branches_skipped)
     if branches_skipped > 0:
         log.warn(
             '{0} branches skipped for not matching expected naming format'.
             format(branches_skipped))
     branches_not_checked = len(self.selected_branches) - len(
         self.branches_dockerfile_checked)
     if branches_not_checked > 1:
         log.warn(
             '{0} branches not checked (no matching Dockerfile found?)'.
             format(branches_not_checked))
         if log.isEnabledFor(logging.DEBUG):
             log.debug(
                 'Branches with no corresponding Dockerfile found:\n%s',
                 '\n'.join(
                     set(self.selected_branches) -
                     set(self.branches_dockerfile_checked)))
     log.info('{0} Dockerfiles checked'.format(len(
         self.dockerfiles_checked)))
     branches_failed = len(self.branches_failed)
     _ = '{0} Dockerfiles failed validation across {1} branches'.format(
         self.dockerfiles_failed, branches_failed)
     if branches_failed > 0:
         log.error(_)
     else:
         log.info(_)
     if self.failed:
         log.error('Dockerfile validation FAILED')
         sys.exit(ERRORS['CRITICAL'])
     log.info('Dockerfile validation SUCCEEDED')
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.validate_thresholds(simple='lower')
Exemple #32
0
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.validate_thresholds(simple='lower')
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if self.get_opt('ssl'):
         self.protocol = 'https'
     self.validate_thresholds(optional=True)
Exemple #34
0
def validate_hbase_rowkey(arg, name=''):
    if name:
        name += ' '
    if not arg:
        raise InvalidOptionException('%(name)shbase row key not defined' %
                                     locals())
    if isHBaseRowKey(arg):
        log_option('%(name)shbase row key' % locals(), arg)
        return True
    raise InvalidOptionException(
        "invalid %(name)shbase row key '%(arg)s' defined" % locals())
 def process_options(self):
     host = self.get_opt('host')
     port = self.get_opt('port')
     validate_host(host)
     validate_port(port)
     if self.get_opt('ssl'):
         log_option('ssl', 'True')
         self.protocol = 'https'
     self.url_base = '{protocol}://{host}:{port}/v2'.format(protocol=self.protocol,
                                                            host=host,
                                                            port=port)
Exemple #36
0
 def process_options(self):
     self.include = self.get_opt('include')
     self.exclude = self.get_opt('exclude')
     if self.include:
         validate_regex(self.include, 'include')
         self.include = re.compile(self.include, re.I)
     if self.exclude:
         validate_regex(self.exclude, 'exclude')
         self.exclude = re.compile(self.exclude, re.I)
     for key in self.opts:
         log_option(key, self.opts[key])
Exemple #37
0
def validate_hbase_column_qualifier(arg, name=''):
    if name:
        name += ' '
    if not arg:
        raise InvalidOptionException(
            '%(name)shbase column qualifier not defined' % locals())
    if isHBaseColumnQualifier(arg):
        log_option('%(name)shbase column' % locals(), arg)
        return True
    raise InvalidOptionException(
        "invalid %(name)shbase column '%(arg)s' defined" % locals())
Exemple #38
0
def validate_hbase_table(arg, name=''):
    if name:
        name += ' '
    if not arg:
        raise InvalidOptionException('%(name)shbase table not defined' %
                                     locals())
    if isHBaseTable(arg):
        log_option('%(name)shbase table' % locals(), arg)
        return True
    raise InvalidOptionException(
        "invalid %(name)shbase table '%(arg)s' defined" % locals())
Exemple #39
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if self.get_opt('ssl'):
         self.protocol = 'https'
     self.validate_thresholds(optional=True)
Exemple #40
0
 def process_args(self):
     #log.setLevel(logging.INFO)
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.table = self.get_opt('table')
     validate_host(self.host)
     validate_port(self.port)
     if not self.get_opt('list_tables'):
         validate_chars(self.table, 'hbase table', 'A-Za-z0-9:._-')
     self.short_region_name = self.get_opt('short_region_name')
     log_option('shorten region name', self.short_region_name)
 def process_options(self):
     super(CheckYarnResourceManagerMasterState, self).process_options()
     self.expect_active = self.get_opt('active')
     self.expect_standby = self.get_opt('standby')
     if self.expect_active:
         log_option('expect active', self.expect_active)
     if self.expect_standby:
         log_option('expect standby', self.expect_standby)
     if self.expect_active and self.expect_standby:
         self.usage('cannot specify --expect-active and --expect-standby at the same time' +
                    ', they are mutually exclusive! (omit them if you do not care whether ' +
                    'the master is in active or standby state)')
 def process_args(self):
     #log.setLevel(logging.INFO)
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.table = self.get_opt('table')
     validate_host(self.host)
     validate_port(self.port)
     if not self.get_opt('list_tables'):
         validate_chars(self.table, 'hbase table', 'A-Za-z0-9:._-')
     self.short_region_name = self.get_opt('short_region_name')
     log_option('shorten region name', self.short_region_name)
Exemple #43
0
 def process_options(self):
     super(CheckYarnResourceManagerMasterState, self).process_options()
     self.expect_active = self.get_opt('active')
     self.expect_standby = self.get_opt('standby')
     if self.expect_active:
         log_option('expect active', self.expect_active)
     if self.expect_standby:
         log_option('expect standby', self.expect_standby)
     if self.expect_active and self.expect_standby:
         self.usage('cannot specify --expect-active and --expect-standby at the same time' +
                    ', they are mutually exclusive! (omit them if you do not care whether ' +
                    'the master is in active or standby state)')
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.validate_thresholds(simple='lower', optional=True)
Exemple #45
0
 def run(self):
     self.num_lines = self.get_opt('num')
     log_option('number of lines', self.num_lines)
     self.quiet = self.get_opt('quiet')
     log_option('quiet', self.quiet)
     if not self.args:
         self.args.append('-')
     for arg in self.args:
         if arg == '-':
             continue
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory"
                 % arg)
     for filename in self.args:
         if filename == '-':
             self.headtail(sys.stdin.read())
         else:
             with open(filename) as _:
                 self.headtail(_.read())
         if not self.quiet and len(self.args) > 1:
             print(self.docsep)
Exemple #46
0
 def process_options(self):
     self.host = self.get_opt("host")
     self.port = self.get_opt("port")
     self.user = self.get_opt("user")
     self.password = self.get_opt("password")
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt("ssl")
     log_option("ssl", ssl)
     if ssl:
         self.protocol = "https"
     self.validate_thresholds(simple="lower", optional=True)
Exemple #47
0
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_user(self.user)
     validate_password(self.password)
     validate_port(self.port)
     use_ssl = self.get_opt('use_ssl')
     log_option('ssl', use_ssl)
     if use_ssl and self.protocol == 'http':
         self.protocol = 'https'
Exemple #48
0
 def run(self):
     self.num_lines = self.get_opt('num')
     log_option('number of lines', self.num_lines)
     self.quiet = self.get_opt('quiet')
     log_option('quiet', self.quiet)
     if not self.args:
         self.args.append('-')
     for arg in self.args:
         if arg == '-':
             continue
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory" % arg)
     for filename in self.args:
         if filename == '-':
             self.headtail(sys.stdin.read())
         else:
             with open(filename) as _:
                 self.headtail(_.read())
         if not self.quiet and len(self.args) > 1:
             print(self.docsep)
 def check_args(args):
     for arg in args:
         if not os.path.exists(arg):
             _ = "'%s' not found" % arg
             #if self.skip_errors:
             #    log.error(_)
             #    self.failed = True
             #else:
             die(_)
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory" % arg)
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.process_expected_version_option()
Exemple #51
0
 def validate_threshold(self, name, threshold=None, optional=False, **kwargs):
     if not isStr(name):
         raise CodingError('non-string name passed to validate_threshold()')
     if threshold is None:
         # log.debug("using threshold option '%s'", name)
         threshold = self.get_opt(name)
         # log.debug("got threshold '%s'", threshold)
     if optional and threshold is None:
         return None
     else:
         try:
             self.__thresholds[name] = Threshold(threshold, name=name, **kwargs)
         except InvalidThresholdException as _:
             self.usage(_)
     log_option(name, threshold)
 def process_options(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     ssl = self.get_opt('ssl')
     log_option('ssl', ssl)
     if ssl:
         self.protocol = 'https'
     self.metrics = self.get_opt('metrics')
     if not self.metrics and not self.get_opt('list_metrics'):
         self.usage("--metrics not specified, use --list-metrics to see what's available in Attivio's API")
     for key in self.filter_types:
         self.filters[key] = self.get_opt(key)
     self.precision = self.get_opt('precision')
     self.validate_thresholds(optional=True)
    def process_args(self):
        self.brokers = self.get_opt('brokers')
        # TODO: add broker list validation back in
        # validate_hostport(self.brokers)
        log_option('brokers', self.brokers)
        self.timeout_ms = max((self.timeout * 1000 - 1000) / 2, 1000)

        try:
            list_topics = self.get_opt('list_topics')
            list_partitions = self.get_opt('list_partitions')
            if list_topics:
                self.print_topics()
                sys.exit(ERRORS['UNKNOWN'])
            self.topic = self.get_opt('topic')
        except KafkaError:
            raise CriticalError(self.exception_msg())

        if self.topic:
            validate_chars(self.topic, 'topic', 'A-Za-z-')
        elif list_topics or list_partitions:
            pass
        else:
            self.usage('--topic not specified')

        try:
            if list_partitions:
                if self.topic:
                    self.print_topic_partitions(self.topic)
                else:
                    for topic in self.get_topics():
                        self.print_topic_partitions(topic)
                sys.exit(ERRORS['UNKNOWN'])
        except KafkaError:
            raise CriticalError(self.exception_msg())

        self.partition = self.get_opt('partition')
        # technically optional, will hash to a random partition, but need to know which partition to get offset
        # if self.partition is not None:
        validate_int(self.partition, "partition", 0, 10000)
        self.topic_partition = TopicPartition(self.topic, self.partition)
        self.acks = self.get_opt('acks')
        try:
            self.acks = int(self.acks)
        except ValueError:
            pass
        log_option('acks', self.acks)
        self.validate_thresholds()
 def process_args(self):
     self.files = self.args
     self.prefix_length = self.get_opt('key_prefix_length')
     self.skip_errors = self.get_opt('skip_errors')
     self.sort_desc = self.get_opt('desc')
     self.include_timestamps = self.get_opt('include_timestamps')
     if self.prefix_length is not None:
         validate_int(self.prefix_length, 'key key prefix length', 1, 100)
         self.prefix_length = int(self.prefix_length)
     if not self.files:
         self.usage('no file(s) specified as arguments')
     self.files = uniq_list_ordered(self.files)
     for filename in self.files:
         if filename == '-':
             log_option('file', '<stdin>')
             continue
         validate_file(filename)
Exemple #55
0
 def run(self):
     if not self.args:
         self.args.append('-')
     for arg in self.args:
         if arg == '-':
             continue
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory" % arg)
     for arg in self.args:
         self.process_path(arg)
 def run(self):
     if not self.args:
         self.usage('no Dockerfile / directory args given')
     args = uniq_list_ordered(self.args)
     self.branch_prefix = self.get_opt('branch_prefix')
     if self.branch_prefix is not None:
         validate_regex(self.branch_prefix, 'branch prefix')
         self.branch_prefix = re.compile(self.branch_prefix)
     for arg in args:
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS['WARNING'])
         if os.path.isfile(arg):
             log_option('file', arg)
         elif os.path.isdir(arg):
             log_option('directory', arg)
         else:
             die("path '%s' could not be determined as either a file or directory" % arg)
     for arg in args:
         self.check_git_branches_dockerfiles(arg)
     log.info('Total Branches: %s', len(self.branches))
     log.info('Selected Branches: %s', len(self.selected_branches))
     log.info('Branches checked: %s', self.branches_checked)
     log.info('Branches with Dockerfile checked: %s', len(self.branches_dockerfile_checked))
     branches_skipped = len(self.branches_skipped)
     if branches_skipped > 0:
         log.warn('{0} branches skipped for not matching expected naming format'
                  .format(branches_skipped))
     branches_not_checked = len(self.selected_branches) - len(self.branches_dockerfile_checked)
     if branches_not_checked > 1:
         log.warn('{0} branches not checked (no matching Dockerfile found?)'.format(branches_not_checked))
         if log.isEnabledFor(logging.DEBUG):
             log.debug('Branches with no corresponding Dockerfile found:\n%s',
                       '\n'.join(set(self.selected_branches) - set(self.branches_dockerfile_checked)))
     log.info('{0} Dockerfiles checked'.format(len(self.dockerfiles_checked)))
     branches_failed = len(self.branches_failed)
     _ = '{0} Dockerfiles failed validation across {1} branches'.format(self.dockerfiles_failed, branches_failed)
     if branches_failed > 0:
         log.error(_)
     else:
         log.info(_)
     if self.failed:
         log.error('Dockerfile validation FAILED')
         sys.exit(ERRORS['CRITICAL'])
     log.info('Dockerfile validation SUCCEEDED')
 def run(self):
     if not self.args:
         self.args.append("-")
     args = uniq_list_ordered(self.args)
     for arg in args:
         if arg == "-":
             continue
         if not os.path.exists(arg):
             print("'%s' not found" % arg)
             sys.exit(ERRORS["WARNING"])
         if os.path.isfile(arg):
             log_option("file", arg)
         elif os.path.isdir(arg):
             log_option("directory", arg)
         else:
             die("path '%s' could not be determined as either a file or directory" % arg)
     for arg in args:
         self.check_path(arg)
 def run(self):
     self.no_args()
     directory = self.get_opt('directory')
     directory = os.path.abspath(directory)
     expected_branch = self.get_opt('branch')
     validate_directory(directory)
     if expected_branch is None:
         self.usage('expected branch not defined')
     if not re.match(r'^[\w-]+$', expected_branch):
         self.usage('Invalid branch name given, must be alphanumeric')
     log_option('expected branch', expected_branch)
     repo = git.Repo(directory)
     current_branch = repo.active_branch.name
     if current_branch == expected_branch:
         qquit('OK', "branch '{0}' currently checked out in directory '{1}'"
               .format(current_branch, directory))
     else:
         qquit('CRITICAL', "branch '{0}' checked out, expecting '{1}' in directory '{2}'"
               .format(current_branch, expected_branch, directory))