コード例 #1
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/' % locals() + self.url_path
        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))
        self.ok()
        version = self.parse_version(soup)
        self.msg = 'HBase {0} version = {1}'.format(self.role, version)
        if expected is not None and not re.search(expected, version):
            self.msg += " (expected '{0}')".format(expected)
            self.critical()
コード例 #2
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        table = self.get_opt('table')
        validate_host(host)
        validate_port(port)
        validate_database_tablename(table)

        # raises 500 error if table doesn't exist
        url = 'http://%(host)s:%(port)s/table.jsp?name=%(table)s' % 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:
            info = ''
            #if req.status_code == '500' and 'TableNotFoundException' in req.content:
            if 'TableNotFoundException' in req.content:
                info = 'table not found'
            raise CriticalError("%s %s %s" % (req.status_code, req.reason, info))
        is_table_compacting = self.parse_is_table_compacting(req.content)
        self.msg = 'HBase table \'{0}\' '.format(table)
        if is_table_compacting:
            self.warning()
            self.msg += 'has compaction in progress'
        else:
            self.msg += 'has no compaction in progress'
コード例 #3
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'
コード例 #4
0
    def run(self):
        self.no_args()
        host = self.options.host
        port = self.options.port
        validate_host(host)
        validate_port(port)

        url = 'http://%(host)s:%(port)s/oozie/v1/admin/status' % 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: '%s'" % req.content)
        if req.status_code != 200:
            qquit('CRITICAL', "Non-200 response! %s %s" % (req.status_code, req.reason))
        # should == NORMAL
        if not isJson(req.content):
            qquit('UNKNOWN', 'non-JSON returned by Oozie server at {0}:{1}'.format(host, port))
        status = None
        try:
            _ = json.loads(req.content)
            status = _['systemMode']
        except KeyError:
            qquit('UNKNOWN', 'systemMode key was not returned in output from Oozie. {0}'.format(support_msg_api()))
        self.msg = 'Oozie status = {0}'.format(status)
        if status == 'NORMAL':
            self.ok()
        else:
            self.critical()
コード例 #5
0
 def process_options(self):
     super(CheckSeleniumHubBrowser, self).process_options()
     self.hub_url = self.get_opt('hub_url')
     if self.hub_url:
         validate_url(self.hub_url, 'hub')
     else:
         self.host = self.get_opt('host')
         self.port = self.get_opt('port')
         validate_host(self.host)
         validate_port(self.port)
         if self.get_opt('ssl') or int(self.port) == 443:
             self.protocol = 'https'
         self.hub_url = '{protocol}://{host}:{port}/{path}'\
                        .format(protocol=self.protocol, \
                                host=self.host, \
                                port=self.port, \
                                path=self.path)
     self.url = self.get_opt('url')
     if ':' not in self.url:
         self.url = 'http://' + self.url
     validate_url(self.url)
     self.browser = self.get_opt('browser')
     if self.browser:
         self.browser = self.browser.upper()
     validate_alnum(self.browser, 'browser')
     self.expected_content = self.get_opt('content')
     self.expected_regex = self.get_opt('regex')
     if self.expected_regex:
         validate_regex(self.expected_regex)
         self.expected_regex = re.compile(self.expected_regex)
     elif self.url == self.url_default:
         self.expected_content = self.expected_content_default
コード例 #6
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        url = 'http://%(host)s:%(port)s/jmx' % 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))
        compaction_queue_size = self.parse(req.content)
        self.msg = 'HBase RegionServer compaction '
        if compaction_queue_size > 0:
            self.warning()
            self.msg += 'in progress'
        else:
            self.msg += 'not in progress'
        self.msg += ', compactionQueueSize = {0}'.format(compaction_queue_size)
        self.msg += ' | compactionQueueSize={0};0;0'.format(compaction_queue_size)
コード例 #7
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)

        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))
