Esempio n. 1
0
def haha():
    from flask import jsonify
    client = ZabbixAction()
    if client.login_test():
        #return "认证成功"
        return jsonify({"result": "fss"})
    else:
        return "认证成功"
Esempio n. 2
0
def data():
    arr = {}
    import time, random
    curr_time = int(round(time.time() * 1000)) 
    
    #http://127.0.0.1:5000/zabbix_get_history/68362/5

    arr['data_1'] = [[curr_time , random.randint(0,1)]]
    arr['data_2'] = [[curr_time , random.randint(0,1)]]
    # arr['data_3'] = [[curr_time , random.randint(0,99)]]

    client = ZabbixAction()
    client.login_test()
    res = client.get_host_history(itemids="68362",limit="100")
    for i in res:
        arr['data_3'] = [[int(i["clock"]) * 1000 , float(i['value'])]]
    print arr
    return json.dumps(arr)
Esempio n. 3
0
def zabbixdel():
    if request.method == 'POST':
      server_list = []
      content = request.form['contenet'].split(',')

      print content
      for i in content:
        server_list.append(i.strip()) # i.strip() 去除多余的空格符
      if server_list[0] == '':
        flash(u'请填写至少一个或多个欲删除主机主机名!', 'danger')
        return  render_template('zabbixdel.html')
      z_del = ZabbixAction()
      z_del.login_test()
      print server_list
      z_del.delete_host(server_list)
      res = (commands.getoutput('cat /tmp/cache_delete_zabbix.txt')).decode('utf-8').split('!')
      return render_template('zabbixdel.html', result=res)
    return render_template('zabbixdel.html')
Esempio n. 4
0
def zabbixadd():
    if request.method == 'POST':
        result = request.files['file']
        #获取当前目录的位置然后通过path.join来连接上传目录
        basepath=path.abspath(path.dirname(__file__))
        upload_path = path.join(basepath,'upload')
        print upload_path
        #print '删除旧文件'
        if result.filename:
            result.save(path.join(upload_path,secure_filename(result.filename)))
            flash(u'文件上传成功 & 主机导入成功!','success')
            z_add = ZabbixAction()
            z_add.login_test()
            z_add.create_hosts(path.join(upload_path,secure_filename(result.filename)))
            res = (commands.getoutput('cat /tmp/cache_add_zabbix.txt')).decode('utf-8').split('!')
            return render_template('zabbixadd.html',result=res)
        else:
            flash(u'务必选择一个文件进行操作!', 'danger')
            return render_template('zabbixadd.html')
    return render_template('zabbixadd.html')
Esempio n. 5
0
def zabbix_get_history(itemids,limit):
      client = ZabbixAction()
      client.login_test()
      res = json.dumps(client.get_host_history(itemids,limit)) 
      return res
Esempio n. 6
0
def zabbix_get_hostitemid(hostids):
      print hostids
      client = ZabbixAction()
      client.login_test()
      return json.dumps(client.get_host_item_id(hostids)) 
Esempio n. 7
0
def zabbix_hostingruop_get(groupid):
      """获取zabbix主机组里面包含的主机,url后面直接跟组id"""
      print groupid
      host_in_group_get = ZabbixAction()
      host_in_group_get.login_test()
      return json.dumps(host_in_group_get.get_hostingroup(groupid)) 
Esempio n. 8
0
def zabbix_hostgruop_get():
        hostgroup_get = ZabbixAction()
        hostgroup_get.login_test()
        hostgroup_get.get_host()
        return json.dumps(hostgroup_get.get_hostgruop()) 
Esempio n. 9
0
def zabbix_host_get():
      print 'xxxxx'
      host_get = ZabbixAction()
      host_get.login_test()
      host_get.get_host()
      return json.dumps(host_get.get_host()) 
Esempio n. 10
0
def haha():
    client=ZabbixAction()
    if client.login_test():
      return "认证成功"
    else:
      return "认证失败"