예제 #1
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info['hostnames'] = {}
        metadata_whitelist = [
            'hostname',
            'fqdn',
            'ipv4',
            'instance-id'
        ]
        if self.metadata:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        status_info['hostnames'][key] = host
                        break

        # Checks.d Status
        status_info['checks'] = {}
        for cs in self.check_statuses:
            status_info['checks'][cs.name] = {'instances': {}}
            for s in cs.instance_statuses:
                status_info['checks'][cs.name]['instances'][s.instance_id] = {
                    'status': s.status,
                    'has_error': s.has_error(),
                    'has_warnings': s.has_warnings(),
                }
                if s.has_error():
                    status_info['checks'][cs.name]['instances'][s.instance_id]['error'] = s.error
                if s.has_warnings():
                    status_info['checks'][cs.name]['instances'][s.instance_id]['warnings'] = s.warnings
            status_info['checks'][cs.name]['metric_count'] = cs.metric_count
            status_info['checks'][cs.name]['event_count'] = cs.event_count

        # Emitter status
        status_info['emitter'] = []
        for es in self.emitter_statuses:
            check_status = {
                'name': es.name,
                'status': es.status,
                'has_error': es.has_error(),
                }
            if es.has_error():
                check_status['error'] = es.error
            status_info['emitter'].append(check_status)

        osname = config.get_os()

        try:
            status_info['confd_path'] = config.get_confd_path(osname)
        except config.PathNotFound:
            status_info['confd_path'] = 'Not found'
        
        try:
            status_info['checksd_path'] = config.get_checksd_path(osname)
        except config.PathNotFound:
            status_info['checksd_path'] = 'Not found'

        return status_info
예제 #2
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info['hostnames'] = {}

        # Checks.d Status
        status_info['checks'] = {}
        check_statuses = self.check_statuses + get_jmx_status()
        for cs in check_statuses:
            status_info['checks'][cs.name] = {'instances': {}}
            if cs.init_failed_error:
                status_info['checks'][cs.name]['init_failed'] = True
                status_info['checks'][
                    cs.name]['traceback'] = cs.init_failed_traceback
            else:
                status_info['checks'][cs.name] = {'instances': {}}
                status_info['checks'][cs.name]['init_failed'] = False
                for s in cs.instance_statuses:
                    status_info['checks'][cs.name]['instances'][
                        s.instance_id] = {
                            'status': s.status,
                            'has_error': s.has_error(),
                            'has_warnings': s.has_warnings(),
                        }
                    if s.has_error():
                        status_info['checks'][cs.name]['instances'][
                            s.instance_id]['error'] = s.error
                    if s.has_warnings():
                        status_info['checks'][cs.name]['instances'][
                            s.instance_id]['warnings'] = s.warnings
                status_info['checks'][
                    cs.name]['metric_count'] = cs.metric_count
                status_info['checks'][cs.name]['event_count'] = cs.event_count

        # Emitter status
        status_info['emitter'] = []
        for es in self.emitter_statuses:
            check_status = {
                'name': es.name,
                'status': es.status,
                'has_error': es.has_error()
            }
            if es.has_error():
                check_status['error'] = es.error
            status_info['emitter'].append(check_status)

        osname = config.get_os()

        try:
            status_info['confd_path'] = config.get_confd_path(osname)
        except config.PathNotFound:
            status_info['confd_path'] = 'Not found'

        try:
            status_info['checksd_path'] = config.get_checksd_path(osname)
        except config.PathNotFound:
            status_info['checksd_path'] = 'Not found'

        return status_info
예제 #3
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info["hostnames"] = {}
        metadata_whitelist = ["hostname", "fqdn", "ipv4", "instance-id"]
        if self.metadata:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        status_info["hostnames"][key] = host
                        break

        # Checks.d Status
        status_info["checks"] = {}
        check_statuses = self.check_statuses + get_jmx_status()
        for cs in check_statuses:
            status_info["checks"][cs.name] = {"instances": {}}
            if cs.init_failed_error:
                status_info["checks"][cs.name]["init_failed"] = True
                status_info["checks"][cs.name]["traceback"] = cs.init_failed_traceback
            else:
                status_info["checks"][cs.name] = {"instances": {}}
                status_info["checks"][cs.name]["init_failed"] = False
                for s in cs.instance_statuses:
                    status_info["checks"][cs.name]["instances"][s.instance_id] = {
                        "status": s.status,
                        "has_error": s.has_error(),
                        "has_warnings": s.has_warnings(),
                    }
                    if s.has_error():
                        status_info["checks"][cs.name]["instances"][s.instance_id]["error"] = s.error
                    if s.has_warnings():
                        status_info["checks"][cs.name]["instances"][s.instance_id]["warnings"] = s.warnings
                status_info["checks"][cs.name]["metric_count"] = cs.metric_count
                status_info["checks"][cs.name]["event_count"] = cs.event_count

        # Emitter status
        status_info["emitter"] = []
        for es in self.emitter_statuses:
            check_status = {"name": es.name, "status": es.status, "has_error": es.has_error()}
            if es.has_error():
                check_status["error"] = es.error
            status_info["emitter"].append(check_status)

        osname = config.get_os()

        try:
            status_info["confd_path"] = config.get_confd_path(osname)
        except config.PathNotFound:
            status_info["confd_path"] = "Not found"

        try:
            status_info["checksd_path"] = config.get_checksd_path(osname)
        except config.PathNotFound:
            status_info["checksd_path"] = "Not found"

        return status_info
