Exemplo n.º 1
0
def host(request):
    try:
        zapi=ZabbixAPI()
        host_list=zapi.HostGet()
        group_list=zapi.HostGroupGet()
        template_list=zapi.TemplateGet()
    except Exception as e:
        error=str(e)
    return render(request, 'ZABBIX/host.html', locals())
Exemplo n.º 2
0
def host(request):
    try:
        zapi = ZabbixAPI()  #instanse
        ###TODO ---now 操作之前是不是应该先登录zabbix?????

        host_list = zapi.HostGet()
        group_list = zapi.HostGroupGet()
        template_list = zapi.TemplateGet()
    except Exception as e:
        error = str(e)
    return render(request, 'ZABBIX/host.html', locals())
Exemplo n.º 3
0
def host(**kwargs):
    try:
        zapi=ZabbixAPI()
        host_list=zapi.HostGet()
        group_list=zapi.HostGroupGet()
        template_list=zapi.TemplateGet()
        write_log('api').info("create zabbix host  scucess" )
        return json.dumps({'code': 0,'result': {'hosts':host_list,'groups':group_list,'templates':template_list}})
    except Exception as e:
        error=str(e)
        write_log('api').error("create zabbix host error: %s" % traceback.format_exc())
        return json.dumps({'code': 1, 'errmsg': 'create zabbix host fail \n %s ' % error})
Exemplo n.º 4
0
def alert(request):
    try:
        zapi = ZabbixAPI()
        host_list = zapi.HostGet()
        group_list = zapi.HostGroupGet()
        trigger_list = zapi.TriggerGet()
        #时间戳转化成日期格式
        for trigger in trigger_list:
            trigger['lastchange'] = time.strftime(
                '%Y/%m/%d %X', time.localtime(float(trigger['lastchange'])))
    except Exception as e:
        error = str(e)
    return render(request, 'ZABBIX/alert.html', locals())
Exemplo n.º 5
0
class Main:
    def __init__(self, filename, user, password, url):
        self.hostlist = LoadCSV(filename).export()
        self.zabbix = ZabbixAPI(user, password, url)
        self.zabbix.login()

    def debug(self):
        print(self.hostlist)
        for line in self.hostlist:
            print(line['Templates'].split(','))
            print(line['Groups'])
            print(line['HostName'])
            print(line['AgentInterface'])

    def chk_ip(self, ip_str):
        sep = ip_str.split('.')
        if len(sep) != 4:
            return False
        for i, x in enumerate(sep):
            try:
                int_x = int(x)
                if int_x < 0 or int_x > 255:
                    return False
            except ValueError as e:
                return False
        return True

    def create_host(self):
        for line in self.hostlist:
            if self.chk_ip(line['AgentInterface']) is False:
                continue
            self.zabbix.get_template_id(line['Templates'].split(','))
            self.zabbix.get_group_id(line['Groups'])
            self.zabbix.create_host(line['HostName'], line['AgentInterface'])
Exemplo n.º 6
0
def host_create(request):
    name=request.GET.get('name','')
    ip=request.GET.get('ip','')
    groupid=request.GET.get('groupid','')
    templateid=request.GET.get('templateid','')
    try:
        zapi=ZabbixAPI()
        hostcreate=zapi.HostCreate(name,ip,groupid,templateid)
        if hostcreate['hostids']:
            result=u"主机%s创建成功,ID为%s."%(name,hostcreate['hostids'])
        else:
            result=u"主机%s创建失败."%(name)
    except Exception as e:
        result=str(e)
    return JsonResponse(result,safe=False)
Exemplo n.º 7
0
def graph(request):
    cf = ConfigParser.ConfigParser()
    cf.read("jumpserver/config.ini")
    graphurl = cf.get("zabbix_server", "graphurl")

    hostid = request.GET.get('hostid', '')
    try:
        zapi = ZabbixAPI()
        host_list = zapi.HostGet()
        if hostid:
            graph_list = zapi.GraphGet(hostid=hostid)
        else:
            graph_list = zapi.GraphGet()
    except Exception as e:
        error = str(e)
    return render(request, 'ZABBIX/graph.html', locals())
Exemplo n.º 8
0
def history(request):
    itemid=request.GET.get('itemid','')
    data_type=request.GET.get('data_type','0')
    print data_type
    try:
        zapi=ZabbixAPI()
        if itemid:
            value=[]
            clock=[]
            item=zapi.ItemGet(itemid=itemid)[0]
            host=zapi.HostGet(hostid=item['hostid'])[0]
            history_list=zapi.History(itemid,int(data_type))
            for history in history_list:
                value.append(float(history['value']))
                clock.append(time.strftime('%Y/%m/%d %H:%M', time.localtime(float(history['clock']))))
            print history_list
    except Exception as e:
        error=str(e)
    return render(request, 'ZABBIX/history.html', locals())
Exemplo n.º 9
0
def item(request):
    cf = ConfigParser.ConfigParser()
    cf.read("EWP_OMS/config.ini")
    itemurl = cf.get("zabbix_server","itemurl")

    hostid=request.GET.get('hostid','')
    try:
        zapi=ZabbixAPI()
        host_list=zapi.HostGet()
        if hostid:
            item_list=zapi.ItemGet(hostid=hostid)
        else:
            item_list=zapi.ItemGet()
        #时间戳转化成日期格式
        for item in item_list:
            item['lastclock']= time.strftime('%Y/%m/%d %H:%M', time.localtime(float(item['lastclock'])))
    except Exception as e:
        error=str(e)
    return render(request, 'ZABBIX/item.html', locals())
Exemplo n.º 10
0
 def __init__(self, filename, user, password, url):
     self.hostlist = LoadCSV(filename).export()
     self.zabbix = ZabbixAPI(user, password, url)
     self.zabbix.login()