コード例 #8
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        table = self.get_opt('table')
        validate_host(host)
        validate_port(port)
        validate_database_tablename(table)

        # raises 500 error if table doesn't exist
        url = 'http://%(host)s:%(port)s/table.jsp?name=%(table)s' % 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:
            info = ''
            #if req.status_code == '500' and 'TableNotFoundException' in req.content:
            if 'TableNotFoundException' in req.content:
                info = 'table not found'
            qquit('CRITICAL', "%s %s %s" % (req.status_code, req.reason, info))
        is_table_compacting = self.parse_is_table_compacting(req.content)
        self.msg = 'HBase table \'{0}\' '.format(table)
        if is_table_compacting:
            self.warning()
            self.msg += 'has compaction in progress'
        else:
            self.msg += 'has no compaction in progress'
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        # observed bug in HDP 2.3 (HBase 1.1.2) where the JMX metric from HMaster UI /jmx is displaying 0 for beans
        # [ {"name":"Hadoop:service=HBase,name=Master,sub=AssignmentManger", ..., "ritCountOverThreshold" : 0 }
        # https://issues.apache.org/jira/browse/HBASE-16636
        #url = 'http://%(host)s:%(port)s/jmx' % locals()
        # could get info from flat txt debug page but it doesn't contain the summary count
        #url = 'http://%(host)s:%(port)s/dump' % locals()
        url = 'http://%(host)s:%(port)s/master-status' % 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))
        regions_stuck_in_transition = self.parse(req.content)
        if regions_stuck_in_transition is None:
            qquit('UNKNOWN', 'parse error - failed to find number for regions stuck in transition')
        if not isInt(regions_stuck_in_transition):
            qquit('UNKNOWN', 'parse error - got non-integer for regions stuck in transition when parsing HMaster UI')
        if regions_stuck_in_transition == 0:
            self.ok()
        else:
            self.critical()
        self.msg = '{0} regions stuck in transition (ie. transitioning longer than HBase threshold)'\
                   .format(regions_stuck_in_transition)
        self.msg += " | regions_stuck_in_transition={0};0;0".format(regions_stuck_in_transition)
コード例 #10
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)
     self.process_expected_version_option()
コード例 #11
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        url = 'http://%(host)s:%(port)s/jmx' % 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))
        compaction_queue_size = self.parse(req.content)
        self.msg = 'HBase RegionServer compaction '
        if compaction_queue_size > 0:
            self.warning()
            self.msg += 'in progress'
        else:
            self.msg += 'not in progress'
        self.msg += ', compactionQueueSize = {0}'.format(compaction_queue_size)
        self.msg += ' | compactionQueueSize={0};0;0'.format(
            compaction_queue_size)
コード例 #12
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        url = 'http://%(host)s:%(port)s/status' % 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')
        #if log.isEnabledFor(logging.DEBUG):
        #     log.debug("BeautifulSoup prettified:\n{0}\n{1}".format(soup.prettify(), '='*80))
        try:
            status = soup.find('div', { 'class': 'alert alert-success'}).get_text().strip()
        except (AttributeError, TypeError):
            qquit('UNKNOWN', 'failed to parse Apache Drill status page. %s' % support_msg())
        self.msg = "Apache Drill status = '{0}'".format(status)
        if re.match('Running!', status):
            self.ok()
        else:
            self.critical()
コード例 #13
0
    def process_args(self):
        self.host_list = self.args
        if not self.host_list:
            self.usage(
                'no host arguments given, must give at least one regionserver host as an argument'
            )
        for host in self.host_list:
            validate_host(host)
        self.port = self.get_opt('port')
        validate_port(self.port)

        self.table = self.get_opt('table')
        table_chars = 'A-Za-z0-9:._-'
        if self.table:
            validate_chars(self.table, 'table', table_chars)
        else:
            self.table = '[{}]+'.format(table_chars)
        self.namespace = self.get_opt('namespace')
        validate_chars(self.namespace, 'hbase namespace', 'A-Za-z0-9:._-')
        self.top_n = self.get_opt('top')
        if self.top_n:
            validate_int(self.top_n, 'top N', 1)
            self.top_n = int(self.top_n)
        self.request_threshold = self.get_opt('requests')
        validate_int(self.request_threshold, 'request count threshold')
        self.request_threshold = int(self.request_threshold)
コード例 #14
0
    def process_args(self):
        self.host_list = self.args
        if not self.host_list:
            self.usage(
                'no host arguments given, must give at least one regionserver host as an argument'
            )
        for host in self.host_list:
            validate_host(host)
        self.port = self.get_opt('port')
        validate_port(self.port)

        self.interval = self.get_opt('interval')
        self.count = self.get_opt('count')
        self.since_uptime = self.get_opt('average')
        validate_int(self.interval, 'interval')
        validate_int(self.count, 'count')
        self.interval = int(self.interval)
        self.count = int(self.count)
        if self.count == 0:
            self.disable_timeout()
        self.request_type = self.get_opt('type')
        if self.request_type:
            self.request_type = [
                _.strip() for _ in self.request_type.split(',')
            ]
            for _ in self.request_type:
                if _ not in self.request_types:
                    self.usage('--type may only include: {}'.format(', '.join(
                        self.request_types)))