예제 #4
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info['hostnames'] = {}
        metadata_whitelist = ['hostname', 'fqdn', 'ipv4', 'instance-id']
        if self.metadata:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        status_info['hostnames'][key] = host
                        break

        # Checks.d Status
        status_info['checks'] = {}
        check_statuses = self.check_statuses + get_jmx_status()
        for cs in check_statuses:
            status_info['checks'][cs.name] = {'instances': {}}
            for s in cs.instance_statuses:
                status_info['checks'][cs.name]['instances'][s.instance_id] = {
                    'status': s.status,
                    'has_error': s.has_error(),
                    'has_warnings': s.has_warnings(),
                }
                if s.has_error():
                    status_info['checks'][cs.name]['instances'][
                        s.instance_id]['error'] = s.error
                if s.has_warnings():
                    status_info['checks'][cs.name]['instances'][
                        s.instance_id]['warnings'] = s.warnings
            status_info['checks'][cs.name]['metric_count'] = cs.metric_count
            status_info['checks'][cs.name]['event_count'] = cs.event_count

        # Emitter status
        status_info['emitter'] = []
        for es in self.emitter_statuses:
            check_status = {
                'name': es.name,
                'status': es.status,
                'has_error': es.has_error(),
            }
            if es.has_error():
                check_status['error'] = es.error
            status_info['emitter'].append(check_status)

        osname = config.get_os()

        try:
            status_info['confd_path'] = config.get_confd_path(osname)
        except config.PathNotFound:
            status_info['confd_path'] = 'Not found'

        try:
            status_info['checksd_path'] = config.get_checksd_path(osname)
        except config.PathNotFound:
            status_info['checksd_path'] = 'Not found'

        return status_info
예제 #5
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info['hostnames'] = {}

        # Checks.d Status
        status_info['checks'] = {}
        check_statuses = self.check_statuses + get_jmx_status()
        for cs in check_statuses:
            status_info['checks'][cs.name] = {'instances': {}}
            if cs.init_failed_error:
                status_info['checks'][cs.name]['init_failed'] = True
                status_info['checks'][cs.name]['traceback'] = cs.init_failed_traceback
            else:
                status_info['checks'][cs.name] = {'instances': {}}
                status_info['checks'][cs.name]['init_failed'] = False
                for s in cs.instance_statuses:
                    status_info['checks'][cs.name]['instances'][s.instance_id] = {
                        'status': s.status,
                        'has_error': s.has_error(),
                        'has_warnings': s.has_warnings(),
                    }
                    if s.has_error():
                        status_info['checks'][cs.name]['instances'][
                            s.instance_id]['error'] = s.error
                    if s.has_warnings():
                        status_info['checks'][cs.name]['instances'][
                            s.instance_id]['warnings'] = s.warnings
                status_info['checks'][cs.name]['metric_count'] = cs.metric_count
                status_info['checks'][cs.name]['event_count'] = cs.event_count

        # Emitter status
        status_info['emitter'] = []
        for es in self.emitter_statuses:
            check_status = {'name': es.name,
                            'status': es.status,
                            'has_error': es.has_error()}
            if es.has_error():
                check_status['error'] = es.error
            status_info['emitter'].append(check_status)

        osname = config.get_os()

        paths = util.Paths()
        try:
            status_info['confd_path'] = paths.get_confd_path()
        except config.PathNotFound:
            status_info['confd_path'] = 'Not found'

        try:
            status_info['checksd_path'] = paths.get_checksd_path()
        except config.PathNotFound:
            status_info['checksd_path'] = 'Not found'

        return status_info
예제 #6
0
def get_check_class(agentConfig, check_name):
    """Return the class object for a given check name"""
    from config import get_os, get_checks_paths, get_check_class

    osname = get_os()
    checks_paths = get_checks_paths(agentConfig, osname)
    for check in itertools.chain(*checks_paths):
        py_check_name = os.path.basename(check).split('.')[0]
        if py_check_name == check_name:
            check_class = get_check_class(check_name, check)
            if isinstance(check_class, dict) or check_class is None:
                log.warning('Failed to load the check class for %s.' % check_name)
                return None
            else:
                return check_class
예제 #7
0
def get_check_class(agentConfig, check_name):
    """Return the class object for a given check name"""
    from config import get_os, get_checks_paths, get_check_class

    osname = get_os()
    checks_paths = get_checks_paths(agentConfig, osname)
    for check in itertools.chain(*checks_paths):
        py_check_name = os.path.basename(check).split('.')[0]
        if py_check_name == check_name:
            check_class = get_check_class(check_name, check)
            if isinstance(check_class, dict) or check_class is None:
                log.warning('Failed to load the check class for %s.' %
                            check_name)
                return None
            else:
                return check_class
예제 #8
0
def get_check_class(agentConfig, check_name):
    """Return the class object for a given check name"""
    from config import get_os, get_checks_places, get_valid_check_class

    osname = get_os()
    checks_places = get_checks_places(osname, agentConfig)
    for check_path_builder in checks_places:
        check_path, _ = check_path_builder(check_name)
        if not os.path.exists(check_path):
            continue

        check_is_valid, check_class, load_failure = get_valid_check_class(check_name, check_path)
        if check_is_valid:
            return check_class

    log.warning('Failed to load the check class for %s.' % check_name)
    return None
예제 #9
0
def get_check_class(agentConfig, check_name):
    """Return the class object for a given check name"""
    from config import get_os, get_checks_places, get_valid_check_class

    osname = get_os()
    checks_places = get_checks_places(osname, agentConfig)
    for check_path_builder in checks_places:
        check_path, manifest_path = check_path_builder(check_name)
        is_wheel = not check_path and not manifest_path

        if not (check_path and os.path.exists(check_path)) and not is_wheel:
            continue

        check_is_valid, check_class, load_failure = get_valid_check_class(check_name, check_path, from_site=is_wheel)
        if check_is_valid:
            return check_class

    log.warning('Failed to load the check class for %s.' % check_name)
    return None
예제 #10
0
def get_check_class(agentConfig, check_name):
    """Return the class object for a given check name"""
    from config import get_os, get_checks_places, get_valid_check_class

    osname = get_os()
    checks_places = get_checks_places(osname, agentConfig)
    for check_path_builder in checks_places:
        check_path, manifest_path = check_path_builder(check_name)
        is_wheel = not check_path and not manifest_path

        if not (check_path and os.path.exists(check_path)) and not is_wheel:
            continue

        check_is_valid, check_class, load_failure = get_valid_check_class(
            check_name, check_path, from_site=is_wheel)
        if check_is_valid:
            return check_class

    log.warning('Failed to load the check class for %s.' % check_name)
    return None
