def update_host(hostname, status):
    """Enable or disable monitoring for the host"""

    # Suppress SSL Verification check
    ssl._create_default_https_context = ssl._create_unverified_context

    server = "https://" + get_zabbix_server(hostname)
    zapi = ZabbixAPI(server)

    # Disable SSL certificate verification
    zapi.session.verify = False

    username = os.getenv("RD_CONFIG_USERNAME")
    password = os.getenv("RD_CONFIG_PASSWORD")

    # Specify a timeout (in seconds)
    zapi.timeout = 5
    zapi.login(username, password)

    try:
        hostid = zapi.host.get({
            "output": ["hostid"],
            "filter": {
                "host": [hostname]
            }
        })[0]['hostid']
    except Exception as e:
        exit(1)
    try:
        zapi.host.update({"hostid": hostid, "status": status})
    except Exception as e:
        print(e)
        exit(1)
#!/usr/bin/env python3

from zabbix_api import ZabbixAPI
from boto import ec2
import os

if all(var in os.environ
       for var in ["ZABBIX_USER", "ZABBIX_PASSWORD", "ZABBIX_URL"]):
    zapi = ZabbixAPI(server=os.environ.get('ZABBIX_URL'))
    zapi.validate_certs = False
    zapi.login(os.environ.get('ZABBIX_USER'),
               os.environ.get('ZABBIX_PASSWORD'))
    zapi.timeout = 30
else:
    raise Exception("Zabbix environment variables are not defined")

zabbix_unavailable_hosts_IPs = set()
ec2_active_instances_IPs = set()

# Get hosts with unavailable zabbix-agents (list from dicts): [{dict},]
zabbix_unavailable_hosts_ids = zapi.host.get({
    "output": ["hostid"],
    "filter": {
        "available": ["2"]
    }
})
# [{'hostid': '10280'}, ...]

# Get hosts IP-id (list from dicts): [{dict},]
zabbix_hosts_ids_IPs = zapi.hostinterface.get({"output": ["ip", "hostid"]})
# [{'hostid': '10084', 'interfaceid': '1', 'ip': '172.31.10.205'}, ...]