예제 #1
0
파일: views.py 프로젝트: znavy/AXES
def delHostByNameView(request):
    url = getCookieUrl(request)
    game_name_cn = request.POST['del_names']
    groups = db.getGroup(url)
    for group in groups:
        if game_name_cn == group['name'].split('_')[0]:
            zabbixapi.deleteHost(url, group_id=group['groupid'])
            zabbixapi.deleteGroup(url, [group['groupid']])
    return HttpResponseRedirect(reverse('isjkgamelisturl'))
예제 #2
0
파일: views.py 프로젝트: znavy/AXES
def notjkGameListView(request):
    url = getCookieUrl(request)
    games_info = Game.objects.all()
    game_list = []
    is_exist_game = [group_name['name'].split('_')[0] for group_name in db.getGroup(url)]
    is_exist_game = list(set(is_exist_game))
    for i in games_info:
        if i.game_name_cn not in is_exist_game:
            game_list.append(i)
    context_dict = {
        'list': game_list
    }
    return render(request, 'zabbixmanage/gametablenotjk.html', context_dict)
예제 #3
0
파일: views.py 프로젝트: znavy/AXES
def updateGroupView(request, GID):
    url = getCookieUrl(request)
    if request.method == 'POST':
        GNAME = request.POST['group_name']
        zabbixapi.updateGroup(url, group_id=GID, group_name=GNAME)
        return HttpResponseRedirect(reverse('updategroupurl', args=[GID]))
    else:
        result = db.getGroup(url, group_id=GID)
        GNAME = result['name']
    context_dict = {
        "GNAME": GNAME,
        'GID': GID,
    }
    return render(request, 'zabbixmanage/updategroup.html', context_dict)
예제 #4
0
파일: views.py 프로젝트: znavy/AXES
def jkGameListView(request):
    url = getCookieUrl(request)
    zabbix_url = ZabbixUrl.objects.all()
    urllist = [i.url for i in zabbix_url]
    games_info = Game.objects.all()
    game_list = []
    is_exist_game = [group_name['name'].split('_')[0] for group_name in db.getGroup(url)]
    is_exist_game = list(set(is_exist_game))
    for i in games_info:
        if i.game_name_cn in is_exist_game:
            game_list.append(i)
    context_dict = {
        'list': game_list
    }
    request.session['urllist'] = urllist
    request.session['length'] = len(urllist)
    return render(request, 'zabbixmanage/gametableisjk.html', context_dict)
예제 #5
0
파일: views.py 프로젝트: znavy/AXES
def groupListView(request):
    url = getCookieUrl(request)
    group_info = db.getGroup(url)
    group_list = []
    project = request.user.userprofile.permission.all()
    project_list = [i.game_name_cn for i in project]
    for i in group_info:
        if i['name'].split('_')[0] in project_list:
            group_dict = {}
            group_dict['groupid'] = i['groupid']
            group_dict['name'] = i['name']
            group_dict['hosts'] = i['hosts']
            group_list.append(group_dict)
    context_dict = {
        'list': group_list,
    }
    return render(request, 'zabbixmanage/grouptable.html', context_dict)
예제 #6
0
파일: views.py 프로젝트: znavy/AXES
def groupHostListView(request, GNAME):
    url = getCookieUrl(request)
    group_name = db.getGroup(url, group_id=GNAME)['name']
    host_list = db.getHost(url, group_name=group_name)
    result = db.getProxy(url)
    game_name = GNAME.split('_')[0]
    proxy = []
    for i in result:
        proxy_dict = {}
        proxy_dict['proxyid'] = i['proxyid']
        proxy_dict['name'] = i['host']
        proxy.append(proxy_dict)
    context_dict = {
        'list': host_list,
        'proxy': proxy,
        'game_name': game_name,
    }
    return render(request, 'zabbixmanage/hostlist.html', context_dict)
예제 #7
0
파일: views.py 프로젝트: znavy/AXES
def createHostView(request):
    url = getCookieUrl(request)
    if request.method == 'POST':
        host = request.POST.get('host')
        name = request.POST.get('name')
        groups = [i for i in re.split(',|;| ', request.POST.get('group')) if i]
        groupid = []
        for group in groups:
            if zabbixapi.isGroup(url, group):
                groupid.append(db.getGroup(url, group_name=group)['groupid'])
            else:
                groupid.append(zabbixapi.createGroup(url, group)['result']['groupids'][0])
        template = request.POST.getlist('template')
        proxyid = request.POST.get('proxy')
        host_dict = dict(zip(['host_ip', 'host_name', 'group_id', 'template_id', 'proxy_id'], [host, name, groupid, template, proxyid]))
        macros_key = request.POST.getlist('macro_key')
        macros_value = request.POST.getlist('macro_value')
        macro_dict = {}
        macros = []
        for i in zip(macros_key, macros_value):
            macro_dict = {}
            if len(i[0]) >= 1 and len(i[1]) >= 1:
                macro_dict['macro'] = i[0].strip().upper()
                macro_dict['value'] = i[1].strip()
            if macro_dict:
                macros.append(macro_dict)
        zabbixapi.createOneHost(url, host_dict, macros)
        db.updateGroupHostCount(url, groupid)
        #  db.updateProxy(url, proxyid)
        return HttpResponseRedirect(reverse('hostinfourl', args=[host]))
    else:
        template_list = db.getTemplate(url)
        global_macro = zabbixapi.getGlobalMacrosInfo(url)['result']
        proxy_list = db.getProxy(url)
    context_dict = {
        "options": template_list,
        "global_macros": global_macro,
        "proxys": proxy_list,
    }
    return render(request, 'zabbixmanage/createonehost.html', context_dict)
예제 #8
0
파일: views.py 프로젝트: znavy/AXES
def maintenanceListView(request):
    url = getCookieUrl(request)
    maintenance_list = []
    maintenances = db.getMaintenance(url)
    for i in maintenances:
        maintenance_dict = {}
        group_list = []
        host_list = []
        maintenance_dict['name'] = i['name']
        for groupid in i['groupids']:
            group_list.append(db.getGroup(url, group_id=groupid)['name'])
        maintenance_dict['groups'] = group_list
        for host in i['hostids']:
            host_list.append(db.getHost(url, host_id=host)['name'])
        maintenance_dict['hosts'] = host_list
        maintenance_dict['status'] = i['status']
        maintenance_list.append(maintenance_dict)
    #  print maintenance_list
    context_dict = {
        'list': maintenance_list,
    }
    return render(request, 'zabbixmanage/maintenancelist.html', context_dict)
예제 #9
0
파일: views.py 프로젝트: znavy/AXES
def hostListView(request, GNAME):
    url = getCookieUrl(request)
    all_group = db.getGroup(url)
    host_list = []
    proxy = []
    for group in all_group:
        if re.search(GNAME, group['name']):
            result = db.getHost(url, group_id=group['groupid'])
            for i in result:
                host_list.append(i)
    result = db.getProxy(url)
    for i in result:
        proxy_dict = {}
        proxy_dict['proxyid'] = i['proxyid']
        proxy_dict['name'] = i['host']
        proxy.append(proxy_dict)
    context_dict = {
        'list': host_list,
        'proxy': proxy,
        'game_name': GNAME,
    }
    return render(request, 'zabbixmanage/hostlist.html', context_dict)
예제 #10
0
파일: views.py 프로젝트: znavy/AXES
def makeCalendarList(this_month_list, year, month, url):
    month_list = []
    for i in this_month_list:
        month_dict = {}
        if this_month_list[0] != 1:
            the_day = (datetime.date.today() + datetime.timedelta(days=(i - this_month_list[0]))).strftime("%Y-%m-%d %H:%M:%S")
            day_sec = time.mktime(time.strptime(the_day, '%Y-%m-%d %H:%M:%S'))
        else:
            the_day = (datetime.date(day=1, month=month, year=year) + datetime.timedelta(days=(i - this_month_list[0]))).strftime('%Y-%m-%d %H:%M:%S')
            day_sec = time.mktime(time.strptime(the_day, '%Y-%m-%d %H:%M:%S'))
        maintenance_info = db.getMaintenance(url)
        tmp_list = []
        num = 0
        for j in maintenance_info:
            tmp_dict = {}
            if day_sec < j['active_till'] and j['active_since'] - day_sec <= 86400:
                timeperiods = j['timeperiods'][0]
                if timeperiods['timeperiod_type'] == '0':
                    diff = timeperiods['start_date'] - day_sec
                    if diff <= 86400 and diff >= 0:
                        num += 1
                        tmp_dict[u'maintenancename'] = j['name']
                        tmp_dict[u'类型'] = '一次性'
                        tmp_dict[u'开始时间'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timeperiods['start_date'])).split(' ')[1]
                        tmp_dict[u'时长(h)'] = timeperiods['period'] / 3600.0
                        tmp_dict[u'组'] = ';'.join([db.getGroup(url, group_id=k)['name'] for k in j['groupids']])
                        tmp_dict[u'主机'] = ';'.join([db.getHost(url, host_id=k)['name'] for k in j['hostids']])
                        tmp_list.append(tmp_dict)
                elif timeperiods['timeperiod_type'] == '2':
                    num += 1
                    tmp_dict['maintenancename'] = j['name']
                    tmp_dict[u'类型'] = '每天'
                    tmp_dict[u'开始时间'] = time.strftime('%H:%M:%S', time.gmtime(timeperiods['start_time']))
                    tmp_dict[u'时长(h)'] = timeperiods['period'] / 3600.0
                    tmp_dict[u'组'] = ';'.join([db.getGroup(url, group_id=k)['name'] for k in j['groupids']])
                    tmp_dict[u'主机'] = ';'.join([db.getHost(url, host_id=k)['name'] for k in j['hostids']])
                    tmp_list.append(tmp_dict)
                elif timeperiods['timeperiod_type'] == '3':
                    week = binToDec(timeperiods['dayofweek'])
                    dayofweek_list = []
                    dayofweek_list.append(str(len(week)))
                    flag = len(week)
                    for k in week[1:]:
                        flag -= 1
                        if k == '1':
                            dayofweek_list.append(str(flag))
                    #  print dayofweek_list
                    #  print todayWeek(year, month, i)
                    if str(todayWeek(year, month, i)) in dayofweek_list:
                        num += 1
                        tmp_dict['maintenancename'] = j['name']
                        tmp_dict[u'类型'] = '每周'
                        tmp_dict[u'开始时间'] = time.strftime('%H:%M:%S', time.gmtime(timeperiods['start_time']))
                        tmp_dict[u'时长(h)'] = timeperiods['period'] / 3600.0
                        tmp_dict[u'组'] = ';'.join([db.getGroup(url, group_id=k)['name'] for k in j['groupids']])
                        tmp_dict[u'主机'] = ';'.join([db.getHost(url, host_id=k)['name'] for k in j['hostids']])
                        tmp_list.append(tmp_dict)
                else:
                    pass
            else:
                continue
        month_dict['day'] = i
        month_dict['job'] = num
        month_dict['week'] = todayWeek(year, month, i)
        month_dict['weekchinese'] = CHINESE_ENGILSH[month_dict['week']]
        month_dict['maintenance'] = tmp_list
        month_list.append(month_dict)
    return month_list