예제 #11
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info['hostnames'] = {}
        metadata_whitelist = ['hostname', 'fqdn', 'ipv4', 'instance-id']
        if self.metadata:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        status_info['hostnames'][key] = host
                        break

        # Checks.d Status
        status_info['checks'] = {}
        check_statuses = self.check_statuses + get_jmx_status()
        for cs in check_statuses:
            status_info['checks'][cs.name] = {'instances': {}}
            if cs.init_failed_error:
                status_info['checks'][cs.name]['init_failed'] = True
                status_info['checks'][
                    cs.name]['traceback'] = cs.init_failed_traceback
            else:
                status_info['checks'][cs.name] = {'instances': {}}
                status_info['checks'][cs.name]['init_failed'] = False
                for s in cs.instance_statuses:
                    status_info['checks'][cs.name]['instances'][
                        s.instance_id] = {
                            'status': s.status,
                            'has_error': s.has_error(),
                            'has_warnings': s.has_warnings(),
                        }
                    if s.has_error():
                        status_info['checks'][cs.name]['instances'][
                            s.instance_id]['error'] = s.error
                    if s.has_warnings():
                        status_info['checks'][cs.name]['instances'][
                            s.instance_id]['warnings'] = s.warnings
                status_info['checks'][
                    cs.name]['metric_count'] = cs.metric_count
                status_info['checks'][cs.name]['event_count'] = cs.event_count
                status_info['checks'][
                    cs.name]['service_check_count'] = cs.service_check_count

        # Emitter status
        status_info['emitter'] = []
        for es in self.emitter_statuses:
            check_status = {
                'name': es.name,
                'status': es.status,
                'has_error': es.has_error(),
            }
            if es.has_error():
                check_status['error'] = es.error
            status_info['emitter'].append(check_status)

        osname = config.get_os()

        try:
            status_info['confd_path'] = config.get_confd_path(osname)
        except config.PathNotFound:
            status_info['confd_path'] = 'Not found'

        try:
            status_info['checksd_path'] = config.get_checksd_path(osname)
        except config.PathNotFound:
            status_info['checksd_path'] = 'Not found'

        # Clocks
        try:
            ntp_offset, ntp_style = get_ntp_info()
            warn_ntp = len(ntp_style) > 0
            status_info["ntp_offset"] = round(ntp_offset, 4)
        except Exception as e:
            ntp_offset = "Unknown (%s)" % str(e)
            warn_ntp = True
            status_info["ntp_offset"] = ntp_offset
        status_info["ntp_warning"] = warn_ntp
        status_info["utc_time"] = datetime.datetime.utcnow().__str__()

        return status_info
예제 #12
0
class CollectorStatus(AgentStatus):

    NAME = 'Collector'

    def __init__(self,
                 check_statuses=None,
                 emitter_statuses=None,
                 metadata=None):
        AgentStatus.__init__(self)
        self.check_statuses = check_statuses or []
        self.emitter_statuses = emitter_statuses or []
        self.metadata = metadata or []

    @property
    def status(self):
        for check_status in self.check_statuses:
            if check_status.status == STATUS_ERROR:
                return STATUS_ERROR
        return STATUS_OK

    def has_error(self):
        return self.status != STATUS_OK

    def body_lines(self):
        # Metadata whitelist
        metadata_whitelist = ['hostname', 'fqdn', 'ipv4', 'instance-id']

        lines = ['Clocks', '======', '']
        try:
            ntp_offset, ntp_styles = get_ntp_info()
            lines.append('  ' + style('NTP offset', *ntp_styles) + ': ' +
                         style('%s s' % round(ntp_offset, 4), *ntp_styles))
        except Exception, e:
            lines.append('  NTP offset: Unknown (%s)' % str(e))
        lines.append('  System UTC time: ' +
                     datetime.datetime.utcnow().__str__())
        lines.append('')

        # Paths to checks.d/conf.d
        lines += ['Paths', '=====', '']

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'

        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks.d: ' + checksd_path)
        lines.append('')

        # Hostnames
        lines += ['Hostnames', '=========', '']

        if not self.metadata:
            lines.append("  No host information available yet.")
        else:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        lines.append("  " + key + ": " + host)
                        break

        lines.append('')

        # Checks.d Status
        lines += ['Checks', '======', '']
        check_statuses = self.check_statuses + get_jmx_status()
        if not check_statuses:
            lines.append("  No checks have run yet.")
        else:
            for cs in check_statuses:
                check_lines = ['  ' + cs.name, '  ' + '-' * len(cs.name)]
                if cs.init_failed_error:
                    check_lines.append(
                        "    - initialize check class [%s]: %s" % (style(
                            STATUS_ERROR, 'red'), repr(cs.init_failed_error)))
                    if self.verbose and cs.init_failed_traceback:
                        check_lines.extend(
                            '      ' + line
                            for line in cs.init_failed_traceback.split('\n'))
                else:
                    for s in cs.instance_statuses:
                        c = 'green'
                        if s.has_warnings():
                            c = 'yellow'
                        if s.has_error():
                            c = 'red'
                        line = "    - instance #%s [%s]" % (s.instance_id,
                                                            style(s.status, c))
                        if s.has_error():
                            line += u": %s" % s.error
                        if s.metric_count is not None:
                            line += " collected %s metrics" % s.metric_count

                        check_lines.append(line)

                        if s.has_warnings():
                            for warning in s.warnings:
                                warn = warning.split('\n')
                                if not len(warn): continue
                                check_lines.append(
                                    u"        %s: %s" %
                                    (style("Warning", 'yellow'), warn[0]))
                                check_lines.extend(u"        %s" % l
                                                   for l in warn[1:])
                        if self.verbose and s.traceback is not None:
                            check_lines.extend(
                                '      ' + line
                                for line in s.traceback.split('\n'))

                    check_lines += [
                        "    - Collected %s metric%s, %s event%s & %s service check%s"
                        % (cs.metric_count, plural(
                            cs.metric_count), cs.event_count,
                           plural(cs.event_count), cs.service_check_count,
                           plural(cs.service_check_count)),
                    ]

                    if cs.library_versions is not None:
                        check_lines += ["    - Dependencies:"]
                        for library, version in cs.library_versions.iteritems(
                        ):
                            check_lines += [
                                "        - %s: %s" % (library, version)
                            ]

                    check_lines += [""]

                lines += check_lines

        # Emitter status
        lines += ["", "Emitters", "========", ""]
        if not self.emitter_statuses:
            lines.append("  No emitters have run yet.")
        else:
            for es in self.emitter_statuses:
                c = 'green'
                if es.has_error():
                    c = 'red'
                line = "  - %s [%s]" % (es.name, style(es.status, c))
                if es.status != STATUS_OK:
                    line += ": %s" % es.error
                lines.append(line)

        return lines
