Пример #1
0
def host_context(host_name: HostName, *, write_state: bool):
    """Make a bit of context information globally available

    So that functions called by checks know this context.
    This is used for both legacy and agent_based API.
    """
    # TODO: this is a mixture of legacy and new Check-API mechanisms. Clean this up!
    try:
        check_api_utils.set_hostname(host_name)
        item_state.load(host_name)
        yield
    finally:
        check_api_utils.reset_hostname()
        if write_state:
            item_state.save(host_name)
        item_state.cleanup_item_states()
Пример #2
0
def current_host(host_name_: str, *, write_state: bool):
    """Make a bit of context information globally available

    So that functions called by checks know this context.
    This is used for both legacy and agent_based API.
    """
    global _hostname
    # we do not encourage nested contexts at all -- but it should work.
    previous_host_name = _hostname
    _hostname = host_name_
    # TODO: this is a mixture of legacy and new Check-API mechanisms. Clean this up!
    try:
        item_state.load(host_name_)
        yield
    finally:
        _hostname = previous_host_name
        if write_state:
            item_state.save()
            item_state.cleanup_item_states()