From b304811915d3fd4c33aa5a6cd7696b305e8ab93a Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 11 Mar 2025 07:02:13 +0000 Subject: [PATCH] Add zabbix_create_hosts.py --- zabbix_create_hosts.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 zabbix_create_hosts.py diff --git a/zabbix_create_hosts.py b/zabbix_create_hosts.py new file mode 100644 index 0000000..cd675ee --- /dev/null +++ b/zabbix_create_hosts.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 +from zabbix_utils import ZabbixAPI +from wonderwords import RandomWord +# Zabbix server details +zabbix_url = "https://student-XX-zbxtr-YYYY.zabbix.training" +api = ZabbixAPI(url=zabbix_url) +api.login(token="6c036300dbe95314dda25b408e3ade3b8042419f434700ab562f9540ff8f64f4") +# Initialize random word generator +rw = RandomWord() +def create_host(host_name): + result = api.host.create({ + "host": host_name, + "interfaces": [{ + "type": 1, + "main": 1, + "useip": 0, + "ip": "", + "dns": "training.example.com", + "port": "10050" + }], + "groups": [{ + "groupid": "2" #Linux servers + }], + "templates": [{ + "templateid": "10561" # Zabbix agent + }] + }) + return result +# Generate and create 100 hosts with random names +for _ in range(100): + word1 = rw.word() + word2 = rw.word() + host_name = f"{word1.capitalize()} {word2.capitalize()}" + result = create_host(host_name) + print(f"Created host: {host_name} - Result: {result}")