예제 #13
0
    def body_lines(self):
        lines = [
            'Clocks',
            '======',
            ''
        ]
        try:
            ntp_offset, ntp_styles = get_ntp_info()
            lines.append('  ' + style('NTP offset', *ntp_styles) + ': ' +
                         style('%s s' % round(ntp_offset, 4), *ntp_styles))
        except Exception as e:
            lines.append('  NTP offset: Unkwown (%s)' % str(e))
        lines.append('  System UTC time: ' + datetime.datetime.utcnow().__str__())
        lines.append('')

        # Paths to checks_d/conf.d
        lines += [
            'Paths',
            '=====',
            ''
        ]

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'

        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks_d: ' + checksd_path)
        lines.append('')

        # Hostnames
        lines += [
            'Hostnames',
            '=========',
            ''
        ]

        # Checks.d Status
        lines += [
            'Checks',
            '======',
            ''
        ]
        check_statuses = self.check_statuses + get_jmx_status()
        if not check_statuses:
            lines.append("  No checks have run yet.")
        else:
            for cs in check_statuses:
                check_lines = [
                    '  ' + cs.name,
                    '  ' + '-' * len(cs.name)
                ]
                if cs.init_failed_error:
                    check_lines.append("    - initialize check class [%s]: %s" %
                                       (style(STATUS_ERROR, 'red'),
                                        repr(cs.init_failed_error)))
                    if self.verbose and cs.init_failed_traceback:
                        check_lines.extend('      ' + line for line in
                                           cs.init_failed_traceback.split('\n'))
                else:
                    for s in cs.instance_statuses:
                        c = 'green'
                        if s.has_warnings():
                            c = 'yellow'
                        if s.has_error():
                            c = 'red'
                        line = "    - instance #%s [%s]" % (s.instance_id, style(s.status, c))
                        if s.has_error():
                            line += u": %s" % s.error
                        if s.metric_count is not None:
                            line += " collected %s metrics" % s.metric_count

                        check_lines.append(line)

                        if s.has_warnings():
                            for warning in s.warnings:
                                warn = warning.split('\n')
                                if not len(warn):
                                    continue
                                check_lines.append(u"        %s: %s" %
                                                   (style("Warning", 'yellow'), warn[0]))
                                check_lines.extend(u"        %s" % l for l in warn[1:])
                        if self.verbose and s.traceback is not None:
                            check_lines.extend('      ' + line for line in s.traceback.split('\n'))

                    check_lines += [
                        "    - Collected %s metrics & %s events" % (
                            cs.metric_count, cs.event_count),
                    ]

                    if cs.library_versions is not None:
                        check_lines += [
                            "    - Dependencies:"]
                        for library, version in cs.library_versions.iteritems():
                            check_lines += ["        - %s: %s" % (library, version)]

                    check_lines += [""]

                lines += check_lines

        # Emitter status
        lines += [
            "",
            "Emitters",
            "========",
            ""
        ]
        if not self.emitter_statuses:
            lines.append("  No emitters have run yet.")
        else:
            for es in self.emitter_statuses:
                c = 'green'
                if es.has_error():
                    c = 'red'
                line = "  - %s [%s]" % (es.name, style(es.status, c))
                if es.status != STATUS_OK:
                    line += ": %s" % es.error
                lines.append(line)

        return lines