예제 #11
0
파일: views.py 프로젝트: znavy/AXES
def oneHostInfoView(request, HNAME):
    url = getCookieUrl(request)
    result = db.getHost(url, host_name=HNAME)
    template_current = result['parentTemplates']
    key = ['templateid' for i in range(len(template_current))]
    value = [template['templateid'] for template in template_current]
    template_old = [{key[i]: value[i]} for i in xrange(len(key))]
    if request.method == 'POST':
        template_ids = []
        host_id = request.POST.get(u'id')
        host_name = request.POST.get(u'主机名称')
        name = request.POST.get(u'可见名称')
        group_name = request.POST.get(u'主机组')
        group = [db.getGroup(url, group_name=group_name)['groupid']]
        templates = request.POST.get(u'模板')
        if len(templates):
            templates = templates.split(',')
        else:
            templates = []
        if templates:
            for template in templates:
                template = template.strip()
                template_dict = {}
                template_info = db.getTemplate(url, template_name=template)
                template_id = template_info['templateid']
                template_dict['templateid'] = template_id
                template_ids.append(template_dict)
        status = request.POST[u'主机状态']
        if 'update' in request.POST:
            macros_key = request.POST.getlist('macro_key')
            macros_value = request.POST.getlist('macro_value')
            macro_dict = {}
            macros = []
            for i in zip(macros_key, macros_value):
                macro_dict = {}
                if len(i[0]) >= 1 and len(i[1]) >= 1:
                    macro_dict['macro'] = i[0].strip().upper()
                    macro_dict['value'] = i[1].strip()
                if macro_dict:
                    macros.append(macro_dict)
            zabbixapi.updateHost(url, host_id, name, template_old, template_ids, group, status, macros)
        elif 'del-macro' in request.POST:
            macros = []
            macros_list = result['macros']
            del_macro_list = request.REQUEST.getlist('macro_list')
            macros = [macro for macro in macros_list if macro.get('macro') not in del_macro_list]
            zabbixapi.updateHost(url, host_id, name, template_old, template_ids, group, status, macros)
        return HttpResponseRedirect(reverse('hostinfourl', args=[host_name]))
    else:
        host_dict = OrderedDict()
        template_list = []
        template_list = [template['name'] for template in result['parentTemplates']]
        host_dict[u'id'] = result['hostid']
        host_dict[u'主机名称'] = result['host']
        host_dict[u'可见名称'] = result['name']
        host_dict[u'主机组'] = result['groups'][0]['name']
        host_dict[u'模板'] = ','.join(template_list)
        host_dict[u'主机状态'] = result['status']
        item_list = zabbixapi.getItemInfo(url, host_id=result['hostid'])['result']
        macros_list = result['macros']
        macros_flag = len(macros_list)
        global_macro = zabbixapi.getGlobalMacrosInfo(url)['result']
    context_dict = {
        "global_macros": global_macro,
        'host_dict': host_dict,
        'item_list': item_list,
        'macros_list': macros_list,
        'macros_flag': macros_flag,
        'HNAME': HNAME,
        'GNAME': result['groups'][0]['name'].split('_')[0],
    }
    return render(request, 'zabbixmanage/updatehost.html', context_dict)