コード例 #1
0
ファイル: views.py プロジェクト: beli-sk/syrup
def main(request):
    za = ZabbixAPI()
    za.login()
    try:
        groups = za.list_groups()
    except:
        groups = None
    return render_to_response('zabsync/main.html', {
            'groups': groups,
            'primary_templates': Node.list_primary_templates(),
            'templates': Node.objects.filter(typ=0),
            },context_instance=RequestContext(request))
コード例 #2
0
def main(request):
    za = ZabbixAPI()
    za.login()
    try:
        groups = za.list_groups()
    except:
        groups = None
    return render_to_response(
        'zabsync/main.html', {
            'groups': groups,
            'primary_templates': Node.list_primary_templates(),
            'templates': Node.objects.filter(typ=0),
        },
        context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: beli-sk/syrup
def add_hosts_by_group(request):
    groups = request.GET.getlist('group')
    template_id = int(request.GET.get('template_id'))
    subtemplate_id = int(request.GET.get('subtemplate_id'))
    template = Node.objects.get(id = template_id)
    subtemplate = Node.objects.get(id = subtemplate_id) if subtemplate_id >= 0 else None
    za = ZabbixAPI()
    za.login()
    hosts = za.hosts_by_group(groups)
    for host in hosts:
        try:
            node = utils.create_host(template, host['host'], host['hostid'], subtemplate)
        except exceptions.DuplicateItemError:
            node = Node.objects.get(paramstr__name = 'zabbix_id', paramstr__value = host['hostid'])
        utils.update_host_inv(za, node)
    return render_to_response('zabsync/add_hosts.html', {
            'hosts': hosts,
            'debug': repr(hosts)
            },context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: beli-sk/breeze2
def trigger_detail(request):
    tid = int(request.GET.get('triggerid'))
    res = HttpResponse()
    res.write("triggerid: %d<br>\n" % tid)
    za = ZabbixAPI()
    za.login()
    triggers = za.triggers([tid])
    events = za.last_events(tid)
    t = triggers[0]
    # fix data for presentation
    t['lastchange_dt'] = datetime.fromtimestamp(float(t['lastchange']))
    t['value_desc'] = decode_trigger_value(t['value'])
    for e in events:
        e['clock_dt'] = datetime.fromtimestamp(float(e['clock']))
        e['value_desc'] = decode_trigger_value(e['value'])
    return render(request, 'zabbixlink/trigger_detail.html', {
        'triggerid': tid,
        'trigger': t,
        'events': events,
        'debug': pformat(triggers, 2)+"\n---\n"+pformat(events, 2),
    })
コード例 #5
0
def add_hosts_by_group(request):
    groups = request.GET.getlist('group')
    template_id = int(request.GET.get('template_id'))
    subtemplate_id = int(request.GET.get('subtemplate_id'))
    template = Node.objects.get(id=template_id)
    subtemplate = Node.objects.get(
        id=subtemplate_id) if subtemplate_id >= 0 else None
    za = ZabbixAPI()
    za.login()
    hosts = za.hosts_by_group(groups)
    for host in hosts:
        try:
            node = utils.create_host(template, host['host'], host['hostid'],
                                     subtemplate)
        except exceptions.DuplicateItemError:
            node = Node.objects.get(paramstr__name='zabbix_id',
                                    paramstr__value=host['hostid'])
        utils.update_host_inv(za, node)
    return render_to_response('zabsync/add_hosts.html', {
        'hosts': hosts,
        'debug': repr(hosts)
    },
                              context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: lixianwen/cmdbdemo
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render
from django.contrib.auth.decorators import permission_required
from django.urls import reverse
from django.http import HttpResponseRedirect
from django.contrib import messages
from zabbixapi import ZabbixAPI
from forms import AddForm

zabbixAPI = ZabbixAPI()


def add(request):
    if request.method == 'POST':
        form = AddForm(request.POST)
        if form.is_valid():
            hostname = form.cleaned_data['hostname']
            asset = form.cleaned_data['ip']
            group_id = form.cleaned_data['group_id']
            template_id = form.cleaned_data['template_id']
            if asset.ip:
                ip = asset.ip
            elif asset.other_ip:
                ip = asset.other_ip
            else:
                ip = '127.0.0.1'
            if asset.asset_type in [2, 3]:
                returns = zabbixAPI.addSnmpDevice(hostname, ip, group_id,
                                                  template_id)
コード例 #7
0
ファイル: forms.py プロジェクト: sepmoon/cmdbdemo
#!/usr/bin/env python
#coding:utf8

from django import forms
from asset.models import Asset
from zabbixapi import ZabbixAPI
from cmdb.utils import AddClass

zabbixApi = ZabbixAPI()


def getGroupid():
    response = zabbixApi.getHostGroupID()
    groupid_list = list()
    for i in response:
        groupid_list.append((int(i['groupid']), i['name']))
    return groupid_list


def getTemplateid():
    response = zabbixApi.getTemplateID()
    template_list = list()
    for i in response:
        template_list.append((int(i['templateid']), i['name']))
    return template_list


def getHostid():
    response = zabbixApi.getHostID()
    host_list = list()
    for i in response: