Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Automatically add Zabbix monitoring host through API

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The company initializes the expansion server automatically through script, but there is a problem. After the expansion, zabbix cannot automatically add the host to the server, and it needs to be added manually, so it is slow and error-prone, so it wants to add host monitoring automatically through API. You can solve this problem by looking at the interface. Https://www.zabbix.com/documentation/4.0/zh/manual/api

Before adding an API, you need to log in, get the login token, then get the token, and then add the server. The script is as follows:

#! / bin/bashhostname='192.168.0.219' # monitored host name ip='192.168.0.219' # monitored host IPport=10050 # monitored host zabbix_agentd port templateid=10001 # template IDgroupid=2 # server group zabbixhost=' http://www to join .zabbix.com'# zabbix host address 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.\ + "result": "([0-9a-z]\ +\)" 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report