Operations 7 min read

Automate Weather Monitoring in Zabbix: HTTP Agent, Preprocessing, and Dynamic Map Visualization

Learn how to set up Zabbix HTTP agent monitoring for weather data, create dependent items with JSON preprocessing, automate batch addition for multiple cities using Python, and visualize alerts on a dynamic map with custom triggers and graphics.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Automate Weather Monitoring in Zabbix: HTTP Agent, Preprocessing, and Dynamic Map Visualization

Overview

This article demonstrates how to use Zabbix's HTTP agent to monitor weather data from the YY Weather API, create dependent items with JSON preprocessing, add triggers for high temperature, and visualize the results on a map.

Creating HTTP Agent Items

Steps to create a HTTP agent item for Beijing weather by filling the request URL and key fields.

Adding Preprocessing and Dependent Items

Shows how to add preprocessing to extract temperature (tq), wind (fl), humidity (qw), and pressure (sd) from the JSON response, then create dependent items that reference the original HTTP item.

Batch Script for Multiple Cities

A Python script logs into the Zabbix API, retrieves the host interface ID, iterates over a list of city codes, creates HTTP items, dependent items, and triggers for each city, reducing repetitive manual work.

<code>#coding=utf-8
import requests,json
ApiUrl='http://192.168.99.200/api_jsonrpc.php'
header={"Content-Type":"application/json"}
user="Admin"
password="zabbix"
city=[{"beijing":"CH010100"},{"shanghai":"CH020100"},{"tianjin":"CH030100"},{"chongqing":"CH040100"},{"harebin":"CH050101"},{"changchun":"CH060101"},{"shenyang":"CH070101"},{"huhehaote":"CH080101"},{"shijiazhuang":"CH090101"},{"taiyuan":"CH100101"},{"xian":"CH110101"},{"jinan":"CH120101"},{"wulumuqi":"CH130101"},{"lasa":"CH140101"},{"xining":"CH150101"},{"lanzhou":"CH160101"},{"yinchuan":"CH170101"},{"zhengzhou":"CH180101"},{"nanjing":"CH190101"},{"wuhan":"CH200101"},{"hangzhou":"CH210101"},{"hefei":"CH220101"},{"fuzhou":"CH230101"},{"nanchang":"CH240101"},{"changsha":"CH250101"},{"guiyang":"CH260101"},{"chengdu":"CH270101"},{"guangzhou":"CH280101"},{"kunming":"CH290101"},{"nanning":"CH300101"},{"haikou":"CH310101"},{"hongkong":"CH320101"},{"aomen":"CH330101"},{"taibei":"CH340101"}]

def get_interface(auth):
    data={"jsonrpc":"2.0","method":"hostinterface.get","params":{"output":"extend","hostids":"10343"},"auth":auth,"id":1}
    gethost=requests.post(url=ApiUrl,headers=header,json=data)
    return json.loads(gethost.content)["result"][0]["interfaceid"]

def gettoken():
    data={"jsonrpc":"2.0","method":"user.login","params":{"user":user,"password":password},"id":1,"auth":None}
    auth=requests.post(url=ApiUrl,headers=header,json=data)
    return json.loads(auth.content)["result"]

def createhttpitem(auth,interface):
    for dic in city:
        for key,value in dic.items():
            data={"jsonrpc":"2.0","method":"item.create","params":{"url":"http://api.yytianqi.com/observe","query_fields":[{"city":"%s"%value},{"key":"iopesm5a0uhq3fag"}],"interfaceid":"%s"%interface,"type":"19","hostid":"10343","delay":"5m","key_":"%s"%key,"name":"%s"%key,"value_type":"1","output_format":"0","timeout":"3s"},"auth":auth,"id":1}
            httpagent=requests.post(url=ApiUrl,headers=header,json=data)
            httpagent=json.loads(httpagent.content)['result']['itemids'][0]
            # create dependent items (temperature, wind, humidity, pressure) and triggers – omitted for brevity

auth=gettoken()
interface=get_interface(auth)
createhttpitem(auth,interface)
</code>

Map Creation and Editing

Upload a background image of China, add map elements, and configure tags to display monitored data; high‑temperature triggers cause the map point to flash red/green.

Result

Screenshots show the map with data points and the alarm animation.

PythonautomationMap visualizationZabbixWeather APIHTTP monitoring
Ops Development Stories
Written by

Ops Development Stories

Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.