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_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