示例#1
0
 def run(self):
     (version, cluster_version) = self.get_version()
     if not isVersion(version):
         qquit('UNKNOWN', '{0} version unrecognized \'{1}\'. {2}'\
                          .format(self.software, version, support_msg_api()))
     if not isVersion(cluster_version):
         qquit('UNKNOWN', '{0} cluster version unrecognized \'{1}\'. {2}'\
                          .format(self.software, cluster_version, support_msg_api()))
     self.msg = '{0} version = {1}'.format(self.software, version)
     if self.expected is not None and not re.search(self.expected, version):
         self.msg += " (expected '{0}')".format(self.expected)
         self.critical()
     #super(CheckEtcdVersion, self).run()
     self.msg += ', cluster version = {0}'.format(cluster_version)
 def run(self):
     expected = self.get_opt('expected')
     if expected is not None:
         validate_regex(expected)
         log.info('expected version regex: %s', expected)
     cmd = 'consul version'
     log.debug('cmd: ' + cmd)
     proc = subprocess.Popen(cmd.split(),
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
     (stdout, _) = proc.communicate()
     log.debug('stdout: ' + str(stdout))
     returncode = proc.wait()
     log.debug('returncode: ' + str(returncode))
     if returncode != 0 or (stdout is not None and 'Error' in stdout):
         raise CriticalError('consul returncode: {0}, output: {1}'.format(
             returncode, stdout))
     version = None
     for line in str(stdout).split('\n'):
         match = self.version_regex.match(line)
         if match:
             version = match.group(1)
     if not version:
         raise UnknownError(
             'Consul version not found in output. Consul output may have changed. {0}'
             .format(support_msg()))
     if not isVersion(version):
         raise UnknownError(
             'Consul version unrecognized \'{0}\'. {1}'.format(
                 version, support_msg()))
     self.ok()
     self.msg = 'Consul version = {0}'.format(version)
     if expected is not None and not re.search(expected, version):
         self.msg += " (expected '{0}')".format(expected)
         self.critical()
 def check_version(self, filename, branch, branch_base, arg_var, found_version, branch_version):
     self.branches_dockerfile_checked.add(branch)
     self.dockerfiles_checked.add(filename)
     if arg_var:
         log.debug("found arg '%s'", arg_var)
         arg_version = "ARG '{0}={1}'".format(arg_var, found_version)
     else:
         arg_version = "'{0}'".format(found_version)
     #log.debug("arg '%s' matches branch base '%s'", argversion.group(1), branch_base)
     log.debug("comparing '%s' contents to version derived from branch '%s' => '%s'",
               filename, branch, branch_version)
     if not isVersion(branch_version.lstrip('jdk').lstrip('jre')):
         die("unrecognized branch version '{0}' for branch_base '{1}'"
             .format(branch_version, branch_base))
     #if branch_version == found_version or branch_version == found_version.split('.', 2)[0]:
     if found_version[0:len(branch_version)] == branch_version:
         log.info("{0} version '{1}' matches {2}".
                  format(self.valid_git_branches_msg, branch_version, arg_version))
     else:
         log.error("{0} version '{1}' vs Dockerfile {2}".
                   format(self.invalid_git_branches_msg, branch_version, arg_version))
         self.dockerfiles_failed += 1
         self.branches_failed.add(branch)
         return False
     return True
 def check_dockerfile_arg(self, filename, tag):
     log.debug('check_dockerfile_arg({0}, {1})'.format(filename, tag))
     tag_base = str(tag).replace('-dev', '')
     (tag_base, tag_version) = tag_base.rsplit('-', 1)
     log.debug('tag_base = {0}'.format(tag_base))
     log.debug('tag_version = {0}'.format(tag_version))
     with open(filename) as filehandle:
         for line in filehandle:
             #log.debug(line.strip())
             argversion = self.arg_regex.match(line.strip())
             if argversion:
                 log.debug("found arg '%s'", argversion.group(0))
                 log.debug("checking arg group 1 '%s' == tag_base '%s'", argversion.group(1), tag_base)
                 if argversion.group(1).lower() == tag_base.lower().replace('-', '_'):
                     log.debug("arg '%s'  matches tag base '%s'", argversion.group(1), tag_base)
                     log.debug("comparing '%s' contents to version derived from tag '%s' => '%s'",
                               filename, tag, tag_version)
                     if not isVersion(tag_version):
                         die("unrecognized tag version '{0}' for tag_base '{1}'".format(tag_version, tag_base))
                     found_version = argversion.group(2)
                     #if tag_version == found_version or tag_version == found_version.split('.', 1)[0]:
                     if found_version[0:len(tag_version)] == tag_version:
                         log.info("{0} (tag version '{1}' matches arg version '{2}')".
                                  format(self.valid_git_tags_msg, tag_version, found_version))
                         return True
                     else:
                         log.error('{0} ({1} tag vs {2} Dockerfile ARG)'.
                                   format(self.invalid_git_tags_msg, tag_version, found_version))
                         return False
     return True
示例#5
0
 def check_version(self, filename, branch, branch_base, arg_var, found_version, branch_version):
     self.branches_dockerfile_checked.add(branch)
     self.dockerfiles_checked.add(filename)
     if arg_var:
         log.debug("found arg '%s'", arg_var)
         arg_version = "ARG '{0}={1}'".format(arg_var, found_version)
     else:
         arg_version = "'{0}'".format(found_version)
     #log.debug("arg '%s' matches branch base '%s'", argversion.group(1), branch_base)
     log.debug("comparing '%s' contents to version derived from branch '%s' => '%s'",
               filename, branch, branch_version)
     if not isVersion(branch_version.lstrip('jdk').lstrip('jre')):
         die("unrecognized branch version '{0}' for branch_base '{1}'"
             .format(branch_version, branch_base))
     #if branch_version == found_version or branch_version == found_version.split('.', 1)[0]:
     if found_version[0:len(branch_version)] == branch_version:
         log.info("{0} version '{1}' matches {2}".
                  format(self.valid_git_branches_msg, branch_version, arg_version))
     else:
         log.error("{0} version '{1}' vs Dockerfile {2}".
                   format(self.invalid_git_branches_msg, branch_version, arg_version))
         self.dockerfiles_failed += 1
         self.branches_failed.add(branch)
         return False
     return True
 def run(self):
     expected = self.get_opt('expected')
     if expected is not None:
         validate_regex(expected)
         log.info('expected version regex: %s', expected)
     cmd = 'nodetool version'
     log.debug('cmd: ' + cmd)
     proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     (stdout, _) = proc.communicate()
     log.debug('stdout: ' + str(stdout))
     returncode = proc.wait()
     log.debug('returncode: ' + str(returncode))
     if returncode != 0 or (stdout is not None and 'Error' in stdout):
         raise CriticalError('nodetool returncode: {0}, output: {1}'.format(returncode, stdout))
     version = None
     for line in str(stdout).split('\n'):
         match = self.version_regex.match(line)
         if match:
             version = match.group(1)
     if not version:
         raise UnknownError('Cassandra version not found in output. Nodetool output may have changed. {0}'.
                            format(support_msg()))
     if not isVersion(version):
         raise UnknownError('Cassandra version unrecognized \'{0}\'. {1}'.format(version, support_msg()))
     self.ok()
     self.msg = 'Cassandra version = {0}'.format(version)
     if expected is not None and not re.search(expected, version):
         self.msg += " (expected '{0}')".format(expected)
         self.critical()
示例#7
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        warn_on_recent_start = self.get_opt('warn_on_recent_start')
        validate_host(host)
        validate_port(port)

        log.info('querying Tachyon%(name)s' % self.__dict__)
        url = 'http://%(host)s:%(port)s/home' % locals()
        log.debug('GET %s' % url)
        try:
            req = requests.get(url)
        except requests.exceptions.RequestException as _:
            qquit('CRITICAL', _)
        log.debug("response: %s %s" % (req.status_code, req.reason))
        log.debug("content:\n{0}\n{1}\n{2}".format('=' * 80,
                                                   req.content.strip(),
                                                   '=' * 80))
        if req.status_code != 200:
            qquit('CRITICAL', "%s %s" % (req.status_code, req.reason))
        soup = BeautifulSoup(req.content, 'html.parser')
        try:
            uptime = soup.find('th', text=re.compile(
                'Uptime:?', re.I)).find_next_sibling().get_text()
            version = soup.find('th', text=re.compile(
                'Version:?', re.I)).find_next_sibling().get_text()
        except (AttributeError, TypeError):
            qquit(
                'UNKNOWN',
                'failed to find parse Tachyon%(name)s uptime/version info' %
                self.__dict__)
        if not uptime or not isStr(uptime) or not re.search(
                r'\d+\s+second', uptime):
            qquit(
                'UNKNOWN',
                'Tachyon{0} uptime format not recognized: {1}'.format(
                    self.name, uptime))
        if not isVersion(version):
            qquit(
                'UNKNOWN',
                'Tachyon{0} version format not recognized: {1}'.format(
                    self.name, version))
        self.msg = 'Tachyon{0} version: {1}, uptime: {2}'.format(
            self.name, version, uptime)  # pylint: disable=attribute-defined-outside-init
        self.ok()
        if warn_on_recent_start:
            match = re.match(
                r'^(\d+)\s+day[^\d\s]+\s+(\d+)\s+hour[^\d\s]+\s+(\d+)\s+minute',
                uptime, re.I)
            if match:
                days = int(match.group(1))
                hours = int(match.group(2))
                mins = int(match.group(3))
                if days == 0 and hours == 0 and mins < 30:
                    self.warning()
                    self.msg += ' (< 30 mins)'
            else:
                self.unknown()
                self.msg += " (couldn't determine if uptime < 30 mins)"
 def run(self):
     expected = self.get_opt("expected")
     if expected is not None:
         validate_regex(expected)
         log.info("expected version regex: %s", expected)
     cmd = "consul version"
     log.debug("cmd: " + cmd)
     proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     (stdout, _) = proc.communicate()
     log.debug("stdout: " + str(stdout))
     returncode = proc.wait()
     log.debug("returncode: " + str(returncode))
     if returncode != 0 or (stdout is not None and "Error" in stdout):
         raise CriticalError("consul returncode: {0}, output: {1}".format(returncode, stdout))
     version = None
     for line in str(stdout).split("\n"):
         match = self.version_regex.match(line)
         if match:
             version = match.group(1)
     if not version:
         raise UnknownError(
             "Consul version not found in output. Consul output may have changed. {0}".format(support_msg())
         )
     if not isVersion(version):
         raise UnknownError("Consul version unrecognized '{0}'. {1}".format(version, support_msg()))
     self.ok()
     self.msg = "Consul version = {0}".format(version)
     if expected is not None and not re.search(expected, version):
         self.msg += " (expected '{0}')".format(expected)
         self.critical()
 def get_version(self):
     content = self.get()
     try:
         json_list = json.loads(content)
         if log.isEnabledFor(logging.DEBUG):
             print(jsonpp(json_list))
             print('=' * 80)
         if not isList(json_list):
             raise ValueError(
                 "non-list returned by API (is type '{0}')".format(
                     type(json_list)))
         json_dict = json_list[0]
         if not isDict(json_dict):
             raise ValueError(
                 "non-dict found inside returned list (is type '{0}')".
                 format(type(json_dict)))
         company_name = json_dict['company_name']
         company_website = json_dict['company_website']
         regex = re.compile(r'Blue\s*Talon', re.I)
         if not regex.match(company_name) and \
            not regex.match(company_website):
             qquit('UNKNOWN', 'Blue Talon name was not found in either company_name or company_website fields' \
                            + ', are you definitely querying a Blue Talon server?')
         build_version = json_dict['build_version']
         update_date = json_dict['update_date']
         api_version = json_dict['api_version']
         if not isVersion(api_version):
             qquit('UNKNOWN', '{0} api version unrecognized \'{1}\'. {2}'\
                              .format(self.software, api_version, support_msg_api()))
         if api_version != self.api_version:
             qquit('UNKNOWN', "unexpected API version '{0}' returned (expected '{1}')"\
                              .format(api_version, self.api_version))
         if self.verbose:
             extra_info = ' revision {revision} build {build}, schema revision = {schema_revision}'\
                           .format(revision=json_dict['revision_no'],
                                   build=json_dict['build_no'],
                                   schema_revision=json_dict['schema_revision'])
             extra_info += ', api version = {api_version}, update date = {update_date}'\
                           .format(api_version=api_version, update_date=update_date)
         else:
             extra_info = ', update date = {update_date}'.format(
                 update_date=update_date)
     except (KeyError, ValueError) as _:
         qquit('UNKNOWN', 'error parsing output from {software}: {exception}: {error}. {support_msg}'\
                          .format(software=self.software,
                                  exception=type(_).__name__,
                                  error=_,
                                  support_msg=support_msg_api()))
     return (build_version, extra_info)
示例#10
0
 def check_version(self, version):
     log.info("checking version '%s'", version)
     if not version:
         qquit('UNKNOWN', '{0} version not found. {1}'.format(self.software, support_msg_api()))
     if not isVersion(version):
         qquit('UNKNOWN', '{0} version unrecognized \'{1}\'. {2}'\
                          .format(self.software, version, support_msg_api()))
     self.msg = '{0} version = {1}'.format(self.software, version)
     if self.expected is not None:
         log.info("verifying version against expected regex '%s'", self.expected)
         if re.match(self.expected, str(version)):
             log.info('version regex matches retrieved version')
         else:
             log.info('version regex does not match retrieved version')
             self.msg += " (expected '{0}')".format(self.expected)
             self.critical()
示例#11
0
 def check_version(self, version):
     log.info("checking version '%s'", version)
     if not version:
         qquit('UNKNOWN', '{0} version not found. {1}'.format(self.software, support_msg_api()))
     if not isVersion(version):
         qquit('UNKNOWN', '{0} version unrecognized \'{1}\'. {2}'\
                          .format(self.software, version, support_msg_api()))
     self.msg = '{0} version = {1}'.format(self.software, version)
     if self.expected is not None:
         log.info("verifying version against expected regex '%s'", self.expected)
         if re.match(self.expected, version):
             log.info('version regex matches retrieved version')
         else:
             log.info('version regex does not match retrieved version')
             self.msg += " (expected '{0}')".format(self.expected)
             self.critical()
    def run(self):
        self.no_args()
        host = self.get_opt("host")
        port = self.get_opt("port")
        warn_on_recent_start = self.get_opt("warn_on_recent_start")
        validate_host(host)
        validate_port(port)

        log.info("querying Tachyon%(name)s" % self.__dict__)
        url = "http://%(host)s:%(port)s/home" % locals()
        log.debug("GET %s" % url)
        try:
            req = requests.get(url)
        except requests.exceptions.RequestException as _:
            qquit("CRITICAL", _)
        log.debug("response: %s %s" % (req.status_code, req.reason))
        log.debug("content:\n{0}\n{1}\n{2}".format("=" * 80, req.content.strip(), "=" * 80))
        if req.status_code != 200:
            qquit("CRITICAL", "Non-200 response! %s %s" % (req.status_code, req.reason))
        soup = BeautifulSoup(req.content, "html.parser")
        try:
            uptime = soup.find("th", text=re.compile("Uptime:?", re.I)).find_next_sibling().get_text()
            version = soup.find("th", text=re.compile("Version:?", re.I)).find_next_sibling().get_text()
        except (AttributeError, TypeError):
            qquit("UNKNOWN", "failed to find parse Tachyon%(name)s uptime/version info" % self.__dict__)
        if not uptime or not isStr(uptime) or not re.search(r"\d+\s+second", uptime):
            qquit("UNKNOWN", "Tachyon{0} uptime format not recognized: {1}".format(self.name, uptime))
        if not isVersion(version):
            qquit("UNKNOWN", "Tachyon{0} version format not recognized: {1}".format(self.name, version))
        self.msg = "Tachyon{0} version: {1}, uptime: {2}".format(
            self.name, version, uptime
        )  # pylint: disable=attribute-defined-outside-init
        self.ok()
        if warn_on_recent_start:
            match = re.match(r"^(\d+)\s+day[^\d\s]+\s+(\d+)\s+hour[^\d\s]+\s+(\d+)\s+minute", uptime, re.I)
            if match:
                days = int(match.group(1))
                hours = int(match.group(2))
                mins = int(match.group(3))
                if days == 0 and hours == 0 and mins < 30:
                    self.warning()
                    self.msg += " (< 30 mins)"
            else:
                self.unknown()
                self.msg += " (couldn't determine if uptime < 30 mins)"
 def check(self, client):
     log.info('getting Docker Swarm version')
     swarm = client.swarm
     if not swarm.attrs:
         raise CriticalError('Docker server is not a Swarm node')
     version = swarm.version
     if not isVersion(version):
         raise UnknownError('Docker Swarm version unrecognized \'{}\'. {}'\
                            .format(version, support_msg_api()))
     self.msg = 'Docker Swarm version = {}'.format(version)
     if self.expected is not None:
         log.info("verifying version against expected regex '%s'", self.expected)
         if re.match(self.expected, str(version)):
             log.info('version regex matches retrieved version')
         else:
             log.info('version regex does not match retrieved version')
             self.msg += " (expected '{}')".format(self.expected)
             self.critical()
示例#14
0
 def check_dockerfile_arg(self, filename, branch):
     log.debug('check_dockerfile_arg({0}, {1})'.format(filename, branch))
     branch_base = str(branch).replace('-dev', '')
     (branch_base, branch_versions) = self.branch_version(branch)
     with open(filename) as filehandle:
         version_index = 0
         for line in filehandle:
             #log.debug(line.strip())
             argversion = self.arg_regex.match(line.strip())
             if argversion:
                 self.dockerfiles_checked.add(filename)
                 log.debug("found arg '%s'", argversion.group(0))
                 arg_var = argversion.group(1)
                 # this is too restrictive and prevents finding a lot of issues with
                 # more complex naming conventions for kafka, centos-java/scala etc
                 # instead we now expect ARG *_VERSION to be in the same order as the version numbers in branch name
                 #log.debug("checking arg group 1 '%s' == branch_base '%s'", argversion.group(1), branch_base)
                 #if self.normalize_name(arg_var) == self.normalize_name(branch_base).replace('-', '_'):
                 if version_index >= len(branch_versions):
                     return True
                 branch_version = branch_versions[version_index]
                 #log.debug("arg '%s' matches branch base '%s'", argversion.group(1), branch_base)
                 log.debug(
                     "comparing '%s' contents to version derived from branch '%s' => '%s'",
                     filename, branch, branch_version)
                 if not isVersion(branch_version):
                     die("unrecognized branch version '{0}' for branch_base '{1}'"
                         .format(branch_version, branch_base))
                 found_version = argversion.group(2)
                 #if branch_version == found_version or branch_version == found_version.split('.', 2)[0]:
                 if found_version[0:len(branch_version)] == branch_version:
                     log.info("{0} version '{1}' matches {2}={3}".format(
                         self.valid_git_branches_msg, branch_version,
                         arg_var, found_version))
                 else:
                     log.error(
                         '{0} version {1} vs Dockerfile ARG {2}={3}'.format(
                             self.invalid_git_branches_msg, branch_version,
                             arg_var, found_version))
                     self.dockerfiles_failed += 1
                     self.branches_failed.add(branch)
                     return False
                 version_index += 1
     return True
 def get_version(self):
     content = self.get()
     try:
         json_list = json.loads(content)
         if log.isEnabledFor(logging.DEBUG):
             print(jsonpp(json_list))
             print('='*80)
         if not isList(json_list):
             raise ValueError("non-list returned by API (is type '{0}')".format(type(json_list)))
         json_dict = json_list[0]
         if not isDict(json_dict):
             raise ValueError("non-dict found inside returned list (is type '{0}')".format(type(json_dict)))
         company_name = json_dict['company_name']
         company_website = json_dict['company_website']
         regex = re.compile(r'Blue\s*Talon', re.I)
         if not regex.match(company_name) and \
            not regex.match(company_website):
             qquit('UNKNOWN', 'Blue Talon name was not found in either company_name or company_website fields' \
                            + ', are you definitely querying a Blue Talon server?')
         build_version = json_dict['build_version']
         update_date = json_dict['update_date']
         api_version = json_dict['api_version']
         if not isVersion(api_version):
             qquit('UNKNOWN', '{0} api version unrecognized \'{1}\'. {2}'\
                              .format(self.software, api_version, support_msg_api()))
         if api_version != self.api_version:
             qquit('UNKNOWN', "unexpected API version '{0}' returned (expected '{1}')"\
                              .format(api_version, self.api_version))
         if self.verbose:
             extra_info = ' revision {revision} build {build}, schema revision = {schema_revision}'\
                           .format(revision=json_dict['revision_no'],
                                   build=json_dict['build_no'],
                                   schema_revision=json_dict['schema_revision'])
             extra_info += ', api version = {api_version}, update date = {update_date}'\
                           .format(api_version=api_version, update_date=update_date)
         else:
             extra_info = ', update date = {update_date}'.format(update_date=update_date)
     except (KeyError, ValueError) as _:
         qquit('UNKNOWN', 'error parsing output from {software}: {exception}: {error}. {support_msg}'\
                          .format(software=self.software,
                                  exception=type(_).__name__,
                                  error=_,
                                  support_msg=support_msg_api()))
     return (build_version, extra_info)
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)
        expected = self.get_opt('expected')
        if expected is not None:
            validate_regex(expected)
            log.info('expected version regex: %s', expected)

        log.info('querying %s', self.software)
        url = 'http://%(host)s:%(port)s/version' % locals()
        log.debug('GET %s' % url)
        try:
            req = requests.get(url)
        except requests.exceptions.RequestException as _:
            raise CriticalError(_)
        log.debug("response: %s %s", req.status_code, req.reason)
        log.debug("content:\n%s\n%s\n%s", '='*80, req.content.strip(), '='*80)
        # Special handling for Nginx, expecting 404 rather than usual 200
        if req.status_code != 404:
            raise CriticalError("%s %s (expecting 404)" % (req.status_code, req.reason))
        soup = BeautifulSoup(req.content, 'html.parser')
        if log.isEnabledFor(logging.DEBUG):
            log.debug("BeautifulSoup prettified:\n{0}\n{1}".format(soup.prettify(), '='*80))
        try:
            version = soup.findAll('center')[1].text
        except (AttributeError, TypeError) as _:
            raise UnknownError('failed to find parse {0} output. {1}\n{2}'.
                               format(self.software, support_msg_api(), traceback.format_exc()))
        if '/' in version:
            version = version.split('/')[1]
        if not version:
            raise UnknownError('{0} version not found in output. {1}'.format(self.software, support_msg_api()))
        if not isVersion(version):
            raise UnknownError('{0} version unrecognized \'{1}\'. {2}'.
                               format(self.software, version, support_msg_api()))
        self.ok()
        self.msg = '{0} version = {1}'.format(self.software, version)
        if expected is not None and not re.search(expected, version):
            self.msg += " (expected '{0}')".format(expected)
            self.critical()
