import requests
import json
from concurrent.futures import ThreadPoolExecutor

ZABBIX_URL = "http://{your_host}/{branch}/api_jsonrpc.php"

HOST_IDS_TO_DELETE = ["10771","10772"]

#master
headers = {"Authorization": "Bearer {put_your_token_here}"}

# === host.delete  ===
def delete_host(hostid):
    payload = {
        "jsonrpc": "2.0",
        "method": "host.delete",
        "params": [hostid],
        "id": 1
    }
    try:
        response = requests.post(ZABBIX_URL, json=payload, headers=headers)
        result = response.json()
        if "result" in result:
            print(f"[OK] Host {hostid} deleted: {result['result']}")
        else:
            print(f"[ERROR] Host {hostid} delete failed: {result.get('error')}")
    except Exception as e:
        print(f"[EXCEPTION] Host {hostid}: {e}")

def delete_hosts_parallel(host_ids, max_workers=2):
    with ThreadPoolExecutor(max_workers=max_workers) as executor:
        futures = [executor.submit(delete_host, hostid) for hostid in host_ids]
        for future in futures:
            future.result() 

if __name__ == "__main__":
    delete_hosts_parallel(HOST_IDS_TO_DELETE, max_workers=2)