コード例 #15
0
ファイル: check_tachyon.py プロジェクト: wanix/nagios-plugins
    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)"
コード例 #16
0
    def process_args(self):
        self.host_list = self.args
        if not self.host_list:
            self.usage(
                'no host arguments given, must give at least one regionserver host as an argument'
            )
        for host in self.host_list:
            validate_host(host)
        self.port = self.get_opt('port')
        validate_port(self.port)

        self.table = self.get_opt('table')
        table_chars = 'A-Za-z0-9:._-'
        if self.table:
            validate_chars(self.table, 'table', table_chars)
        else:
            self.table = '[{}]+'.format(table_chars)
        self.namespace = self.get_opt('namespace')
        validate_chars(self.namespace, 'hbase namespace', 'A-Za-z0-9:._-')
        self.region_regex = re.compile('^Namespace_{namespace}_table_({table})_region_(.+)_metric_{metric}'\
                                       .format(namespace=self.namespace, table=self.table, metric=self.metric))
        self.top_n = self.get_opt('top')
        if self.top_n:
            validate_int(self.top_n, 'top N', 1)
            self.top_n = int(self.top_n)
コード例 #17
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        log.info('querying Tachyon Master')
        url = 'http://%(host)s:%(port)s/workers' % 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')
        dead_workers = 0
        try:
            dead_workers = len([_ for _ in soup.find(id='data2').find('tbody').find_all('tr') if _])
        except (AttributeError, TypeError):
            qquit('UNKNOWN', 'failed to find parse Tachyon Master info for dead workers' % self.__dict__)
        try:
            dead_workers = int(dead_workers)
        except (ValueError, TypeError):
            qquit('UNKNOWN', 'Tachyon Master dead workers parsing returned non-integer: {0}'.format(dead_workers))
        self.msg = 'Tachyon dead workers = {0}'.format(dead_workers)  # pylint: disable=attribute-defined-outside-init
        self.ok()
        # TODO: thresholds on number of dead workers (coming soon)
        if dead_workers:
            self.critical()
コード例 #18
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))
コード例 #19
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        url = 'http://%(host)s:%(port)s/oozie/v1/admin/status' % 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: '%s'" % req.content)
        if req.status_code != 200:
            qquit('CRITICAL', "%s %s" % (req.status_code, req.reason))
        # should == NORMAL
        if not isJson(req.content):
            qquit('UNKNOWN', 'non-JSON returned by Oozie server at {0}:{1}'.format(host, port))
        status = None
        try:
            _ = json.loads(req.content)
            status = _['systemMode']
        except KeyError:
            qquit('UNKNOWN', 'systemMode key was not returned in output from Oozie. {0}'.format(support_msg_api()))
        self.msg = 'Oozie status = {0}'.format(status)
        if status == 'NORMAL':
            self.ok()
        else:
            self.critical()
コード例 #20
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)
        self.validate_thresholds(integer=False)

        url = 'http://%(host)s:%(port)s/master-status' % 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)))
        self.parse_output(req.content)
        log.info('server with min regions = %s regions on %s',
                 self.server_min_regions[1], self.server_min_regions[0])
        log.info('server with max regions = %s regions on %s',
                 self.server_max_regions[1], self.server_max_regions[0])
        imbalance = self.calculate_imbalance()
        self.msg = '{0}% region imbalance'.format(imbalance)
        self.check_thresholds(imbalance)
        self.msg += ' between HBase RegionServers hosting the most vs least number of regions'
        self.msg += ' (min = {0}, max = {1})'.format(
            self.server_min_regions[1], self.server_max_regions[1])
        self.msg += " | '% region imbalance'={0}%".format(imbalance)
        self.msg += self.get_perf_thresholds()
        self.msg += ' min_regions={0} max_regions={1}'.format(
            self.server_min_regions[1], self.server_max_regions[1])