示例#17
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        warn_on_recent_start = self.get_opt('warn_on_recent_start')
        validate_host(host)
        validate_port(port)

        log.info('querying %s%s', self.software, self.name)
        url = 'http://%(host)s:%(port)s/home' % locals()
        log.debug('GET %s', url)
        try:
            req = requests.get(url)
        except requests.exceptions.RequestException as _:
            qquit('CRITICAL', _)
        log.debug("response: %s %s", req.status_code, req.reason)
        log.debug("content:\n%s\n%s\n%s", '='*80, req.content.strip(), '='*80)
        if req.status_code != 200:
            qquit('CRITICAL', "%s %s" % (req.status_code, req.reason))
        soup = BeautifulSoup(req.content, 'html.parser')
        try:
            uptime = soup.find('th', text=re.compile('Uptime:?', re.I)).find_next_sibling().get_text()
            version = soup.find('th', text=re.compile('Version:?', re.I)).find_next_sibling().get_text()
        except (AttributeError, TypeError):
            qquit('UNKNOWN', 'failed to find parse %(software)s%(name)s uptime/version info' % self.__dict__)
        if not uptime or not isStr(uptime) or not re.search(r'\d+\s+second', uptime):
            qquit('UNKNOWN', '{0}{1} uptime format not recognized: {2}'.format(self.software, self.name, uptime))
        if not isVersion(version):
            qquit('UNKNOWN', '{0}{1} version format not recognized: {2}'.format(self.software, self.name, version))
        self.msg = '{0}{1} version: {2}, uptime: {3}'.format(self.software, self.name, version, uptime)  # pylint: disable=attribute-defined-outside-init
        self.ok()
        if warn_on_recent_start:
            match = re.match(r'^(\d+)\s+day[^\d\s]+\s+(\d+)\s+hour[^\d\s]+\s+(\d+)\s+minute', uptime, re.I)
            if match:
                days = int(match.group(1))
                hours = int(match.group(2))
                mins = int(match.group(3))
                if days == 0 and hours == 0 and mins < 30:
                    self.warning()
                    self.msg += ' (< 30 mins)'
            else:
                self.unknown()
                self.msg += " (couldn't determine if uptime < 30 mins)"
