[Nagiosplug-devel] max_state logic?

Ton Voon ton.voon at altinity.com
Wed Sep 19 10:12:18 CEST 2007


On 19 Sep 2007, at 08:13, Thomas Guyot-Sionnest wrote:

> I was trying to replicate max_state from utils.c in Perl, but the  
> logic
> there seems broken:
>
> int
> max_state (int a, int b)
> {
>         if (a == STATE_CRITICAL || b == STATE_CRITICAL)
>                 return STATE_CRITICAL;
>         else if (a == STATE_WARNING || b == STATE_WARNING)
>                 return STATE_WARNING;
>         else if (a == STATE_OK || b == STATE_OK)
>                 return STATE_OK;
>         else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN)
>                 return STATE_UNKNOWN;
>         else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT)
>                 return STATE_DEPENDENT;
>         else
>                 return max (a, b);
> }
>
> Given that, OK + UNKNOWN or OK + DEPENDENT will always return OK. Is
> that right? IMO the OK test should be moved at the end.
>

Yes, that does look broken. I think DEPENDENT was a really old state,  
which I don't think should be used anymore, though I can see it is  
used in check_http and check_snmp. Anyone know the history of this?

Thomas, could you fix? Ideally there should be some tests against it  
but that would involve moving max_state into utils_base.c.

Ton

http://www.altinity.com
T: +44 (0)870 787 9243
F: +44 (0)845 280 1725
Skype: tonvoon






More information about the Devel mailing list