Ejemplo n.º 1
0
def edit(request, tcp_id):
    app_list = AppService.objects.filter(type = 3)
    tcpinfo = TCPInfo.objects.get(id=int(tcp_id))
    
    if request.POST:
        tcpinfo.responsetime = request.POST.get('responsetime', None)
        
        tcpinfo.save()
        
        # 维护redis中当前应用的配置信息
        maintain_tcp_port_configuration(tcpinfo.app)
        
        # 维护监控项
        maintain_monitoritem_add_or_update(tcpinfo)
        
        # 更新当前应用对应的时间戳
        update_app_timestamp(tcpinfo.app)

        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 0
        log.relate_id = tcpinfo.id
        log.content="execute edit tcpinfo " + tcpinfo.app.app_name + " " + tcpinfo.port + " success!"
        log.level = 1
        log.save()
        return HttpResponse(simplejson.dumps({"statusCode":200, "url": "/tcpinfo/index", "message":u'编辑成功'}), mimetype='application/json')    
    return render_to_response('tcpinfo/edit.html',{'app_list':app_list, 'tcpinfo':tcpinfo})
Ejemplo n.º 2
0
def edit(request, nocip_id):
    nocip = NOCIP.objects.get(id=int(nocip_id))
    if request.POST:
        nocid = request.POST.get('nocid', None)
        ip = request.POST.get('ip', None)
        # 判断nocid+ip是否重复
        nocips = NOCIP.objects.filter(nocid__iexact=nocid, ip__iexact=ip).exclude(id=int(nocip_id))
        if nocips:
            return HttpResponse(simplejson.dumps({"statusCode":400, "url": "/nocip/index", "message":u'当前机房IP对应信息已经存在不能修改'}), mimetype='application/json')   
        
        nocip.nocid = nocid
        nocip.ip = ip
        nocip.save()
        
        # 更新机房IP对应信息
        maintain_noc_ip_map(nocid)
        
        # 更新当前机房下所有应用对应的时间戳
        update_timestamp_by_nocid(nocid)

        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 0
        log.relate_id = nocip.id
        log.content="execute edit nocip " + nocip.nocid + " " + nocip.ip + " success!"
        log.level = 1
        log.save()
        return HttpResponse(simplejson.dumps({"statusCode":200, "url": "/nocip/index", "message":u'编辑成功'}), mimetype='application/json')    
    return render_to_response('nocip/edit.html',{'nocip':nocip, 'noc_info_dict':noc_info_dict})
Ejemplo n.º 3
0
def delete(request, tcp_id):
    item  = None
    try:
        item = TCPInfo.objects.get(id=int(tcp_id))
    except BaseException:
        return HttpResponse(simplejson.dumps({"statusCode":400, "message":u'当前TCP服务不存在!'}), mimetype='application/json')
    item.delete()
    
    # 维护redis中当前应用的配置信息
    maintain_tcp_port_configuration(item.app)
    
    # 维护监控项信息
    maintain_monitoritem_delete(item)
    
    # 更新当前应用对应的时间戳
    update_app_timestamp(item.app)
    
    # 日志
    log = Log()
    log.username = request.user.username
    log.log_type = 0
    log.relate_id = item.id
    log.content="execute delete tcpinfo " + item.app.app_name + " " + item.port + " success!"
    log.level = 1
    log.save()
    return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/tcpinfo/index", "message":u'删除成功'}), mimetype='application/json')
Ejemplo n.º 4
0
def add(request):
    pdict = {}
    for key in permission_type_dict:
        if key != 4:    # 节点权限的配置另外实现
            pdict[permission_type_dict[key]]=Permission.objects.filter(type=key).order_by('id')
    
    if request.POST:
        role_name = request.POST.get("role_name")
        role_desc = request.POST.get("role_desc")
        permission_id_list = request.POST.getlist("permission_id")
        # 保存角色信息
        role = Role();
        role.name = role_name
        role.desc = role_desc
        role.save()
        # 保存角色和权限对应关系
        for pid in permission_id_list:
            role.permissions.add(pid)
        
        # 日志
        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 2
        log.relate_id = role.id
        log.content="execute add role " + role.name + " success!"
        log.level = 1
        log.save()
        return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/role/index", "message":u'添加成功'}), 
            mimetype='application/json')
    return render_to_response('role/add.html',{'pdict':pdict})