示例#18
0
 def check(self, client):
     log.info('getting Docker Swarm version')
     swarm = client.swarm
     if not swarm.attrs:
         raise CriticalError('Docker server is not a Swarm node')
     version = swarm.version
     if not isVersion(version):
         raise UnknownError('Docker Swarm version unrecognized \'{}\'. {}'\
                            .format(version, support_msg_api()))
     self.msg = 'Docker Swarm version = {}'.format(version)
     if self.expected is not None:
         log.info("verifying version against expected regex '%s'",
                  self.expected)
         if re.match(self.expected, str(version)):
             log.info('version regex matches retrieved version')
         else:
             log.info('version regex does not match retrieved version')
             self.msg += " (expected '{}')".format(self.expected)
             self.critical()
示例#19
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)
        expected = self.get_opt('expected')
        if expected is not None:
            validate_regex(expected)
            log.info('expected version regex: %s', expected)

        url = 'http://%(host)s:%(port)s/solr/admin/info/system' % locals()
        log.debug('GET %s' % url)
        try:
            req = requests.get(url)
        except requests.exceptions.RequestException as _:
            raise CriticalError(_)
        log.debug("response: %s %s", req.status_code, req.reason)
        log.debug("content:\n%s\n%s\n%s", '=' * 80, req.content.strip(),
                  '=' * 80)
        if req.status_code != 200:
            raise CriticalError("%s %s" % (req.status_code, req.reason))
        soup = BeautifulSoup(req.content, 'html.parser')
        if log.isEnabledFor(logging.DEBUG):
            log.debug("BeautifulSoup prettified:\n{0}\n{1}".format(
                soup.prettify(), '=' * 80))
        try:
            version = soup.find('str', {'name': 'solr-spec-version'}).text
        except (AttributeError, TypeError) as _:
            raise UnknownError(
                'failed to find parse Solr output. {0}\n{1}'.format(
                    support_msg_api(), traceback.format_exc()))
        if not version:
            raise UnknownError('Solr version not found in output. {0}'.format(
                support_msg_api()))
        if not isVersion(version):
            raise UnknownError('Solr version unrecognized \'{0}\'. {1}'.format(
                version, support_msg_api()))
        self.ok()
        self.msg = 'Solr version = {0}'.format(version)
        if expected is not None and not re.search(expected, version):
            self.msg += " (expected '{0}')".format(expected)
            self.critical()
