您的位置:1010cc时时彩经典版 > 操作系统 > 1010cc时时彩经典版:Zabbix API与PHP的配置

1010cc时时彩经典版:Zabbix API与PHP的配置

发布时间:2019-08-08 08:50编辑:操作系统浏览(116)

                  'method': 'template.get',

    因为这段日子加多screen的急需比相当多,就大约写了多少个python脚本用来自动化增加screen,风乐趣的可以借鉴下。

            quit()

    CentOS 7 下 Zabbix 3.0装置详解 http://www.linuxidc.com/Linux/2017-03/141716.htm

    因为前段时间增加screen的必要比较多,就大约写了贰个python脚本用来自动化增多screen,有意思味的能够借鉴下。

        auth = authenticate(url, username, password)

    Ubuntu 16.04安装配置监督体系Zabbix2.4  http://www.linuxidc.com/Linux/2017-03/141436.htm

            vsize = len(graphids) / columns

    利用办法:

                graphs.append(i['graphid'])

                      'password': password

    Zabbix监察和控制装置配置及警报配置  http://www.linuxidc.com/Linux/2017-03/141611.htm

    现实的脚本:

    64位CentOS 6.2下安装Zabbix 2.0.6   http://www.linuxidc.com/Linux/2014-11/109541.htm

            selecttype = ['graphid']

        #id_list = [{"templateid":'10843'},{"templateid":"10554"},{"templateid":"10467"},{"templateid":"10560"},{"templateid":"10566"},{"templateid":"10105"}]

    #!/usr/bin/env python
    import urllib2
    import sys
    import json
    import argparse
    def requestJason(url,values):
        data = json.dumps(values)
        req = urllib2.Request(url, data, {'Content-Type': 'application/json-rpc'})
        response = urllib2.urlopen(req, data)
        data_get = response.read()
        output = json.loads(data_get)
        print output
        try:
            message = output['result']
        except:
            message = output['error']['data']
            quit()
        print json.dumps(message) 
        return output
               
    def authenticate(url, username, password):
        values = {'jsonrpc': '2.0',
                  'method': 'user.login',
                  'params': {
                      'user': username,
                      'password': password
                  },
                  'id': '0'
                  }
        idvalue = requestJason(url,values)
        return idvalue['result']
    def getHosts(hostname,url,auth):
        host_list = []
        values = {'jsonrpc': '2.0',
                  'method': 'host.get',
                  'params': {
                      'output': ["hostid","host"],
                      'filter': {
                          'host': hostname
                      }
                  },
                  'auth': auth,
                  'id': '2'
                  }
        output = requestJason(url,values)
        for host in output['result']:
            host_list.append(host['hostid'])
        return host_list
    def getGraphs(host_list,name_list, url, auth, columns, graphtype=0 ,dynamic=0):
        if (graphtype == 0):
            selecttype = ['graphid']
            select = 'selectGraphs'
        if (graphtype == 1):
            selecttype = ['itemid', 'value_type']
            select = 'selectItems'
        values = ({'jsonrpc': '2.0',
                "method": "graph.get",
                "params": {
                    select: [selecttype,"name"],
                    "output": ["graphid","name"],
                    "hostids": host_list,                   
                    "filter":{'name':name_list},
                    "sortfield":"name",
                },
                "auth": auth,
                "id": '3'
            })
        print values
        output = requestJason(url,values)
        bb = sorted(output['result'],key = lambda x:x['hosts'][0]['hostid'])
        output['result'] = bb
        graphs = []
        if (graphtype == 0):
            for i in output['result']:
                print i
                graphs.append(i['graphid'])
        if (graphtype == 1):
            for i in output['result']:
                if int(i['value_type']) in (0, 3):
                    graphs.append(i['itemid'])
        graph_list = []
        x = 0
        y = 0
        print graphs
        for graph in graphs:
            print "x is " str(x)
            print "y is " str(y)
            graph_list.append({
                "resourcetype": graphtype,
                "resourceid": graph,
                "width": "500",
                "height": "100",
                "x": str(x),
                "y": str(y),
                "colspan": "0",
                "rowspan": "0",
                "elements": "0",
                "valign": "0",
                "halign": "0",
                "style": "0",
                "url": "",
                "dynamic": str(dynamic)
            })
            x = 1
            print type(x)
            print type(columns)
            if x == int(columns):
                x = 0
                y = 1
        print graph_list
        return graph_list
    def screenCreate(url, auth, screen_name, graphids, columns):
        columns = int(columns)
        if len(graphids) % columns == 0:
            vsize = len(graphids) / columns
        else:
            vsize = (len(graphids) / columns) 1
        values = {"jsonrpc": "2.0",
                  "method": "screen.create",
                  "params": [{
                      "name": screen_name,
                      "hsize": columns,
                      "vsize": vsize,
                      "screenitems": []
                  }],
                  "auth": auth,
                  "id": 2
                  }
        for i in graphids:
            values['params'][0]['screenitems'].append(i)
        output = requestJason(url,values)
    def main():
        url = ''
        username = 'xxxx'
        password = 'xxxx'
        auth = authenticate(url, username, password)
        host_list = getHosts(hostname,url,auth)
        print host_list
        graph_ids = getGraphs(host_list,graphname, url, auth, columns)
        screenCreate(url, auth, screenname, graph_ids, columns)
    if __name__ == '__main__':
        parser = argparse.ArgumentParser(description='Create Zabbix screen from all of a host Items or Graphs.')
        parser.add_argument('-G', dest='graphname', nargs=' ',metavar=('grah name'),
                            help='Zabbix Host Graph to create screen from')
        parser.add_argument('-H', dest='hostname', nargs=' ',metavar=('10.19.111.145'),
                            help='Zabbix Host to create screen from')
        parser.add_argument('-n', dest='screenname', type=str,
                            help='Screen name in Zabbix.  Put quotes around it if you want spaces in the name.')
        parser.add_argument('-c', dest='columns', type=int,
                            help='number of columns in the screen')
        args = parser.parse_args()
        print args
        hostname = args.hostname
        screenname = args.screenname
        columns = args.columns
        graphname = args.graphname
        if columns is None:
            columns = len(graphname)
        print columns
        main()

        graph_ids = getGraphs(host_list,graphname, url, auth, columns)

    局地Zabbix相关学科群集

                "params": {

        id_list = []

    具体的台本:

            columns = len(graphname)

    CentOS 7 LNMP情形搭建Zabbix3.0  http://www.linuxidc.com/Linux/2017-02/140134.htm

    《安装配备布满式监察和控制系列Zabbix 2.06》

            message = output['result']

    zabbix之所以能形成相比完美的监察工具,个人以为是因为两特性状:多个是数量的存放方式,方便做多少管理,容积规划,归档等,那个以前说过。另叁个是其精锐的api,利用其api可以平价的和其它的零件实行整合,比方cmdb能够透过zabbix api来落到实处监察和控制的充分,更新和剥夺等,zabbix的合英文书档案提供了比较详细的api列表。

    import urllib2

    Zabbix监察和控制装置配备及警报配置  http://www.linuxidc.com/Linux/2017-03/141611.htm

        values = {"jsonrpc": "2.0",

            quit()

    python ./screen_host.py  -H 主机列表 -n screen名称 -G graph名称

                  'method': 'host.get',

    python create_screen.py -g servers -G 'Network traffic on em1' -c 4 -n 'servers Network traffic on em1'

                            help='Zabbix Host Graph to create screen from')

    if __name__ == '__main__':

    1010cc时时彩经典版 1

    CentOS 6.3下Zabbix监控apache server-status http://www.linuxidc.com/Linux/2013-05/84740.htm

    1010cc时时彩经典版 2

        if columns is None:

        changeTemplate(idx,id_list,url,auth)

    Ubuntu 16.04下安装配置Zabbix3.0  http://www.linuxidc.com/Linux/2017-02/140395.htm

            x = 1

    剧本如下:适用于v2.2.11

                  'method': 'user.login',

        print json.dumps(message) 

    Ubuntu 14.04下Zabbix2.4.5 源码编写翻译安装  http://www.linuxidc.com/Linux/2015-05/117657.htm

                      }

    CentOS 6.3下Zabbix监控apache server-status http://www.linuxidc.com/Linux/2013-05/84740.htm

        if len(graphids) % columns == 0:

                  'params': {

    CentOS 7 下 Zabbix 3.0安装详解 http://www.linuxidc.com/Linux/2017-03/141716.htm

        host_list = getHosts(hostname,url,auth)

    import json
    import urllib2
    import argparse
     
    def requestjson(url, values):
        data = json.dumps(values)
        req = urllib2.Request(url, data, {'Content-Type': 'application/json-rpc'})
        res = urllib2.urlopen(req, data)
        output = json.loads(res.read())
     
        return output
     
    def authenticate(url, username, password):
        values = {'jsonrpc': '2.0',
                  'method': 'user.login',
                  'params': {
                      'user': username,
                      'password': password
                  },
                  'id': '0'
        }
        output = requestjson(url, values)
     
        return output['result']
     
    def gethosts(groupname, url, auth):
        host_list = []
        values = {'jsonrpc': '2.0',
                  'method': 'hostgroup.get',
                  'params': {
                      'output': 'extend',
                      'filter': {'name': groupname},
                      'selectHosts': ['hostid']
                  },
                  'auth': auth,
                  'id': '2'
        }
        output = requestjson(url, values)
        for host in output['result'][0]['hosts']:
            host_list.append(host['hostid'])
     
        return host_list
     
    def getgraphs(host_list, name_list, url, auth, columns, graphtype=0, dynamic=0):
        if (graphtype == 0):
            selecttype = ['graphid']
            select = 'selectGraphs'
        if (graphtype == 1):
            selecttype = ['itemid', 'value_type']
            select = 'selectItems'
     
        values = ({'jsonrpc': '2.0',
                  'method': 'graph.get',
                  'params': {
                      select: [selecttype, 'name'],
                      'output': ['graphid', 'name'],
                      'hostids': host_list,
                      'filter': {'name': name_list},
                      'sortfield': 'name'
                  },
                  'auth': auth,
                  'id': '3'
                  })
     
        output = requestjson(url, values)
        bb = sorted(output['result'])
     
        graphs = []
        if (graphtype == 0):
            for i in bb:
                graphs.append(i['graphid'])
        if (graphtype == 1):
            for i in bb:
                if int(i['value_type']) in (0, 3):
                    graphs.append(i['itemid'])
     
        graph_list = []
        x = 0
        y = 0
        for graph in graphs:
            graph_list.append({
                'resourcetype': graphtype,
                'resourceid': graph,
                'width': '300',
                'height': '100',
                'x': str(x),
                'y': str(y),
                'colspan': '0',
                'rowspan': '0',
                'elements': '0',
                'valign': '0',
                'halign': '0',
                'style': '0',
                'url': '',
                'dynamic': str(dynamic)
            })
            x = 1
            if x == int(columns):
                x = 0
                y = 1
     
        return graph_list
     
    def screencreate(url, auth, screen_name, graphids, columns):
        columns = int(columns)
        if len(graphids) % columns == 0:
            vsize = len(graphids) / columns
        else:
            vsize = (len(graphids) / columns) 1
     
        values = {'jsonrpc': '2.0',
                  'method': 'screen.create',
                  'params': [{
                      'name': screen_name,
                      'hsize': columns,
                      'vsize': vsize,
                      'screenitems': []
                  }],
                  'auth': auth,
                  'id': 2
                  }
        for i in graphids:
            values['params'][0]['screenitems'].append(i)
        output = requestjson(url, values)
     
    def main():
        url = ''
        username = 'admin'
        password = '__Q&(0sH1zNAdD'
        auth = authenticate(url, username, password)
        host_list = gethosts(groupname, url, auth)
        graph_ids = getgraphs(host_list, graphname, url, auth, columns)
        screencreate(url, auth, screen_name, graph_ids, columns)
     
    if __name__ == '__main__':
        parser = argparse.ArgumentParser()
        parser.add_argument('-g', dest='groupname', nargs=' ', metavar='groupname', type=str, help='which group you want to select')
        parser.add_argument('-G', dest='graphname', nargs=' ', metavar='graphname', type=str, help='which graph you want to select')
        parser.add_argument('-c', dest='columns', metavar='columns', type=int, help='the screen columns')
        parser.add_argument('-n', dest='screen_name', metavar='screen_name', type=str, help='the screen name')
        args = parser.parse_args()
     
        groupname = args.groupname
        graphname = args.graphname
        columns = args.columns
        screen_name = args.screen_name
     
        main()

        hostname = args.hostname

        values = {'jsonrpc': '2.0',

    选拔办法如下:

                "width": "500",

    不帮衬3.x本子的缓和情势见 http://www.linuxidc.com/Linux/2017-03/141926.htm

        print json.dumps(message) 

                      'user': username,

    CentOS 6.3下Zabbix监控apache server-status http://www.linuxidc.com/Linux/2013-05/84740.htm

                "method": "graph.get",

    正文永世更新链接地址:http://www.linuxidc.com/Linux/2017-03/141925.htm

            vsize = (len(graphids) / columns) 1

    回过头来看那一个题目:

    ZABBIX 的详实介绍:请点这里
    ZABBIX 的下载地址:请点这里

                      "hsize": columns,

    Ubuntu 14.04下Zabbix2.4.5 源码编写翻译安装  http://www.linuxidc.com/Linux/2015-05/117657.htm

        graph_ids = getGraphs(host_list,graphname, url, auth, columns)

    ZABBIX 的事无巨细介绍:请点这里
    ZABBIX 的下载地址:请点这里

    正文恒久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141922.htm

            if x == int(columns):

    Ubuntu 16.04下安装配置Zabbix3.0  http://www.linuxidc.com/Linux/2017-02/140395.htm

    python ./screen_host.py  -H 主机列表 -n screen名称 -G graph名称

                      'filter': {

    局地Zabbix相关学科集合

    #!/usr/bin/env python

    Ubuntu 16.04设置配置监督系统Zabbix2.4  http://www.linuxidc.com/Linux/2017-03/141436.htm

                "width": "500",

    CentOS 6.3下Zabbix安装安排 http://www.linuxidc.com/Linux/2013-05/83786.htm

    CentOS 7 LNMP情形搭建Zabbix3.0  http://www.linuxidc.com/Linux/2017-02/140134.htm

    import sys

    ZABBIX 的事无巨细介绍:请点这里
    ZABBIX 的下载地址:请点这里

        print graph_list

        output = json.loads(data_get)

    64位CentOS 6.2下安装Zabbix 2.0.6   http://www.linuxidc.com/Linux/2014-11/109541.htm

                "auth": auth,

    zabbix的screen作用能够把graph聚合起来,统一开始展览浮现,大家的要求是把同多少个主机组的同八个item聚合起来,比如三个screen显示同四个组的富有主机的内存使用率,达到近似ganglia的作用,由于服务器很多,所以我们调用zabbix api来开始展览创办。

        password = 'xxxx'

                  'params': {

        print graphs

        output['result'] = bb

        print output['result'][0]['hostid']

                    "output": ["graphid","name"],

                      'password': password

    import json

    python ./screen_host.py  -H 主机列表 -n screen名称 -G graph名称

            vsize = len(graphids) / columns

        data_get = response.read()

                  'id': '0'

                "auth": auth,

    测量试验脚本

        parser.add_argument('-n', dest='screenname', type=str,

        data_get = response.read()

                  'auth': auth,

                x = 0

        columns = args.columns

    Zabbix遍布式监察和控制种类实践 http://www.linuxidc.com/Linux/2013-06/85758.htm

        print args

                    "output": ["graphid","name"],

        print output

    def getHosts(hostname,url,auth):

        output = json.loads(data_get)

    urllib2.HTTPError: HTTP Error 500: Internal Server Error

        auth = authenticate(url, username, password)

                      "name": screen_name,

                          'host': hostname

                            help='Zabbix Host Graph to create screen from')

                    "sortfield":"name",

    def requestJason(url,values):

                "url": "",

        if (graphtype == 1):

        return output

    def requestJason(url,values):

    CentOS 6.3下Zabbix安装配置

                      'output': "extend",

        graph_list = []

                "y": str(y),

        hostname = "linuxidc_Template_OS_Linux_Hadoop_Datanode_Pro"

    def authenticate(url, username, password):

        parser = argparse.ArgumentParser(description='Create Zabbix screen from all of a host Items or Graphs.')

    CentOS 6.3下Zabbix监察和控制MySQL数据库参数 http://www.linuxidc.com/Linux/2013-05/84800.htm

            })

    if __name__ == '__main__':

    编写推荐:

    连带阅读:

                "height": "100",

    zabbix分歧于一般的线上利用,在调用api做立异时,是二个batch的行为,对内部存款和储蓄器和实行时间有早晚的渴求。

            for i in output['result']:

        for graph in graphs:

    本文由1010cc时时彩经典版发布于操作系统,转载请注明出处:1010cc时时彩经典版:Zabbix API与PHP的配置

    关键词:

上一篇:VIP安装配置,04下搭建MySQL主从服务器

下一篇:没有了