HOSTSTATE not changing ( my logic )

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
eherr
Posts: 1
Joined: Thu Mar 06, 2014 8:48 am

HOSTSTATE not changing ( my logic )

Post by eherr »

HOSTSTATE doesnt always change correctly and I have read the support page but I need some more guidance.

I am trying to disable all notifications but have an event handler that shoots me a custom email after it has been down max_check_attempts which would equate to roughly 10 Minutes.

When I bring the IP offline it works correctly. When I bring it up after the max_check_attempts + some more time, the HOSTSTATEs are still correct. If I flap it real quick, the HOSTSTATE does not show correctly.

I basically want the logic to be if circuit is down and its been after max attempts, run custom code.
if( $HOSTSTATE =~ /DOWN/ && $SERVICEATTEMPT =~ /3/ )
{
# code ....
}

Thoughts?

Log of not working....

-----------
BRINGING IP OFFLINE
-----------

Fri Mar 7 10:55:10 2014
LASTHOSTCHECK: 1394207681
HOSTADDRESS: 216.187.15.113
HOSTSTATETYPE: SOFT
HOSTATTEMPT: 1
HOSTDISPLAYNAME: TESTSITE
HOSTSTATE: DOWN
MAXHOSTATTEMPTS: 3
SERVICESTATE: CRITICAL
SERVICESTATEID: 2
SERVICESTATETYPE: SOFT
SERVICEATTEMPT: 1
MAXSERVICEATTEMPTS: 3
-------------------


-----------
BRINGING IP ONLINE
-----------

Fri Mar 7 10:56:11 2014
LASTHOSTCHECK: 1394207710
HOSTADDRESS: 216.187.15.113
HOSTSTATETYPE: SOFT
HOSTATTEMPT: 2
HOSTDISPLAYNAME: TESTSITE
HOSTSTATE: DOWN
MAXHOSTATTEMPTS: 3
SERVICESTATE: OK
SERVICESTATEID: 0
SERVICESTATETYPE: SOFT
SERVICEATTEMPT: 2
MAXSERVICEATTEMPTS: 3
-------------------


I am guessing my logic for this should be to use SERVICESTATE instead.

if( $SERVICESTATE !~ /OK/ && $SERVICEATTEMPT =~ /3/ )
{
# code ....
}


-----------
BRINGING IP OFFLINE
-----------

Fri Mar 7 11:29:10 2014
LASTHOSTCHECK: 1394209714
HOSTADDRESS: 216.187.15.113
HOSTSTATETYPE: SOFT
HOSTATTEMPT: 1
HOSTDISPLAYNAME: AlbertusMagnus
HOSTSTATE: DOWN
MAXHOSTATTEMPTS: 3
SERVICESTATE: CRITICAL
SERVICESTATEID: 2
SERVICESTATETYPE: SOFT
SERVICEATTEMPT: 1
MAXSERVICEATTEMPTS: 3
-------------------

Fri Mar 7 11:30:10 2014
LASTHOSTCHECK: 1394209750
HOSTADDRESS: 216.187.15.113
HOSTSTATETYPE: SOFT
HOSTATTEMPT: 2
HOSTDISPLAYNAME: AlbertusMagnus
HOSTSTATE: DOWN
MAXHOSTATTEMPTS: 3
SERVICESTATE: CRITICAL
SERVICESTATEID: 2
SERVICESTATETYPE: SOFT
SERVICEATTEMPT: 2
MAXSERVICEATTEMPTS: 3
-------------------


-----------
BRINGING IP ONLINE
-----------

Fri Mar 7 11:31:11 2014
LASTHOSTCHECK: 1394209810
HOSTADDRESS: 216.187.15.113
HOSTSTATETYPE: HARD
HOSTATTEMPT: 3
HOSTDISPLAYNAME: AlbertusMagnus
HOSTSTATE: DOWN
MAXHOSTATTEMPTS: 3
SERVICESTATE: OK
SERVICESTATEID: 0
SERVICESTATETYPE: SOFT
SERVICEATTEMPT: 3
MAXSERVICEATTEMPTS: 3
-------------------
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: HOSTSTATE not changing ( my logic )

Post by tmcdonald »

Services on a host might be checked at different times or intervals than the actual host itself. You could have a host check interval of 20 minutes and a service interval of 1 minute. So you could very well see the service go up and down by plugging in and unplugging a network cable, and the host is never shown as down because it hasn't been re-checked in that time.

You will need to take this into consideration when determining your logic.
Former Nagios employee
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: HOSTSTATE not changing ( my logic )

Post by sreinhardt »

I think you would want hoststate and hostattempt for hosts and servicestate and serviceattempt for services, then since this is a global event handler, find a way to determine if this was a host check or service check.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked