Beispiel #1
0
def _get_indexed_addresses(
    host_attrs: config.ObjectAttributes, address_family: Literal["4", "6"]
) -> Iterator[Tuple[str, str]]:
    for name, address in host_attrs.items():
        address_template = f"_ADDRESSES_{address_family}_"
        if address_template in name:
            index = name.removeprefix(address_template)
            yield f"$_HOSTADDRESSES_{address_family}_{index}$", address
Beispiel #2
0
def _get_host_address_config(
    hostname: str, host_attrs: config.ObjectAttributes
) -> HostAddressConfiguration:
    return HostAddressConfiguration(
        hostname=hostname,
        host_address=host_attrs["address"],
        alias=host_attrs["alias"],
        ipv4address=host_attrs.get("_ADDRESS_4"),
        ipv6address=host_attrs.get("_ADDRESS_6"),
        indexed_ipv4addresses=dict(_get_indexed_addresses(host_attrs, "4")),
        indexed_ipv6addresses=dict(_get_indexed_addresses(host_attrs, "6")),
    )
Beispiel #3
0
def get_host_macros_from_attributes(hostname: HostName, attrs: ObjectAttributes) -> ObjectMacros:
    macros = {
        "$HOSTNAME$": hostname,
        "$HOSTADDRESS$": attrs['address'],
        "$HOSTALIAS$": attrs['alias'],
    }

    # Add custom macros
    for macro_name, value in attrs.items():
        if macro_name[0] == '_':
            macros["$HOST" + macro_name + "$"] = value
            # Be compatible to nagios making $_HOST<VARNAME>$ out of the config _<VARNAME> configs
            macros["$_HOST" + macro_name[1:] + "$"] = value

    return macros