コード例 #21
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        # observed bug in HDP 2.3 (HBase 1.1.2) where the JMX metric from HMaster UI /jmx is displaying 0 for beans
        # [ {"name":"Hadoop:service=HBase,name=Master,sub=AssignmentManger", ..., "ritCountOverThreshold" : 0 }
        # https://issues.apache.org/jira/browse/HBASE-16636
        #url = 'http://%(host)s:%(port)s/jmx' % locals()
        # could get info from flat txt debug page but it doesn't contain the summary count
        #url = 'http://%(host)s:%(port)s/dump' % locals()
        url = 'http://%(host)s:%(port)s/master-status' % 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))
        regions_stuck_in_transition = self.parse(req.content)
        if regions_stuck_in_transition is None:
            qquit('UNKNOWN', 'parse error - failed to find number for regions stuck in transition')
        if not isInt(regions_stuck_in_transition):
            qquit('UNKNOWN', 'parse error - got non-integer for regions stuck in transition when parsing HMaster UI')
        if regions_stuck_in_transition == 0:
            self.ok()
        else:
            self.critical()
        self.msg = '{0} regions stuck in transition (ie. transitioning longer than HBase threshold)'\
                   .format(regions_stuck_in_transition)
        self.msg += " | regions_stuck_in_transition={0};0;0".format(regions_stuck_in_transition)
コード例 #22
0
 def process_args(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     # pika library requires int type
     self.port = self.port
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     self.port = int(self.port)
     validate_user(self.user)
     validate_password(self.password)
     self.vhost = self.get_opt('vhost')
     self.vhost = self.vhost if self.vhost else '/'
     validate_chars(self.vhost, 'vhost', r'/\w\._-')
     self.exchange = self.get_opt('exchange')
     if self.exchange:
         validate_chars(self.exchange, 'exchange', r'\w\._-')
     else:
         log_option('exchange', self.exchange)
     self.exchange_type = self.get_opt('exchange_type')
     if self.exchange_type:
         if self.exchange_type not in self.valid_exchange_types:
             self.usage('invalid --exchange-type given, expected one of: {valid_exchange_types}'\
                        .format(valid_exchange_types=', '.join(self.valid_exchange_types)))
     log_option('exchange type', self.exchange_type)
     self.queue = self.get_opt('queue')
     if self.queue:
         validate_chars(self.queue, 'queue', r'\w\._-')
     else:
         log_option('queue', self.queue)
     self.routing_key = self.get_opt('routing_key')
     if not self.routing_key:
         self.routing_key = self.queue
     log_option('routing key', self.routing_key)
     #self.no_ack = self.get_opt('no_ack')
     log_option('no ack', self.no_ack)
     self.connection_attempts = self.get_opt('connection_attempts')
     validate_int(self.connection_attempts,
                  'connection attempts',
                  min_value=1,
                  max_value=10)
     self.connection_attempts = int(self.connection_attempts)
     self.retry_delay = self.get_opt('retry_delay')
     validate_int(self.retry_delay,
                  'retry delay',
                  min_value=0,
                  max_value=10)
     self.retry_delay = int(self.retry_delay)
     self.use_transactions = self.get_opt('use_transactions')
     #self.durable = not self.get_opt('non_durable')
     if self.get_opt('non_durable'):
         self.durable = False
     log_option('non-durable', not self.durable)
     sleep_secs = self.get_opt('sleep')
     if sleep_secs:
         # validation done through property wrapper
         self.sleep_secs = sleep_secs
     log_option('sleep secs', self.sleep_secs)
     self.validate_thresholds()
コード例 #23
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        log.info('querying Tachyon Master')
        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:
            running_workers = soup.find('th', text=re.compile(r'Running\s+Workers:?', re.I))\
                .find_next_sibling().get_text()
        except (AttributeError, TypeError):
            qquit('UNKNOWN', 'failed to find parse Tachyon Master info for running workers' % self.__dict__)
        try:
            running_workers = int(running_workers)
        except (ValueError, TypeError):
            qquit('UNKNOWN', 'Tachyon Master live workers parsing returned non-integer: {0}'.format(running_workers))
        self.msg = 'Tachyon running workers = {0}'.format(running_workers)  # pylint: disable=attribute-defined-outside-init
        self.ok()
        # TODO: thresholds on number of live workers (coming soon)
        if running_workers < 1:
            self.critical()
コード例 #24
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)
        self.validate_thresholds(integer=False)

        url = 'http://%(host)s:%(port)s/master-status' % 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)))
        self.parse_output(req.content)
        log.info('server with min regions = %s regions on %s', self.server_min_regions[1], self.server_min_regions[0])
        log.info('server with max regions = %s regions on %s', self.server_max_regions[1], self.server_max_regions[0])
        imbalance = self.calculate_imbalance()
        self.msg = '{0}% region imbalance'.format(imbalance)
        self.check_thresholds(imbalance)
        self.msg += ' between HBase RegionServers hosting the most vs least number of regions'
        self.msg += ' (min = {0}, max = {1})'.format(self.server_min_regions[1], self.server_max_regions[1])
        self.msg += " | '% region imbalance'={0}%".format(imbalance)
        self.msg += self.get_perf_thresholds()
        self.msg += ' min_regions={0} max_regions={1}'.format(self.server_min_regions[1], self.server_max_regions[1])
