Exemple #1
0
def client_configs(request, client_id):
    print("--->", client_id)
    config_obj = ClientHandler(client_id)
    config = config_obj.fetch_configs()

    if config:
        return HttpResponse(json.dumps(config))
Exemple #2
0
def client_configs(request, client_id):
    config_obj = ClientHandler(client_id)
    config = config_obj.fetch_configs()
    if config:
        return HttpResponse(json.dumps(config))
    else:
        return HttpResponse(json.dumps('{"status":"ERROR_CONFIG_NOT_FOUND"}'))
Exemple #3
0
def client_configs(request,client_id):
    print("--->",client_id)
    config_obj = ClientHandler(client_id)
    config = config_obj.fetch_configs()

    if config:
        return HttpResponse(json.dumps(config))
Exemple #4
0
def client_configs(request, client_id):
    print "\033[31;1mthe client %s begin to get configuration\033[0m" % client_id
    config_obj = ClientHandler(client_id)
    config = config_obj.fetch_configs()

    if config:
        return HttpResponse(json.dumps(config))
Exemple #5
0
def host_detail(request, host_id):
    host_obj = models.Host.objects.get(id=host_id)

    config_obj = ClientHandler(host_obj.id)
    monitored_services = {
        "services": {},
        "sub_services": {}  #存储一个服务有好几个独立子服务 的监控,比如网卡服务 有好几个网卡
    }

    template_list = list(host_obj.templates.select_related())

    for host_group in host_obj.host_groups.select_related():
        template_list.extend(host_group.templates.select_related())
    print(template_list)
    for template in template_list:
        # print(template.services.select_related())

        for service in template.services.select_related():  #loop each service
            print(service)
            if not service.has_sub_service:
                monitored_services['services'][service.name] = [
                    service.plugin_name, service.interval
                ]
            else:
                monitored_services['sub_services'][service.name] = []

                # get last point from redis in order to acquire the sub-service-key
                last_data_point_key = "StatusData_%s_%s_latest" % (
                    host_obj.id, service.name)
                last_point_from_redis = REDIS_OBJ.lrange(
                    last_data_point_key, -1, -1)[0]
                if last_point_from_redis:
                    data, data_save_time = json.loads(last_point_from_redis)
                    if data:
                        service_data_dic = data.get('data')
                        for serivce_key, val in service_data_dic.items():
                            monitored_services['sub_services'][
                                service.name].append(serivce_key)

    return render(request, 'host_detail.html', {
        'host_obj': host_obj,
        'monitored_services': monitored_services
    })