Zabbix API: adding devices with a script
Sign in to read this lesson
Ten hosts can be added by hand, a hundred cannot. In this lesson we learn how the Zabbix API works, how API access is opened in 8.0, how to create a token, how to find group and template IDs with curl, how to add a host with an SNMP v2c or v3 interface through host.create, and a small script that adds hosts in bulk from a CSV file.
What you will learn
- API address:
http://10.10.10.20/zabbix/api_jsonrpc.php, format JSON-RPC 2.0, headersContent-Type: application/json-rpcandAuthorization: Bearer <token>. - In a new Zabbix 8.0 installation API access is disabled for roles: create a separate role (Access to API: Enabled, only the methods that are needed), a user and an API token.
- IDs are found by name:
hostgroup.get(groupid),template.get(templateid); thenhost.create. - Interface:
type1 Agent, 2 SNMP; for SNMP thedetails:version2 andcommunity, orversion3,securityname,securitylevel2,authprotocol,privprotocoland the passphrases. - We do not write the token inside the script: we keep it in a file with
600permissions or in an environment variable, and give it an expiry date.
The lesson has 5 key points, an explanation and 5 questions. It opens with a package.