コード例 #25
0
 def process_options(self):
     super(SeleniumHubBrowserTest, self).process_options()
     self.hub_url = self.get_opt('hub_url')
     if self.hub_url:
         validate_url(self.hub_url, 'hub')
     else:
         self.host = self.get_opt('host')
         self.port = self.get_opt('port')
         validate_host(self.host)
         validate_port(self.port)
         if self.get_opt('ssl') or int(self.port) == 443:
             self.protocol = 'https'
         self.hub_url = '{protocol}://{host}:{port}/{path}'\
                        .format(protocol=self.protocol, \
                                host=self.host, \
                                port=self.port, \
                                path=self.path)
     self.url = self.get_opt('url')
     if ':' not in self.url:
         self.url = 'http://' + self.url
     validate_url(self.url)
     self.expected_content = self.get_opt('content')
     self.expected_regex = self.get_opt('regex')
     if self.expected_regex:
         validate_regex(self.expected_regex)
         self.expected_regex = re.compile(self.expected_regex)
     elif self.url == self.url_default:
         self.expected_content = self.expected_content_default
     if not self.args:
         # test basic Chrome and Firefox are available
         self.args.append('chrome')
         self.args.append('firefox')
コード例 #26
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        url = 'http://%(host)s:%(port)s/oozie/v1/admin/status' % locals()
        req = RequestHandler().get(url)
        # should == NORMAL
        if not isJson(req.content):
            raise UnknownError(
                'non-JSON returned by Oozie server at {0}:{1}'.format(
                    host, port))
        status = None
        try:
            _ = json.loads(req.content)
            status = _['systemMode']
        except KeyError:
            raise UnknownError(
                'systemMode key was not returned in output from Oozie. {0}'.
                format(support_msg_api()))
        self.msg = 'Oozie status = {0}'.format(status)
        if status == 'NORMAL':
            self.ok()
        else:
            self.critical()
コード例 #27
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)
     self.process_expected_version_option()
コード例 #28
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        validate_host(host)
        validate_port(port)

        log.info('querying Tachyon Master')
        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:
            running_workers = soup.find('th', text=re.compile(r'Running\s+Workers:?', re.I))\
                .find_next_sibling().get_text()
        except (AttributeError, TypeError):
            qquit('UNKNOWN', 'failed to find parse Tachyon Master info for running workers' % self.__dict__)
        try:
            running_workers = int(running_workers)
        except (ValueError, TypeError):
            qquit('UNKNOWN', 'Tachyon Master live workers parsing returned non-integer: {0}'.format(running_workers))
        self.msg = 'Tachyon running workers = {0}'.format(running_workers)  # pylint: disable=attribute-defined-outside-init
        self.ok()
        # TODO: thresholds on number of live workers (coming soon)
        if running_workers < 1:
            self.critical()
コード例 #29
0
    def process_args(self):
        self.host_list = self.args
        if not self.host_list:
            self.usage(
                'no host arguments given, must give at least one regionserver host as an argument'
            )
        for host in self.host_list:
            validate_host(host)
        self.port = self.get_opt('port')
        validate_port(self.port)

        self.table = self.get_opt('table')
        table_chars = 'A-Za-z0-9:._-'
        if self.table:
            validate_chars(self.table, 'table', table_chars)
        else:
            self.table = '[{}]+'.format(table_chars)
        self.namespace = self.get_opt('namespace')
        validate_chars(self.namespace, 'hbase namespace', 'A-Za-z0-9:._-')
        self.interval = self.get_opt('interval')
        self.count = self.get_opt('count')
        self.since_uptime = self.get_opt('average')
        validate_int(self.interval, 'interval')
        validate_int(self.count, 'count')
        self.interval = int(self.interval)
        self.count = int(self.count)
        if self.count == 0:
            self.disable_timeout()
        if self.get_opt('reads'):
            self.show.add('read')
        if self.get_opt('writes'):
            self.show.add('write')
        if self.get_opt('total'):
            self.show.add('total')