예제 #14
0
    def body_lines(self):
        # Metadata whitelist
        metadata_whitelist = [
            'hostname',
            'fqdn',
            'ipv4',
            'instance-id'
        ]

        lines = [
            'Clocks',
            '======',
            ''
        ]
        try:
            ntp_offset, ntp_styles = get_ntp_info()
            lines.append('  ' + style('NTP offset', *ntp_styles) + ': ' + style('%s s' % round(ntp_offset, 4), *ntp_styles))
        except Exception as e:
            lines.append('  NTP offset: Unknown (%s)' % str(e))
        lines.append('  System UTC time: ' + datetime.datetime.utcnow().__str__())
        lines.append('')

        # Paths to checks.d/conf.d
        lines += [
            'Paths',
            '=====',
            ''
        ]

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'

        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks.d: ' + checksd_path)
        lines.append('')

        # Hostnames
        lines += [
            'Hostnames',
            '=========',
            ''
        ]

        if not self.host_metadata:
            lines.append("  No host information available yet.")
        else:
            for key, host in self.host_metadata.iteritems():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        lines.append("  " + key + ": " + host)
                        break

        lines.append('')

        # Checks.d Status
        lines += [
            'Checks',
            '======',
            ''
        ]
        check_statuses = self.check_statuses + get_jmx_status()
        if not check_statuses:
            lines.append("  No checks have run yet.")
        else:
            for cs in check_statuses:
                check_lines = [
                    '  ' + cs.name + ' ({})'.format(cs.check_version),
                    '  ' + '-' * (len(cs.name) + 3 + len(cs.check_version))
                ]
                if cs.init_failed_error:
                    check_lines.append("    - initialize check class [%s]: %s" %
                                       (style(STATUS_ERROR, 'red'),
                                        repr(cs.init_failed_error)))
                    if self.verbose and cs.init_failed_traceback:
                        check_lines.extend('      ' + line for line in
                                           cs.init_failed_traceback.split('\n'))
                else:
                    for s in cs.instance_statuses:
                        c = 'green'
                        if s.has_warnings():
                            c = 'yellow'
                        if s.has_error():
                            c = 'red'
                        line = "    - instance #%s [%s]" % (
                            s.instance_id, style(s.status, c))
                        if s.has_error():
                            line += u": %s" % s.error
                        if s.metric_count is not None:
                            line += " collected %s metrics" % s.metric_count
                        if s.instance_check_stats is not None:
                            line += " Last run duration: %s" % s.instance_check_stats.get('run_time')

                        check_lines.append(line)

                        if s.has_warnings():
                            for warning in s.warnings:
                                warn = warning.split('\n')
                                if not len(warn):
                                    continue
                                check_lines.append(u"        %s: %s" %
                                                   (style("Warning", 'yellow'), warn[0]))
                                check_lines.extend(u"        %s" % l for l in
                                                   warn[1:])
                        if self.verbose and s.traceback is not None:
                            check_lines.extend('      ' + line for line in
                                               s.traceback.split('\n'))

                    check_lines += [
                        "    - Collected %s metric%s, %s event%s & %s service check%s" % (
                            cs.metric_count, plural(cs.metric_count),
                            cs.event_count, plural(cs.event_count),
                            cs.service_check_count, plural(cs.service_check_count)),
                    ]

                    if cs.check_stats is not None:
                        check_lines += [
                            "    - Stats: %s" % pretty_statistics(cs.check_stats)
                        ]

                    if cs.library_versions is not None:
                        check_lines += [
                            "    - Dependencies:"]
                        for library, version in cs.library_versions.iteritems():
                            check_lines += [
                                "        - %s: %s" % (library, version)]

                    check_lines += [""]

                lines += check_lines

        # Metadata status
        metadata_enabled = 1#_is_affirmative(get_config().get('display_service_metadata', False))

        if metadata_enabled:
            lines += [
                "",
                "Service metadata",
                "================",
                ""
            ]
            if not check_statuses:
                lines.append("  No checks have run yet.")
            else:
                meta_lines = []
                for cs in check_statuses:
                    # Check title
                    check_line = [
                        '  ' + cs.name,
                        '  ' + '-' * len(cs.name)
                    ]
                    instance_lines = []
                    for i, meta in enumerate(cs.service_metadata):
                        if not meta:
                            continue
                        instance_lines += ["    - instance #%s:" % i]
                        for k, v in meta.iteritems():
                            instance_lines += ["        - %s: %s" % (k, v)]
                    if instance_lines:
                        check_line += instance_lines
                        meta_lines += check_line
                if meta_lines:
                    lines += meta_lines
                else:
                    lines.append("  No metadata were collected.")

        # Emitter status
        lines += [
            "",
            "Emitters",
            "========",
            ""
        ]
        if not self.emitter_statuses:
            lines.append("  No emitters have run yet.")
        else:
            for es in self.emitter_statuses:
                c = 'green'
                if es.has_error():
                    c = 'red'
                line = "  - %s [%s]" % (es.name, style(es.status, c))
                if es.status != STATUS_OK:
                    line += ": %s" % es.error
                lines.append(line)

        return lines
예제 #15
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info['hostnames'] = {}
        metadata_whitelist = [
            'hostname',
            'fqdn',
            'ipv4',
            'instance-id'
        ]
        if self.host_metadata:
            for key, host in self.host_metadata.iteritems():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        status_info['hostnames'][key] = host
                        break

        # Checks.d Status
        status_info['checks'] = {}
        check_statuses = self.check_statuses + get_jmx_status()
        for cs in check_statuses:
            status_info['checks'][cs.name] = {'instances': {}}
            status_info['checks'][cs.name]['check_version'] = cs.check_version
            if cs.init_failed_error:
                status_info['checks'][cs.name]['init_failed'] = True
                status_info['checks'][cs.name]['traceback'] = \
                    cs.init_failed_traceback or cs.init_failed_error
            else:
                status_info['checks'][cs.name]['init_failed'] = False
                for s in cs.instance_statuses:
                    status_info['checks'][cs.name]['instances'][s.instance_id] = {
                        'status': s.status,
                        'has_error': s.has_error(),
                        'has_warnings': s.has_warnings(),
                    }
                    if s.has_error():
                        status_info['checks'][cs.name]['instances'][s.instance_id]['error'] = s.error
                    if s.has_warnings():
                        status_info['checks'][cs.name]['instances'][s.instance_id]['warnings'] = s.warnings
                status_info['checks'][cs.name]['metric_count'] = cs.metric_count
                status_info['checks'][cs.name]['event_count'] = cs.event_count
                status_info['checks'][cs.name]['service_check_count'] = cs.service_check_count

        # Emitter status
        status_info['emitter'] = []
        for es in self.emitter_statuses:
            check_status = {
                'name': es.name,
                'status': es.status,
                'has_error': es.has_error(),
            }
            if es.has_error():
                check_status['error'] = es.error
            status_info['emitter'].append(check_status)

        osname = config.get_os()

        try:
            status_info['confd_path'] = config.get_confd_path(osname)
        except config.PathNotFound:
            status_info['confd_path'] = 'Not found'

        try:
            status_info['checksd_path'] = config.get_checksd_path(osname)
        except config.PathNotFound:
            status_info['checksd_path'] = 'Not found'

        # Clocks
        try:
            ntp_offset, ntp_style = get_ntp_info()
            warn_ntp = len(ntp_style) > 0
            status_info["ntp_offset"] = round(ntp_offset, 4)
        except Exception as e:
            ntp_offset = "Unknown (%s)" % str(e)
            warn_ntp = True
            status_info["ntp_offset"] = ntp_offset
        status_info["ntp_warning"] = warn_ntp
        status_info["utc_time"] = datetime.datetime.utcnow().__str__()

        return status_info