Ejemplo n.º 5
0
def add(request):
    app_list = AppService.objects.all();
    if request.POST:
        mitem = MonitorItem()
        
        mitem.monitor_type = request.POST.get('monitor_type')
        var_name = request.POST.get('var_name')
        # 去除空格
        mitem.var_name = var_name.strip()
        mitem.formula = request.POST.get('formula')
        
        warning_type = request.POST.get('warning_type')
        w = request.POST.get('w')
        w1 = request.POST.get('w1')
        w2 = request.POST.get('w2')
        mitem.warning_threshold = generate_threshold(warning_type,w,w1,w2)
            
        critical_type = request.POST.get('critical_type')
        c = request.POST.get('c')
        c1 = request.POST.get('c1')
        c2 = request.POST.get('c2')
        mitem.critical_threshold = generate_threshold(critical_type,c,c1,c2)
        
        mitem.desc = request.POST.get('desc')
        mitem.app_id = request.POST.get('app_id')
        
        mitem.save()

        # 根据监控项变化情况,同步监控点
        sync_monitor_point(mitem.app)
        
        # 同步应用的监控规则
        sync_app_mitem(mitem.app)
        
        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 4
        log.relate_id = mitem.id
        log.content="execute add monitoritem " + mitem.app.app_name + " " + mitem.desc + " success!"
        log.level = 1
        log.save()
        return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/monitoritem/index", "message":u'添加成功'}), mimetype='application/json')        
    return render_to_response('monitoritem/add.html',{'app_list':app_list}) 
Ejemplo n.º 6
0
def edit(request, item_id):
    app_list = AppService.objects.all()
    item = MonitorItem.objects.get(id=int(item_id))
    warning_tuple = parse_threshold(item.warning_threshold)
    critical_tuple = parse_threshold(item.critical_threshold)
    
    if request.POST:
        
        item.monitor_type = request.POST.get('monitor_type')
        item.var_name = request.POST.get('var_name')
        # 去除空格
        item.var_name = item.var_name.strip()
        item.formula = request.POST.get('formula')

        warning_type = request.POST.get('warning_type')
        w = request.POST.get('w')
        w1 = request.POST.get('w1')
        w2 = request.POST.get('w2')
        item.warning_threshold = generate_threshold(warning_type,w,w1,w2)
           
        critical_type = request.POST.get('critical_type')
        c = request.POST.get('c')
        c1 = request.POST.get('c1')
        c2 = request.POST.get('c2')
        item.critical_threshold = generate_threshold(critical_type,c,c1,c2)

        item.desc = request.POST.get('desc')
        item.save()
        
        # 同步应用的监控规则
        sync_app_mitem(item.app)
        
        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 4
        log.relate_id = item.id
        log.content="execute edit monitoritem " + item.app.app_name + " " + item.desc + " success!"
        log.level = 1
        log.save()
        return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/monitoritem/index", "message":u'编辑成功'}), mimetype='application/json')    
    return render_to_response('monitoritem/edit.html',{'app_list':app_list,'item':item,'warning_tuple':warning_tuple,'critical_tuple':critical_tuple})
Ejemplo n.º 7
0
def edit(request, role_id):
    pdict = {}
    for key in permission_type_dict:
        # 节点权限的配置另外实现
        if key != 4:    
            pdict[permission_type_dict[key]] = Permission.objects.filter(type=key).order_by('id')
            print pdict[permission_type_dict[1]]
    role = Role.objects.get(id=int(role_id))#把具体的角色管理中所对应的角色名称取出来
    
    permission_id_list = [] 
    for p in role.permissions.all():
        permission_id_list.append(p.id)
    
    if request.POST:
        role_name = request.POST.get("role_name")
        role_desc = request.POST.get("role_desc")
        permission_id_list = request.POST.getlist("permission_id")
        #保存角色信息
        role.name = role_name
        role.desc = role_desc
        role.save()
        # 保存角色和权限对应关系
        role.permissions.clear()
        for pid in permission_id_list:
            role.permissions.add(pid)
        
        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 2
        log.relate_id = role.id
        log.content = "execute edit role " + role.name + " success!"
        log.level = 1
        log.save()
        
        return HttpResponse(simplejson.dumps({"statusCode":200, "url": "/role/index", "message":u'编辑成功'}),
            mimetype='application/json')  
    return render_to_response('role/edit.html', {"pdict":pdict, "role": role, "permission_id_list":permission_id_list},
			        context_instance=RequestContext(request))
Ejemplo n.º 8
0
def add(request):
    app_list = AppService.objects.filter(type = 1);
    if request.POST:
        url = request.POST.get('url', None)
        responsetime = request.POST.get('responsetime', None)
        type = request.POST.get('type', None)
        target = request.POST.get('target', None)
        value = request.POST.get('value', None)
        app_id = request.POST.get('app_id', 1)
        
        # 判断url是否重复
        urlinfos = URLInfo.objects.filter(url__iexact=url, is_deleted=1)
        if urlinfos:
            return HttpResponse(simplejson.dumps({"statusCode":400, "url": "/urlinfo/index", "message":u'当前URL已经存在不能添加'}), mimetype='application/json')   
        
        urlinfo = URLInfo(url=url, responsetime=responsetime, type=type, target=target, value=value, app_id=app_id)
        urlinfo.save()
        
        # 维护redis中当前应用的配置信息
        maintain_http_url_configuration(urlinfo.app)
        
        # 维护监控项
        maintain_monitoritem_add_or_update(urlinfo)
        
        # 更新当前应用对应的时间戳
        update_app_timestamp(urlinfo.app)
        

        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 0
        log.relate_id = urlinfo.id
        log.content="execute add urlinfo " + urlinfo.app.app_name + " " + urlinfo.url + " success!"
        log.level = 1
        log.save()
        return HttpResponse(simplejson.dumps({"statusCode":200, "url": "/urlinfo/index", "message":u'添加成功'}), mimetype='application/json')        
    return render_to_response('urlinfo/add.html',{'app_list':app_list}) 
