Пример #1
0
def generate_hosts(hosts_file=DEFAULT_HOSTS_FILE):

    host_list = parse_hosts_file(hosts_file)[1]
    group_names = ["cloud_vms"]

    root = zxml.root()

    for group_name in group_names:
        root.find("groups").append(zxml.group(group_name))

    for host_ip in host_list:
        host_name = host_list[host_ip]

        # Determine the Zabbix template type by removing the numbers from
        # the hostname.
        base_name = re.split(r'(\d+)', host_name)[0]
        template = "cloud_vm_" + base_name

        # Skip cloud* nodes since they are already monitored.
        if base_name == "cloud":
            continue

        root.find("hosts").append(
            zxml.host(hostname=host_name,
                      ip=host_ip,
                      templates=["cloud_vm_base", template],
                      groups=["cloud_vms"]))

    return etree.ElementTree(root)
Пример #2
0
def generate_hosts(hosts_file=DEFAULT_HOSTS_FILE):

    host_list = parse_hosts_file(hosts_file)[1]
    group_names = ["cloud_vms"]

    root = zxml.root()

    for group_name in group_names:
        root.find("groups").append(zxml.group(group_name))

    for host_ip in host_list:
        host_name = host_list[host_ip]

        # Determine the Zabbix template type by removing the numbers from
        # the hostname.
        base_name = re.split(r"(\d+)", host_name)[0]
        template = "cloud_vm_" + base_name

        # Skip cloud* nodes since they are already monitored.
        if base_name == "cloud":
            continue

        root.find("hosts").append(
            zxml.host(hostname=host_name, ip=host_ip, templates=["cloud_vm_base", template], groups=["cloud_vms"])
        )

    return etree.ElementTree(root)
Пример #3
0
def load_hosts(hosts_file=DEFAULT_HOSTS_FILE):
    hosts = dict()

    for (name, addresses) in parse_hosts_file(hosts_file)[0].iteritems():
        if len(addresses) == 1:
            hosts[name] = addresses[0]

    return hosts
Пример #4
0
def load_hosts(hosts_file=DEFAULT_HOSTS_FILE):
    hosts = dict()

    for (name, addresses) in parse_hosts_file(hosts_file)[0].iteritems():
        if len(addresses) == 1:
            hosts[name] = addresses[0]

    return hosts