예제 #16
0
    def body_lines(self):
        # Metadata whitelist
        metadata_whitelist = [
            'hostname',
            'fqdn',
            'ipv4',
            'instance-id'
        ]

        lines = [
            'Clocks',
            '======',
            ''
        ]
        try:
            ntp_offset, ntp_styles = get_ntp_info()
            lines.append('  ' + style('NTP offset', *ntp_styles) + ': ' + style('%s s' % round(ntp_offset, 4), *ntp_styles))
        except Exception as e:
            lines.append('  NTP offset: Unknown (%s)' % str(e))
        lines.append('  System UTC time: ' + datetime.datetime.utcnow().__str__())
        lines.append('')

        # Paths to checks.d/conf.d
        lines += [
            'Paths',
            '=====',
            ''
        ]

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'

        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks.d: ' + checksd_path)
        lines.append('')

        # Hostnames
        lines += [
            'Hostnames',
            '=========',
            ''
        ]

        if not self.host_metadata:
            lines.append("  No host information available yet.")
        else:
            for key, host in self.host_metadata.iteritems():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        lines.append("  " + key + ": " + host)
                        break

        lines.append('')

        # Checks.d Status
        lines += [
            'Checks',
            '======',
            ''
        ]
        check_statuses = self.check_statuses + get_jmx_status()
        if not check_statuses:
            lines.append("  No checks have run yet.")
        else:
            for cs in check_statuses:
                check_lines = [
                    '  ' + cs.name + ' ({})'.format(cs.check_version),
                    '  ' + '-' * (len(cs.name) + 3 + len(cs.check_version))
                ]
                if cs.init_failed_error:
                    check_lines.append("    - initialize check class [%s]: %s" %
                                       (style(STATUS_ERROR, 'red'),
                                        repr(cs.init_failed_error)))
                    if self.verbose and cs.init_failed_traceback:
                        check_lines.extend('      ' + line for line in
                                           cs.init_failed_traceback.split('\n'))
                else:
                    for s in cs.instance_statuses:
                        c = 'green'
                        if s.has_warnings():
                            c = 'yellow'
                        if s.has_error():
                            c = 'red'
                        line = "    - instance #%s [%s]" % (
                            s.instance_id, style(s.status, c))
                        if s.has_error():
                            line += u": %s" % s.error
                        if s.metric_count is not None:
                            line += " collected %s metrics" % s.metric_count
                        if s.instance_check_stats is not None:
                            line += " Last run duration: %s" % s.instance_check_stats.get('run_time')

                        check_lines.append(line)

                        if s.has_warnings():
                            for warning in s.warnings:
                                warn = warning.split('\n')
                                if not len(warn):
                                    continue
                                check_lines.append(u"        %s: %s" %
                                                   (style("Warning", 'yellow'), warn[0]))
                                check_lines.extend(u"        %s" % l for l in
                                                   warn[1:])
                        if self.verbose and s.traceback is not None:
                            check_lines.extend('      ' + line for line in
                                               s.traceback.split('\n'))

                    check_lines += [
                        "    - Collected %s metric%s, %s event%s & %s service check%s" % (
                            cs.metric_count, plural(cs.metric_count),
                            cs.event_count, plural(cs.event_count),
                            cs.service_check_count, plural(cs.service_check_count)),
                    ]

                    if cs.check_stats is not None:
                        check_lines += [
                            "    - Stats: %s" % pretty_statistics(cs.check_stats)
                        ]

                    if cs.library_versions is not None:
                        check_lines += [
                            "    - Dependencies:"]
                        for library, version in cs.library_versions.iteritems():
                            check_lines += [
                                "        - %s: %s" % (library, version)]

                    check_lines += [""]

                lines += check_lines

        # Metadata status
        metadata_enabled = _is_affirmative(get_config().get('display_service_metadata', False))

        if metadata_enabled:
            lines += [
                "",
                "Service metadata",
                "================",
                ""
            ]
            if not check_statuses:
                lines.append("  No checks have run yet.")
            else:
                meta_lines = []
                for cs in check_statuses:
                    # Check title
                    check_line = [
                        '  ' + cs.name,
                        '  ' + '-' * len(cs.name)
                    ]
                    instance_lines = []
                    for i, meta in enumerate(cs.service_metadata):
                        if not meta:
                            continue
                        instance_lines += ["    - instance #%s:" % i]
                        for k, v in meta.iteritems():
                            instance_lines += ["        - %s: %s" % (k, v)]
                    if instance_lines:
                        check_line += instance_lines
                        meta_lines += check_line
                if meta_lines:
                    lines += meta_lines
                else:
                    lines.append("  No metadata were collected.")

        # Emitter status
        lines += [
            "",
            "Emitters",
            "========",
            ""
        ]
        if not self.emitter_statuses:
            lines.append("  No emitters have run yet.")
        else:
            for es in self.emitter_statuses:
                c = 'green'
                if es.has_error():
                    c = 'red'
                line = "  - %s [%s]" % (es.name, style(es.status, c))
                if es.status != STATUS_OK:
                    line += ": %s" % es.error
                lines.append(line)

        return lines
예제 #17
0
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library.

from __future__ import print_function
import os
import sys

MIN_PYTHON_VERSION = (3, 7)

# check python version
current_version = sys.version_info
if not current_version >= MIN_PYTHON_VERSION:
    print("OctoBot requires a Python version to be higher or equal to Python " + str(MIN_PYTHON_VERSION[0])
          + "." + str(MIN_PYTHON_VERSION[1]) + " current Python version is " + str(current_version[0])
          + "." + str(current_version[1]) + "\n"
          + "You can download Python last versions on: https://www.python.org/downloads/", file=sys.stderr)
    sys.exit(-1)
else:
    # binary tentacle importation
    sys.path.append(os.path.dirname(sys.executable))

    # if compatible version, can proceed with imports
    from config import PlatformsName, get_os
    from tools.logging.logging_util import get_logger

    # check sudo rights
    if get_os() is not PlatformsName.WINDOWS and os.getuid() == 0:
        get_logger("PythonChecker").warning("OctoBot is started with admin / sudo rights that are not required, "
                                            "please check you starting command ")