コード例 #30
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)
コード例 #31
0
 def run(self):
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     all_services = self.get_opt('all')
     services_str = self.get_opt('services')
     cancel = self.get_opt('cancel')
     if cancel and (all_services or services_str):
         self.usage(
             'cannot specify --cancel and --services/--all simultaneously' +
             ', --cancel will cancel all pending service checks')
     if all_services and services_str:
         self.usage(
             'cannot specify --all and --services simultaneously, they are mutually exclusive'
         )
     services_requested = []
     if services_str:
         services_requested = [
             service.strip().upper() for service in services_str.split(',')
         ]
     list_clusters = self.get_opt('list_clusters')
     list_services = self.get_opt('list_services')
     clusters = self.get_clusters()
     if list_clusters:
         if self.verbose > 0:
             print('Ambari Clusters:\n')
         print('\n'.join(clusters))
         sys.exit(3)
     if not self.cluster and len(clusters) == 1:
         self.cluster = clusters[0]
         log.info(
             'no --cluster specified, but only one cluster managed by Ambari'
             + ', inferring --cluster=\'%s\'', self.cluster)
     validate_chars(self.cluster, 'cluster', r'\w\s\.-')
     self.services = self.get_services()
     if list_services:
         if self.verbose > 0:
             print('Ambari Services:\n')
         print('\n'.join(self.services))
         sys.exit(3)
     if not services_requested and not all_services and not cancel:
         self.usage('no --services specified, nor was --all requested')
     services_to_check = []
     if all_services:
         services_to_check = self.services
     else:
         for service_requested in services_requested:
             if service_requested not in self.services:
                 die('service \'{0}\' is not in the list of available services in Ambari!'
                     .format(service_requested) +
                     ' Here is the list of services available:\n' +
                     '\n'.join(self.services))
         services_to_check = services_requested
     if cancel:
         self.cancel_service_checks()
     else:
         self.request_service_checks(services_to_check)
コード例 #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'
コード例 #33
0
 def process_args(self):
     if not self.name:
         raise CodingError("didn't name check, please set self.name in __init__()")
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     self._process_args()
コード例 #34
0
 def process_args(self):
     if not self.name:
         raise CodingError("didn't name check, please set self.name in __init__()")
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     self._process_args()
コード例 #35
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'
コード例 #36
0
 def process_args(self):
     if not self.name:
         raise CodingError("didn't name check, please set self.name in __init__()")
     self.no_args()
     self.host = self.get_opt("host")
     self.port = self.get_opt("port")
     validate_host(self.host)
     validate_port(self.port)
     self.validate_thresholds()
コード例 #37
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        slave = self.get_opt('slave')
        list_slaves = self.get_opt('list_slaves')
        validate_host(host)
        validate_port(port)
        if not list_slaves:
            validate_host(slave, 'slave')

        url = 'http://%(host)s:%(port)s/master/slaves' % 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))
        content = req.content
        if not isJson(content):
            qquit('UNKNOWN', 'invalid JSON returned by Mesos Master')
        data = json.loads(content)
        if log.isEnabledFor(logging.DEBUG):
            log.debug('\n%s', jsonpp(data))
        slaves = {}
        regex = re.compile(r'^slave\(\d+\)\@(.+):\d+')
        try:
            for item in data['slaves']:
                match = regex.match(item['pid'])
                if match:
                    slaves[item['hostname']] = match.group(1)
                else:
                    slaves[item['hostname']] = item['pid']
        except KeyError:
            qquit(
                'UNKNOWN',
                'failed to parse slaves from Mesos API output. {0}'.format(
                    support_msg_api))
        if list_slaves:
            qquit('UNKNOWN', 'Slaves list:\n\n{0}'.format(dict_lines(slaves)))
        log.info('found slaves:\n\n{0}\n'.format(dict_lines(slaves)))
        slave = slave.lower()
        for _ in slaves:
            if slave == _.lower() or slave == slaves[_].lower():
                qquit('OK',
                      "Mesos slave '{0}' registered with master".format(slave))
                break
        else:
            qquit('CRITICAL',
                  "Mesos slave '{0}' not registered with master".format(slave))
