Zabbix分布式监控

Posted minseo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zabbix分布式监控相关的知识,希望对你有一定的参考价值。

  上一篇:Zabbix低级主动发现之MySQL多实例

  

  登录请求(返回一个token,在后面的api中需要用到)

curl -s -X POST -H \'Content-Type:application/json\' -d\'
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "zabbix"
        
    },
    "id": 1
}\' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool


{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "940da948f7aabb512d71c13ced76699a"
}

  

  host get

curl -s -X POST -H \'Content-Type:application/json\' -d\'
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output":["host"]
    },
    
    "auth": "940da948f7aabb512d71c13ced76699a",
    "id": 1
}\' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool


{
    "id": 1,
    "jsonrpc": "2.0",
    "result": [
        {
            "host": "Zabbix server",
            "hostid": "10084"
        },
        {
            "host": "linux-node2.example.com",
            "hostid": "10117"
        }
    ]
}

  获取到了host和hostid  怎么查看

  添加主机的api

  修改配置

  修改了ip groupid 和templateid(删除了官方的资产信息)

curl -s -X POST -H \'Content-Type:application/json\' -d\'
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "Linux server",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "192.168.80.160",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "templates": [
            {
                "templateid": "10001"
            }
        ]
    },
    "auth": "940da948f7aabb512d71c13ced76699a",
    "id": 1
}\' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool

 

  添加成功

  

  创建主机api的应用脚本批量添加主机(list.txt写好需要添加主机的ip列表)

  zabbix_host_creates.sh

#!/bin/bash
#login
tok=`curl -s -X POST -H \'Content-Type:application/json\' -d\'
{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "zabbix"
        
    },
    "id": 1
}\' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool`
jsson= echo "$tok" | grep result | awk -F \'"\' \'{print $4}\'
#create hosts
for ip in `cat list.txt` 
do
curl -s -X POST -H \'Content-Type:application/json\' -d\'
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": \'\\"$ip\\"\',
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": \'\\"$ip\\"\',
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "11"
            }
        ],
        "templates": [
            {
                "templateid": "10001"
            }
        ]
    },
    "auth": \'\\"$jsson\\"\',
    "id": 1
}\' http://192.168.80.130/zabbix/api_jsonrpc.php | python -m json.tool
done

  运行报错了

 

  下一篇:Zabbix分布式监控

  

  

以上是关于Zabbix分布式监控的主要内容,如果未能解决你的问题,请参考以下文章

Zabbix监控之分布式监控zabbix_proxy

zabbix概念

zabbix监控nginxmysqljava应用Zabbix + proxy分布式

zabbix监控nginx监控mysql数据库监控java应用Zabbix + proxy分布式

zabbix分布式监控与SNMP监控

分布式监控系统Zabbix-3.0.3-完整安装记录-解决zabbix监控图中出现中文乱码问题