Ejemplo n.º 9
0
def edit(request, url_id):
    app_list = AppService.objects.filter(type = 1)
    urlinfo = URLInfo.objects.get(id=int(url_id))
    
    if request.POST:
        # 禁止修改url
#        url = request.POST.get('url', None)
#        urlinfos = URLInfo.objects.filter(url__iexact=url, is_deleted=1).exclude(id=int(url_id))
#        if urlinfos:
#            return HttpResponse(simplejson.dumps({"statusCode":400, "url": "/urlinfo/index", "message":u'当前URL已经存在不能修改'}), mimetype='application/json')   
#        
#        urlinfo.url = url
        urlinfo.responsetime = request.POST.get('responsetime', None)
        urlinfo.type = request.POST.get('type', None)
        urlinfo.target = request.POST.get('target', None)
        urlinfo.value = request.POST.get('value', None)
        
        urlinfo.save()
        
        # 维护redis中当前应用的配置信息
        maintain_http_url_configuration(urlinfo.app)
        
        # 维护监控项
        maintain_monitoritem_add_or_update(urlinfo)
        
        # 更新当前应用对应的时间戳
        update_app_timestamp(urlinfo.app)

        # 日志
        log = Log()
        log.username = request.user.username
        log.log_type = 0
        log.relate_id = urlinfo.id
        log.content="execute edit urlinfo " + urlinfo.app.app_name + " " + urlinfo.url + " success!"
        log.level = 1
        log.save()
        return HttpResponse(simplejson.dumps({"statusCode":200, "url": "/urlinfo/index", "message":u'编辑成功'}), mimetype='application/json')    
    return render_to_response('urlinfo/edit.html',{'app_list':app_list, 'urlinfo':urlinfo})
Ejemplo n.º 10
0
def delete(request, nocip_id):
    item  = None
    try:
        item = NOCIP.objects.get(id=int(nocip_id))
    except BaseException:
        return HttpResponse(simplejson.dumps({"statusCode":400, "message":u'当前机房IP对应信息不存在!'}), mimetype='application/json')
    item.delete()
    
    # 在redis中删除指定机房下指定IP
    maintain_noc_ip_map(item.nocid)
    
    # 更新当前机房下所有应用对应的时间戳
    update_timestamp_by_nocid(item.nocid)
    
    # 日志
    log = Log()
    log.username = request.user.username
    log.log_type = 0
    log.relate_id = item.id
    log.content="execute delete nocip " + item.nocid + " " + item.ip + " success!"
    log.level = 1
    log.save()
    return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/nocip/index", "message":u'删除成功'}), mimetype='application/json')
Ejemplo n.º 11
0
def delete(request, item_id):
    item  = None
    try:
        item = MonitorItem.objects.get(id=int(item_id))
    except BaseException:
        return HttpResponse(simplejson.dumps({"statusCode":400, "message":u'监控项不存在!'}), mimetype='application/json')
    item.delete()
    
    # 根据监控项变化情况,同步监控点
    sync_monitor_point(item.app)
    
    # 同步应用的监控规则
    sync_app_mitem(item.app)
    
    # 日志
    log = Log()
    log.username = request.user.username
    log.log_type = 4
    log.relate_id = item.id
    log.content="execute delete monitoritem " + item.app.app_name + " " + item.desc + " success!"
    log.level = 1
    log.save()
    return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/monitoritem/index", "message":u'删除成功'}), mimetype='application/json')
Ejemplo n.º 12
0
def delete(request, role_id):
    role = None
    try:
        role = Role.objects.get(id=int(role_id))
    except BaseException:
        return HttpResponse(simplejson.dumps({"statusCode":400, "message":u'此角色不存在!'}), mimetype='application/json')
    # 删除角色和人的关联关系
    role.users.clear()
    # 删除角色和权限的关联关系
    role.permissions.clear()
    # 删除此角色
    role.delete()
    
    # 日志
    log = Log()
    log.username = request.user.username
    log.log_type = 2
    log.relate_id = role.id
    log.content="execute delete role " + role.name + " success!"
    log.level = 1
    log.save()
    
    return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/role/index", "message":u'删除成功'}), mimetype='application/json')