Beispiel #1
0
def do_docker_show():
    d = get_kunai_json('/docker/stats')
    scontainers = d.get('containers')
    simages     = d.get('images')

    print_info_title('Docker Stats')
    if not scontainers:
        cprint("No running containers", color='grey')
    for (cid, stats) in scontainers.iteritems():
        print_info_title('Container:%s' % cid)
        keys = stats.keys()
        keys.sort()
        e = []
        for k in keys:
            sd = stats[k]
            e.append( (k, sd['value']) )
            
        # Normal agent information
        print_2tab(e, capitalize=False, col_size=30)

    for (cid, stats) in simages.iteritems():
        print_info_title('Image:%s (sum)' % cid)
        keys = stats.keys()
        keys.sort()
        e = []
        for k in keys:
            sd = stats[k]
            e.append( (k, sd['value']) )
            
        # Normal agent information
        print_2tab(e, capitalize=False, col_size=30)
Beispiel #2
0
    collectors = d.get("collectors")

    e = [
        ("name", name),
        ("uuid", _uuid),
        ("version", version),
        ("pid", pid),
        ("port", port),
        ("addr", addr),
        ("socket", socket_path),
        ("threads", nb_threads),
    ]

    # Normal agent information
    print_info_title("Kunai Daemon")
    print_2tab(e)

    # Normal agent information
    int_server = httpservers["external"]
    if int_server:
        e = (
            ("threads", int_server["nb_threads"]),
            ("idle_threads", int_server["idle_threads"]),
            ("queue", int_server["queue"]),
        )
        print_info_title("HTTP (LAN)")
        print_2tab(e)

    # Unix socket http daemon
    int_server = httpservers["internal"]
    if int_server:
Beispiel #3
0
def do_info(show_logs):
    d = get_kunai_json('/agent/info')
    
    logs = d.get('logs')
    version = d.get('version')
    pid = d.get('pid')
    name = d.get('name')
    port = d.get('port')
    addr = d.get('addr')
    nb_threads = d.get('threads')['nb_threads']
    httpservers = d.get('httpservers', {'internal':None, 'external':None})
    socket_path = d.get('socket')
    _uuid = d.get('uuid')
    graphite = d.get('graphite')
    statsd = d.get('statsd')
    websocket = d.get('websocket')
    dns = d.get('dns')
    _docker = d.get('docker')

    e = [('name', name), ('uuid',_uuid), ('version', version), ('pid', pid), ('port',port), ('addr',addr), ('socket',socket_path), ('threads', nb_threads)]

    # Normal agent information
    print_info_title('Kunai Daemon')
    print_2tab(e)
    
    # Normal agent information
    int_server = httpservers['external']
    if int_server:
        e = (('threads', int_server['nb_threads']), ('idle_threads', int_server['idle_threads']), ('queue', int_server['queue']) )
        print_info_title('HTTP (LAN)')
        print_2tab(e)

    # Unix socket http daemon
    int_server = httpservers['internal']
    if int_server:
        e = (('threads', int_server['nb_threads']), ('idle_threads', int_server['idle_threads']), ('queue', int_server['queue']) )
        print_info_title('HTTP (Unix Socket)')
        print_2tab(e)
        
    # Now DNS part
    print_info_title('DNS')
    if dns is None:
        cprint('No dns configured')
    else:
        w = dns
        e = [('enabled', w['enabled']), ('port', w['port']), ('domain',w['domain']) ]
        print_2tab(e)
    
    # Now websocket part
    print_info_title('Websocket')
    if websocket is None:
        cprint('No websocket configured')
    else:
        w = websocket
        st = d.get('websocket_info', None)
        e = [('enabled', w['enabled']), ('port', w['port']) ]
        if st:
            e.append( ('Nb connexions', st.get('nb_connexions')) )
        print_2tab(e)

    # Now graphite part
    print_info_title('Graphite')
    if graphite is None:
        cprint('No graphite configured')
    else:
        g = graphite
        e = [('enabled', g['enabled']), ('port', g['port']), ('udp', g['udp']), ('tcp', g['tcp']) ]
        print_2tab(e)

    # Now statsd part
    print_info_title('Statsd')
    if statsd is None:
        cprint('No statsd configured')
    else:
        s = statsd
        e = [('enabled', s['enabled']), ('port', s['port']), ('interval', s['interval'])]
        print_2tab(e)


    # Now statsd part
    print_info_title('Docker')
    _d = _docker
    if _d['connected']:
        e = [('enabled', _d['enabled']), ('connected', _d['connected']),
             ('version',_d['version']), ('api', _d['api']),
              ('containers', len(_d['containers'])),
             ('images', len(_d['images'])),
        ]
    else:
        e = [
            ('enabled', {'value':_d['enabled'], 'color':'grey'}),
            ('connected', {'value':_d['connected'], 'color':'grey'}),
            ]
            
    print_2tab(e)
    
    # Show errors logs if any
    print_info_title('Logs')
    errors  = logs.get('ERROR')
    warnings = logs.get('WARNING')
 
    # Put warning and errors in red/yellow if need only
    e = []
    if len(errors) > 0:
        e.append( ('error', {'value':len(errors), 'color':'red'}) )
    else:
        e.append( ('error', len(errors)) )
    if len(warnings) > 0:
        e.append( ('warning', {'value':len(warnings), 'color':'yellow'}) )
    else:
        e.append( ('warning', len(warnings)) )

    print_2tab(e)

    if show_logs:
        if len(errors) > 0:
            print_info_title('Error logs')
            for s in errors:
                cprint(s, color='red')
    
        if len(warnings) > 0:
            print_info_title('Warning logs')
            for s in warnings:
                cprint(s, color='yellow')
        
    logger.debug('Raw information: %s' % d)
Beispiel #4
0
        logger.error(exp)
        return

    try:
        d = json.loads(r)
    except ValueError, exp:# bad json
        logger.error('Bad return from the server %s' % exp)
        return

    e = []
    for i in d:
        e.append( (i['name'], ','.join(i['tags']) ) )

    # Normal agent information
    print_info_title('Detectors')
    print_2tab(e)
    

def do_detect_run():
    try:
        (code, r) = get_kunai_local('/agent/detectors/run')
    except request_errors, exp:
        logger.error(exp)
        return

    try:
        d = json.loads(r)
    except ValueError, exp:  # bad json
        logger.error('Bad return from the server %s' % exp)
        return