示例#20
0
 def parse_version(self, soup):
     version = None
     try:
         attributes_table = soup.find('table', {'id': 'attributes_table'})
         rows = attributes_table.findAll('tr')
         num_rows = len(rows)
         self.sanity_check(num_rows > 5,
                           'too few rows ({0})'.format(num_rows))
         headers = rows[0].findAll('th')
         num_headers = len(headers)
         self.sanity_check(
             num_headers > 2,
             'too few header columns ({0})'.format(num_headers))
         self.sanity_check(
             headers[0].text.strip() == 'Attribute Name',
             'header first column does not match expected \'Attribute Name\''
         )
         self.sanity_check(
             headers[1].text.strip() == 'Value',
             'header second column does not match expected \'Value\'')
         for row in rows:
             cols = row.findAll('td')
             num_cols = len(cols)
             if num_cols == 0:
                 continue
             self.sanity_check(num_cols > 2,
                               'too few columns ({0})'.format(num_cols))
             if cols[0].text.strip() == 'HBase Version':
                 version = cols[1].text.split(',')[0]
                 break
     except (AttributeError, TypeError):
         raise UnknownError(
             'failed to find parse HBase output. {0}\n{1}'.format(
                 support_msg(), traceback.format_exc()))
     if not version:
         raise UnknownError('HBase version not found in output. {0}'.format(
             support_msg()))
     if not isVersion(version):
         raise UnknownError(
             'HBase version unrecognized \'{0}\'. {1}'.format(
                 version, support_msg()))
     return version
 def run(self):
     self.no_args()
     host = self.get_opt('host')
     port = self.get_opt('port')
     validate_host(host)
     validate_port(port)
     expected = self.get_opt('expected')
     if expected is not None:
         validate_regex(expected)
         log.info('expected version regex: %s', expected)
     data = None
     try:
         #conn = socket.create_connection('%(host)s:%(port)s' % locals(), timeout=self.timeout/2)
         #conn = socket.create_connection('%s:%s' % (host, port), timeout=self.timeout/2)
         conn = socket.create_connection((host, port),
                                         timeout=self.timeout / 2)
         conn.sendall('envi')
         data = conn.recv(1024)
         conn.close()
     except socket.error as _:
         raise CriticalError('Failed to connect to ZooKeeper: ' + str(_))
     version = None
     log.debug(data.strip())
     for line in data.split('\n'):
         _ = self.version_line_regex.match(line)
         if _:
             version = _.group(1)
             break
     if not version:
         raise UnknownError(
             'ZooKeeper version not found in output. {0}'.format(
                 support_msg_api()))
     if not isVersion(version):
         raise UnknownError(
             'ZooKeeper version unrecognized \'{0}\'. {1}'.format(
                 version, support_msg_api()))
     self.ok()
     self.msg = 'ZooKeeper version = {0}'.format(version)
     if expected is not None and not re.match(expected, version):
         self.msg += " (expected '{0}')".format(expected)
         self.critical()
 def check_dockerfile_arg(self, filename, tag):
     log.debug("check_dockerfile_arg({0}, {1})".format(filename, tag))
     tag_base = str(tag).replace("-dev", "")
     (tag_base, tag_version) = tag_base.rsplit("-", 1)
     log.debug("tag_base = {0}".format(tag_base))
     log.debug("tag_version = {0}".format(tag_version))
     with open(filename) as filehandle:
         for line in filehandle:
             # log.debug(line.strip())
             argversion = self.arg_regex.match(line.strip())
             if argversion:
                 log.debug("found arg '%s'", argversion.group(0))
                 log.debug("checking arg group 1 '%s' == tag_base '%s'", argversion.group(1), tag_base)
                 if argversion.group(1).lower() == tag_base.lower().replace("-", "_"):
                     log.debug("arg '%s'  matches tag base '%s'", argversion.group(1), tag_base)
                     log.debug(
                         "comparing '%s' contents to version derived from tag '%s' => '%s'",
                         filename,
                         tag,
                         tag_version,
                     )
                     if not isVersion(tag_version):
                         die("unrecognized tag version '{0}' for tag_base '{1}'".format(tag_version, tag_base))
                     found_version = argversion.group(2)
                     # if tag_version == found_version or tag_version == found_version.split('.', 2)[0]:
                     if found_version[0 : len(tag_version)] == tag_version:
                         log.info(
                             "{0} (tag version '{1}' matches arg version '{2}')".format(
                                 self.valid_git_tags_msg, tag_version, found_version
                             )
                         )
                         return True
                     else:
                         log.error(
                             "{0} ({1} tag vs {2} Dockerfile ARG)".format(
                                 self.invalid_git_tags_msg, tag_version, found_version
                             )
                         )
                         return False
     return True
 def check_dockerfile_arg(self, filename, branch):
     log.debug('check_dockerfile_arg({0}, {1})'.format(filename, branch))
     branch_base = str(branch).replace('-dev', '')
     (branch_base, branch_versions) = self.branch_version(branch)
     with open(filename) as filehandle:
         version_index = 0
         for line in filehandle:
             #log.debug(line.strip())
             argversion = self.arg_regex.match(line.strip())
             if argversion:
                 self.dockerfiles_checked.add(filename)
                 log.debug("found arg '%s'", argversion.group(0))
                 arg_var = argversion.group(1)
                 # this is too restrictive and prevents finding a lot of issues with
                 # more complex naming conventions for kafka, centos-java/scala etc
                 # instead we now expect ARG *_VERSION to be in the same order as the version numbers in branch name
                 #log.debug("checking arg group 1 '%s' == branch_base '%s'", argversion.group(1), branch_base)
                 #if self.normalize_name(arg_var) == self.normalize_name(branch_base).replace('-', '_'):
                 if version_index >= len(branch_versions):
                     return True
                 branch_version = branch_versions[version_index]
                 #log.debug("arg '%s' matches branch base '%s'", argversion.group(1), branch_base)
                 log.debug("comparing '%s' contents to version derived from branch '%s' => '%s'",
                           filename, branch, branch_version)
                 if not isVersion(branch_version):
                     die("unrecognized branch version '{0}' for branch_base '{1}'"
                         .format(branch_version, branch_base))
                 found_version = argversion.group(2)
                 #if branch_version == found_version or branch_version == found_version.split('.', 2)[0]:
                 if found_version[0:len(branch_version)] == branch_version:
                     log.info("{0} version '{1}' matches {2}={3}".
                              format(self.valid_git_branches_msg, branch_version, arg_var, found_version))
                 else:
                     log.error('{0} version {1} vs Dockerfile ARG {2}={3}'.
                               format(self.invalid_git_branches_msg, branch_version, arg_var, found_version))
                     self.dockerfiles_failed += 1
                     self.branches_failed.add(branch)
                     return False
                 version_index += 1
     return True
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)
        expected = self.get_opt('expected')
        if expected is not None:
            validate_regex(expected)
            log.info('expected version regex: %s', expected)

        url = 'http://%(host)s:%(port)s/solr/admin/info/system' % locals()
        log.debug('GET %s' % url)
        try:
            req = requests.get(url)
        except requests.exceptions.RequestException as _:
            raise CriticalError(_)
        log.debug("response: %s %s", req.status_code, req.reason)
        log.debug("content:\n%s\n%s\n%s", '='*80, req.content.strip(), '='*80)
        if req.status_code != 200:
            raise CriticalError("%s %s" % (req.status_code, req.reason))
        soup = BeautifulSoup(req.content, 'html.parser')
        if log.isEnabledFor(logging.DEBUG):
            log.debug("BeautifulSoup prettified:\n{0}\n{1}".format(soup.prettify(), '='*80))
        try:
            version = soup.find('str', {'name':'solr-spec-version'}).text
        except (AttributeError, TypeError) as _:
            raise UnknownError('failed to find parse Solr output. {0}\n{1}'.
                               format(support_msg_api(), traceback.format_exc()))
        if not version:
            raise UnknownError('Solr version not found in output. {0}'.format(support_msg_api()))
        if not isVersion(version):
            raise UnknownError('Solr version unrecognized \'{0}\'. {1}'.format(version, support_msg_api()))
        self.ok()
        self.msg = 'Solr version = {0}'.format(version)
        if expected is not None and not re.search(expected, version):
            self.msg += " (expected '{0}')".format(expected)
            self.critical()
 def run(self):
     self.no_args()
     host = self.get_opt('host')
     port = self.get_opt('port')
     validate_host(host)
     validate_port(port)
     expected = self.get_opt('expected')
     if expected is not None:
         validate_regex(expected)
         log.info('expected version regex: %s', expected)
     data = None
     try:
         #conn = socket.create_connection('%(host)s:%(port)s' % locals(), timeout=self.timeout/2)
         #conn = socket.create_connection('%s:%s' % (host, port), timeout=self.timeout/2)
         conn = socket.create_connection((host, port), timeout=self.timeout/2)
         conn.sendall('envi')
         data = conn.recv(1024)
         conn.close()
     except socket.error as _:
         raise CriticalError('Failed to connect to ZooKeeper: ' + str(_))
     version = None
     log.debug(data.strip())
     for line in data.split('\n'):
         _ = self.version_line_regex.match(line)
         if _:
             version = _.group(1)
             break
     if not version:
         raise UnknownError('ZooKeeper version not found in output. {0}'.format(support_msg_api()))
     if not isVersion(version):
         raise UnknownError('ZooKeeper version unrecognized \'{0}\'. {1}'.format(version, support_msg_api()))
     self.ok()
     self.msg = 'ZooKeeper version = {0}'.format(version)
     if expected is not None and not re.match(expected, version):
         self.msg += " (expected '{0}')".format(expected)
         self.critical()