The last host state is not correct

CMK version: RAW 2.1.0p15.cre

HI all,

I notice a issue with my checkmk , not sure if it’s a bug. I tested turned off my winserver, the alert notification sent out. But the event is only showing “DOWN (Problem) “ rather than “UP→Down”. I checked the recent notification, it shows the lasthoststate is down, same as hoststate, but suppose the lasthoststate is up . any idea about this issue?

It is possible, that the current and last host state are the same. If for example you just added a host and it was never up, both variables will have the same value. Just an example though.

The shown part of your mail uses the variable “$EVENT_TXT$”
This variable is constructed for the different types of notifications.

def _event_text_template(notification_type: str) -> str:
    # Returns an event summary
    if notification_type in ["PROBLEM", "RECOVERY"]:
        return "$PREVIOUS@HARDSHORTSTATE$ -> $@SHORTSTATE$"
    if notification_type == "FLAPPINGSTART":
        return "Started Flapping"
    if notification_type == "FLAPPINGSTOP":
        return "Stopped Flapping ($@SHORTSTATE$)"
    if notification_type == "FLAPPINGDISABLED":
        return "Disabled Flapping ($@SHORTSTATE$)"
    if notification_type == "DOWNTIMESTART":
        return "Downtime Start ($@SHORTSTATE$)"
    if notification_type == "DOWNTIMEEND":
        return "Downtime End ($@SHORTSTATE$)"
    if notification_type == "DOWNTIMECANCELLED":
        return "Downtime Cancelled ($@SHORTSTATE$)"
    if notification_type == "ACKNOWLEDGEMENT":
        return "Acknowledged ($@SHORTSTATE$)"
    if notification_type == "CUSTOM":
        return "Custom Notification ($@SHORTSTATE$)"
    if notification_type.startswith("ALERTHANDLER"):
        # The notification_type here is "ALERTHANDLER (exit_code)"
        return notification_type
    return notification_type

The problem what we have now is that the variables used are not all available inside your Nagios core. In your case it is this “$PREVIOUS@HARDSHORTSTATE$” @ is replaced with HOST or SERVICE. This is not existing inside Nagios.

That is the reason for your mail only containing the current state. There is no real and easy solution for the problem. To replace the HARDSTATE variable with LAST@STATE is no solution as this shows the state of the last check attempt. If you have more than 1 check attempt configured (what you should have) then you will see there also a DOWN for the hard state message after X check attempts.