コード例 #38
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)
     self.expected = self.get_opt('expected')
     if self.expected is not None:
         validate_regex(self.expected)
         log.info('expected version regex: %s', self.expected)
コード例 #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)
     self.expected = self.get_opt('expected')
     if self.expected is not None:
         validate_regex(self.expected)
         log.info('expected version regex: %s', self.expected)
コード例 #40
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')
コード例 #41
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')
コード例 #42
0
 def process_options(self):
     super(PostgreSQLCLI, self).process_options()
     self.host = self.get_opt('host')
     self.host = self.get_opt('host')
     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)
     self.port = int(self.port)
コード例 #43
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)
コード例 #44
0
 def process_args(self):
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     # pika library requires int type
     self.port = self.port
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     validate_host(self.host)
     validate_port(self.port)
     self.port = int(self.port)
     validate_user(self.user)
     validate_password(self.password)
     self.vhost = self.get_opt('vhost')
     self.vhost = self.vhost if self.vhost else '/'
     validate_chars(self.vhost, 'vhost', r'/\w\._-')
     self.exchange = self.get_opt('exchange')
     if self.exchange:
         validate_chars(self.exchange, 'exchange', r'\w\._-')
     else:
         log_option('exchange', self.exchange)
     self.exchange_type = self.get_opt('exchange_type')
     if self.exchange_type:
         if self.exchange_type not in self.valid_exchange_types:
             self.usage('invalid --exchange-type given, expected one of: {valid_exchange_types}'\
                        .format(valid_exchange_types=', '.join(self.valid_exchange_types)))
     log_option('exchange type', self.exchange_type)
     self.queue = self.get_opt('queue')
     if self.queue:
         validate_chars(self.queue, 'queue', r'\w\._-')
     else:
         log_option('queue', self.queue)
     self.routing_key = self.get_opt('routing_key')
     if not self.routing_key:
         self.routing_key = self.queue
     log_option('routing key', self.routing_key)
     #self.no_ack = self.get_opt('no_ack')
     log_option('no ack', self.no_ack)
     self.connection_attempts = self.get_opt('connection_attempts')
     validate_int(self.connection_attempts, 'connection attempts', min_value=1, max_value=10)
     self.connection_attempts = int(self.connection_attempts)
     self.retry_delay = self.get_opt('retry_delay')
     validate_int(self.retry_delay, 'retry delay', min_value=0, max_value=10)
     self.retry_delay = int(self.retry_delay)
     self.use_transactions = self.get_opt('use_transactions')
     #self.durable = not self.get_opt('non_durable')
     if self.get_opt('non_durable'):
         self.durable = False
     log_option('non-durable', not self.durable)
     sleep_secs = self.get_opt('sleep')
     if sleep_secs:
         # validation done through property wrapper
         self.sleep_secs = sleep_secs
     log_option('sleep secs', self.sleep_secs)
     self.validate_thresholds()
コード例 #45
0
 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)
 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)
コード例 #47
0
 def process_args(self):
     log.setLevel(logging.INFO)
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     regex = self.get_opt('regex')
     if regex:
         validate_regex(regex)
         self.table_regex = re.compile(regex, re.I)
         log.info('filtering to compact only tables matching regex \'{0}\''.format(regex))
コード例 #48
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)
コード例 #49
0
 def process_args(self):
     if not self.name:
         raise CodingError("didn't name check, please set self.name in __init__()")
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     validate_host(self.host)
     validate_port(self.port)
     self.validate_thresholds()
     sleep_secs = self.get_opt('sleep')
     if sleep_secs:
         # validation done through property wrapper
         self.sleep_secs = sleep_secs
コード例 #50
0
 def validate_options(self):
     if not self.host_list:
         self.usage('no hosts specified')
     validate_hostport_list(self.host_list, port_optional=True)
     validate_port(self.port)
     if self.protocol and self.protocol not in ('http', 'https', 'ping'):
         code_error('invalid protocol, must be one of http or https')
     if self.regex:
         if not self.protocol:
             self.usage('--regex cannot be used without --http / --https')
         validate_regex(self.regex)
         self.regex = re.compile(self.regex)
     validate_int(self.num_threads, 'num threads', 1, 100)
