通过API自动增加Zabbix监控主机
2021-01-20 19:11
标签:request save int ofo ace 扩容 agentd pre 监控 新增接口前需要做个登录,拿到登录的token,然后拿到这个token,再去添加服务器。脚本如下: 通过API自动增加Zabbix监控主机 标签:request save int ofo ace 扩容 agentd pre 监控 原文地址:https://blog.51cto.com/fengwan/2463504#!/bin/bash
hostname=‘192.168.0.219‘ #被监控主机名称
ip=‘192.168.0.219‘ #被监控主机IP
port=10050 #被监控主机zabbix_agentd端口
templateid=10001 #模板ID
groupid=2 #需要加入的服务器组
zabbixhost=‘http://www.zabbix.com‘ #zabbix主机地址
header=‘Content-Type:application/json‘
request_data=‘{"jsonrpc" : "2.0","method" : "user.login","params" : {"user" : "admin" ,"password" : "zabbix"} ,"id" : 1 }‘
result=$(curl -s -XPOST -H ${header} -d "${request_data}" ${zabbixhost}/api_jsonrpc.php)
token=$(echo $result|sed ‘s/.\+"result":"\([0-9a-z]\+\)".\+/\1/‘)
save_request_data=‘{"jsonrpc": "2.0","method": "host.create","params": {"host": "‘${hostname}‘","interfaces": [{"type": 1,"main": 1,"useip": 1,"ip": "‘${ip}‘","dns": "","port": "‘${port}‘"}],"groups": [{"groupid": "‘${groupid}‘"}],"templates": [{"templateid": "‘${templateid}‘"}]},"auth": "‘${token}‘","id": 1 }‘
curl -s -XPOST -H ${header} -d "${save_request_data}" ${zabbixhost}/api_jsonrpc.php
下一篇:WPF实现大数据分析
文章标题:通过API自动增加Zabbix监控主机
文章链接:http://soscw.com/index.php/essay/44662.html