예제 #18
0
    def body_lines(self):
        # Metadata whitelist
        metadata_whitelist = ['hostname', 'fqdn', 'ipv4', 'instance-id']
        # Paths to checks.d/conf.d
        lines = ['Paths', '=====', '']

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'

        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks.d: ' + checksd_path)
        lines.append('')

        # Hostnames
        lines += ['Hostnames', '=========', '']

        if not self.metadata:
            lines.append("  No host information available yet.")
        else:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        lines.append("  " + key + ": " + host)
                        break

        lines.append('')

        # Checks.d Status
        lines += ['Checks', '======', '']
        check_statuses = self.check_statuses + get_jmx_status()
        if not check_statuses:
            lines.append("  No checks have run yet.")
        else:
            for cs in check_statuses:
                check_lines = ['  ' + cs.name, '  ' + '-' * len(cs.name)]
                if cs.init_failed_error:
                    check_lines.append(
                        "    - initialize check class [%s]: %s" % (style(
                            STATUS_ERROR, 'red'), repr(cs.init_failed_error)))
                    if self.verbose and cs.init_failed_traceback:
                        check_lines.extend(
                            '      ' + line
                            for line in cs.init_failed_traceback.split('\n'))
                else:
                    for s in cs.instance_statuses:
                        c = 'green'
                        if s.has_warnings():
                            c = 'yellow'
                        if s.has_error():
                            c = 'red'
                        line = "    - instance #%s [%s]" % (s.instance_id,
                                                            style(s.status, c))
                        if s.has_error():
                            line += u": %s" % s.error

                        check_lines.append(line)

                        if s.has_warnings():
                            for warning in s.warnings:
                                warn = warning.split('\n')
                                if not len(warn): continue
                                check_lines.append(
                                    u"        %s: %s" %
                                    (style("Warning", 'yellow'), warn[0]))
                                check_lines.extend(u"        %s" % l
                                                   for l in warn[1:])
                        if self.verbose and s.traceback is not None:
                            check_lines.extend(
                                '      ' + line
                                for line in s.traceback.split('\n'))

                    check_lines += [
                        "    - Collected %s metrics & %s events" %
                        (cs.metric_count, cs.event_count),
                    ]

                    if cs.library_versions is not None:
                        check_lines += ["    - Dependencies:"]
                        for library, version in cs.library_versions.iteritems(
                        ):
                            check_lines += [
                                "        - %s: %s" % (library, version)
                            ]

                    check_lines += [""]

                lines += check_lines

        # Emitter status
        lines += ["", "Emitters", "========", ""]
        if not self.emitter_statuses:
            lines.append("  No emitters have run yet.")
        else:
            for es in self.emitter_statuses:
                c = 'green'
                if es.has_error():
                    c = 'red'
                line = "  - %s [%s]" % (es.name, style(es.status, c))
                if es.status != STATUS_OK:
                    line += ": %s" % es.error
                lines.append(line)

        return lines
예제 #19
0
    def body_lines(self):
        # Metadata whitelist
        metadata_whitelist = [
            'hostname',
            'fqdn',
            'ipv4',
            'instance-id'
        ]
        # Paths to checks.d/conf.d
        lines = [
            'Paths',
            '=====',
            ''
        ]

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'
        
        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks.d: ' + checksd_path)
        lines.append('')

        # Hostnames
        lines += [
            'Hostnames',
            '=========',
            ''
        ]

        if not self.metadata:
            lines.append("  No host information available yet.")
        else:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        lines.append("  " + key + ": " + host)
                        break

        lines.append('')

        # Checks.d Status
        lines += [
            'Checks',
            '======',
            ''
        ]
        check_statuses = self.check_statuses + get_jmx_status()
        if not check_statuses:
            lines.append("  No checks have run yet.")
        else:
            for cs in check_statuses:
                check_lines = [
                    '  ' + cs.name,
                    '  ' + '-' * len(cs.name)
                ]
                if cs.init_failed_error:
                    check_lines.append("    - initialize check class [%s]: %s" %
                                       (style(STATUS_ERROR, 'red'),
                                       repr(cs.init_failed_error)))
                    if self.verbose and cs.init_failed_traceback:
                        check_lines.extend('      ' + line for line in
                                           cs.init_failed_traceback.split('\n'))
                else:
                    for s in cs.instance_statuses:
                        c = 'green'
                        if s.has_warnings():
                            c = 'yellow'
                        if s.has_error():
                            c = 'red'
                        line =  "    - instance #%s [%s]" % (
                                 s.instance_id, style(s.status, c))
                        if s.has_error():
                            line += u": %s" % s.error

                        check_lines.append(line)

                        if s.has_warnings():
                            for warning in s.warnings:
                                warn = warning.split('\n')
                                if not len(warn): continue
                                check_lines.append(u"        %s: %s" %
                                    (style("Warning", 'yellow'), warn[0]))
                                check_lines.extend(u"        %s" % l for l in
                                            warn[1:])
                        if self.verbose and s.traceback is not None:
                            check_lines.extend('      ' + line for line in
                                           s.traceback.split('\n'))

                    check_lines += [
                        "    - Collected %s metrics & %s events" % (cs.metric_count, cs.event_count),
                    ]

                    if cs.library_versions is not None:
                        check_lines += [
                            "    - Dependencies:"]
                        for library, version in cs.library_versions.iteritems():
                            check_lines += [
                            "        - %s: %s" % (library, version)]

                    check_lines += [""]

                lines += check_lines

        # Emitter status
        lines += [
            "",
            "Emitters",
            "========",
            ""
        ]
        if not self.emitter_statuses:
            lines.append("  No emitters have run yet.")
        else:
            for es in self.emitter_statuses:
                c = 'green'
                if es.has_error():
                    c = 'red'
                line = "  - %s [%s]" % (es.name, style(es.status,c))
                if es.status != STATUS_OK:
                    line += ": %s" % es.error
                lines.append(line)

        return lines