コード例 #51
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        slave = self.get_opt('slave')
        list_slaves = self.get_opt('list_slaves')
        validate_host(host)
        validate_port(port)
        if not list_slaves:
            validate_host(slave, 'slave')

        url = 'http://%(host)s:%(port)s/master/slaves' % 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:
            if req.status_code == 404:
                qquit('CRITICAL', '%s %s (did you point this at the correct Mesos Master?)'
                                  % (req.status_code, req.reason))
            qquit('CRITICAL', "Non-200 response! %s %s" % (req.status_code, req.reason))
        content = req.content
        if not isJson(content):
            qquit('UNKNOWN', 'invalid JSON returned by Mesos Master')
        data = json.loads(content)
        if log.isEnabledFor(logging.DEBUG):
            log.debug('\n%s', jsonpp(data))
        slaves = {}
        regex = re.compile(r'^slave\(\d+\)\@(.+):\d+')
        try:
            for item in data['slaves']:
                match = regex.match(item['pid'])
                if match:
                    slaves[item['hostname']] = match.group(1)
                else:
                    slaves[item['hostname']] = item['pid']
        except KeyError:
            qquit('UNKNOWN', 'failed to parse slaves from Mesos API output. {0}'.format(support_msg_api))
        if list_slaves:
            qquit('UNKNOWN', 'Slaves list:\n\n{0}'.format(dict_lines(slaves)))
        log.info('found slaves:\n\n{0}\n'.format(dict_lines(slaves)))
        slave = slave.lower()
        for _ in slaves:
            if slave == _.lower() or slave == slaves[_].lower():
                qquit('OK', "Mesos slave '{0}' registered with master".format(slave))
                break
        else:
            qquit('CRITICAL', "Mesos slave '{0}' not registered with master".format(slave))
コード例 #52
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)
コード例 #53
0
ファイル: rest_nagiosplugin.py プロジェクト: HariSekhon/pylib
 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'
コード例 #54
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)
コード例 #55
0
 def run(self):
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     all_services = self.get_opt('all')
     services_str = self.get_opt('services')
     cancel = self.get_opt('cancel')
     if cancel and (all_services or services_str):
         self.usage('cannot specify --cancel and --services/--all simultaneously' +
                    ', --cancel will cancel all pending service checks')
     if all_services and services_str:
         self.usage('cannot specify --all and --services simultaneously, they are mutually exclusive')
     services_requested = []
     if services_str:
         services_requested = [service.strip().upper() for service in services_str.split(',')]
     list_clusters = self.get_opt('list_clusters')
     list_services = self.get_opt('list_services')
     clusters = self.get_clusters()
     if list_clusters:
         if self.verbose > 0:
             print('Ambari Clusters:\n')
         print('\n'.join(clusters))
         sys.exit(3)
     if not self.cluster and len(clusters) == 1:
         self.cluster = clusters[0]
         log.info('no --cluster specified, but only one cluster managed by Ambari' +
                  ', inferring --cluster=\'%s\'', self.cluster)
     validate_chars(self.cluster, 'cluster', r'\w\s\.-')
     self.services = self.get_services()
     if list_services:
         if self.verbose > 0:
             print('Ambari Services:\n')
         print('\n'.join(self.services))
         sys.exit(3)
     if not services_requested and not all_services and not cancel:
         self.usage('no --services specified, nor was --all requested')
     services_to_check = []
     if all_services:
         services_to_check = self.services
     else:
         for service_requested in services_requested:
             if service_requested not in self.services:
                 die('service \'{0}\' is not in the list of available services in Ambari!'.format(service_requested)
                     + ' Here is the list of services available:\n' + '\n'.join(self.services))
         services_to_check = services_requested
     if cancel:
         self.cancel_service_checks()
     else:
         self.request_service_checks(services_to_check)
コード例 #56
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_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()
コード例 #57
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')
     self.prefix_length = self.get_opt('key_prefix_length')
     self.sort = self.get_opt('sort')
     self.sort_desc = self.get_opt('desc')
     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:._-')
         validate_int(self.prefix_length, 'row key prefix length', 1, 10)
         self.prefix_length = int(self.prefix_length)
コード例 #58
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.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)