예제 #20
0
    def body_lines(self):
        lines = ['Clocks', '======', '']
        try:
            ntp_offset, ntp_styles = get_ntp_info()
            lines.append('  ' + style('NTP offset', *ntp_styles) + ': ' +
                         style('%s s' % round(ntp_offset, 4), *ntp_styles))
        except Exception as e:
            lines.append('  NTP offset: Unkwown (%s)' % str(e))
        lines.append('  System UTC time: ' +
                     datetime.datetime.utcnow().__str__())
        lines.append('')

        # Paths to checks_d/conf.d
        lines += ['Paths', '=====', '']

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'

        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks_d: ' + checksd_path)
        lines.append('')

        # Hostnames
        lines += ['Hostnames', '=========', '']

        # Checks.d Status
        lines += ['Checks', '======', '']
        check_statuses = self.check_statuses + get_jmx_status()
        if not check_statuses:
            lines.append("  No checks have run yet.")
        else:
            for cs in check_statuses:
                check_lines = ['  ' + cs.name, '  ' + '-' * len(cs.name)]
                if cs.init_failed_error:
                    check_lines.append(
                        "    - initialize check class [%s]: %s" % (style(
                            STATUS_ERROR, 'red'), repr(cs.init_failed_error)))
                    if self.verbose and cs.init_failed_traceback:
                        check_lines.extend(
                            '      ' + line
                            for line in cs.init_failed_traceback.split('\n'))
                else:
                    for s in cs.instance_statuses:
                        c = 'green'
                        if s.has_warnings():
                            c = 'yellow'
                        if s.has_error():
                            c = 'red'
                        line = "    - instance #%s [%s]" % (s.instance_id,
                                                            style(s.status, c))
                        if s.has_error():
                            line += u": %s" % s.error
                        if s.metric_count is not None:
                            line += " collected %s metrics" % s.metric_count

                        check_lines.append(line)

                        if s.has_warnings():
                            for warning in s.warnings:
                                warn = warning.split('\n')
                                if not len(warn):
                                    continue
                                check_lines.append(
                                    u"        %s: %s" %
                                    (style("Warning", 'yellow'), warn[0]))
                                check_lines.extend(u"        %s" % l
                                                   for l in warn[1:])
                        if self.verbose and s.traceback is not None:
                            check_lines.extend(
                                '      ' + line
                                for line in s.traceback.split('\n'))

                    check_lines += [
                        "    - Collected %s metrics & %s events" %
                        (cs.metric_count, cs.event_count),
                    ]

                    if cs.library_versions is not None:
                        check_lines += ["    - Dependencies:"]
                        for library, version in cs.library_versions.iteritems(
                        ):
                            check_lines += [
                                "        - %s: %s" % (library, version)
                            ]

                    check_lines += [""]

                lines += check_lines

        # Emitter status
        lines += ["", "Emitters", "========", ""]
        if not self.emitter_statuses:
            lines.append("  No emitters have run yet.")
        else:
            for es in self.emitter_statuses:
                c = 'green'
                if es.has_error():
                    c = 'red'
                line = "  - %s [%s]" % (es.name, style(es.status, c))
                if es.status != STATUS_OK:
                    line += ": %s" % es.error
                lines.append(line)

        return lines
예제 #21
0
                     datetime.datetime.utcnow().__str__())
        lines.append('')

        # uuid
        lines = ['UUID', '======', '']
        try:
            uuid = get_uuid()
            lines.append('  System uuid: ' + str(uuid))
        except Exception, e:
            lines.append('  System uuid: Unknown (%s)' % str(e))
        lines.append('')

        # Paths to checks.d/conf.d
        lines += ['Paths', '=====', '']

        osname = config.get_os()

        try:
            confd_path = config.get_confd_path(osname)
        except config.PathNotFound:
            confd_path = 'Not found'

        try:
            checksd_path = config.get_checksd_path(osname)
        except config.PathNotFound:
            checksd_path = 'Not found'

        lines.append('  conf.d: ' + confd_path)
        lines.append('  checks.d: ' + checksd_path)
        lines.append('')
예제 #22
0
    def to_dict(self):
        status_info = AgentStatus.to_dict(self)

        # Hostnames
        status_info["hostnames"] = {}
        metadata_whitelist = ["hostname", "fqdn", "ipv4", "instance-id"]
        if self.metadata:
            for key, host in self.metadata.items():
                for whitelist_item in metadata_whitelist:
                    if whitelist_item in key:
                        status_info["hostnames"][key] = host
                        break

        # Checks.d Status
        status_info["checks"] = {}
        check_statuses = self.check_statuses + get_jmx_status()
        for cs in check_statuses:
            status_info["checks"][cs.name] = {"instances": {}}
            if cs.init_failed_error:
                status_info["checks"][cs.name]["init_failed"] = True
                status_info["checks"][cs.name]["traceback"] = cs.init_failed_traceback
            else:
                status_info["checks"][cs.name] = {"instances": {}}
                status_info["checks"][cs.name]["init_failed"] = False
                for s in cs.instance_statuses:
                    status_info["checks"][cs.name]["instances"][s.instance_id] = {
                        "status": s.status,
                        "has_error": s.has_error(),
                        "has_warnings": s.has_warnings(),
                    }
                    if s.has_error():
                        status_info["checks"][cs.name]["instances"][s.instance_id]["error"] = s.error
                    if s.has_warnings():
                        status_info["checks"][cs.name]["instances"][s.instance_id]["warnings"] = s.warnings
                status_info["checks"][cs.name]["metric_count"] = cs.metric_count
                status_info["checks"][cs.name]["event_count"] = cs.event_count
                status_info["checks"][cs.name]["service_check_count"] = cs.service_check_count

        # Emitter status
        status_info["emitter"] = []
        for es in self.emitter_statuses:
            check_status = {"name": es.name, "status": es.status, "has_error": es.has_error()}
            if es.has_error():
                check_status["error"] = es.error
            status_info["emitter"].append(check_status)

        osname = config.get_os()

        try:
            status_info["confd_path"] = config.get_confd_path(osname)
        except config.PathNotFound:
            status_info["confd_path"] = "Not found"

        try:
            status_info["checksd_path"] = config.get_checksd_path(osname)
        except config.PathNotFound:
            status_info["checksd_path"] = "Not found"

        # Clocks
        try:
            ntp_offset, ntp_style = get_ntp_info()
            warn_ntp = len(ntp_style) > 0
            status_info["ntp_offset"] = round(ntp_offset, 4)
        except Exception as e:
            ntp_offset = "Unknown (%s)" % str(e)
            warn_ntp = True
            status_info["ntp_offset"] = ntp_offset
        status_info["ntp_warning"] = warn_ntp
        status_info["utc_time"] = datetime.datetime.utcnow().__str__()

        return status_info