[Nagiosplug-devel] [PATCH] negate: Let the user specify what end result of specific return code
Thomas Guyot-Sionnest
dermoth at aei.ca
Sat Jun 23 18:06:19 CEST 2007
On 21/06/07 08:47 AM, Andreas Ericsson wrote:
> Thomas Guyot-Sionnest wrote:
>>> -----Original Message-----
>>> From: nagiosplug-devel-bounces at lists.sourceforge.net [mailto:nagiosplug-
>>> devel-bounces at lists.sourceforge.net] On Behalf Of Andreas Ericsson
>>> Sent: June 11, 2007 5:50
>>> To: Nagios Plugin Development Mailing List
>>> Subject: Re: [Nagiosplug-devel] [PATCH] negate: Let the user specify what
>>> end result of specific return code
>>>
>>> Ton Voon wrote:
>>>> Hi Andreas,
>>>>
>>>> On 23 May 2007, at 15:46, Andreas Ericsson wrote:
>>>>
>>>>> This patch lets the user specify how to translate the various return
>>>>> codes from the commands the negate plugin runs, rather than just
>>>>> having
>>>>> the hardcoded option to go with.
>>>>>
>>>>> This is specified as such:
>>>>> --critical=warning (to make critical translate to warning)
>>>>> --warning=ok
>>>>>
>>>> This looks interesting and I wrote some tests to try this out, but I
>>>> don't appear to be getting the right results. Could have a look at it?
>>>>
>>> Oh gawds, this went dormant for a long time. Higher prio projects, illness
>>> and vacations came in between.
>>>
>>> I happened to build the patch from the wrong branch. The correct one is
>>> attached.
>> Thanks Andreas... I just found use for that new negate, though it still fail
>> Ton's tests. I noticed that the run_simple function does not handle properly
>> ok state. At line 169:
>>
>> if (WEXITSTATUS(status){
>> ...
>> }
>>
>> return STATE_UNKNOWN;
>>
>> Did you sent the wrong patch again? After looking at the current code, it
>> looks like there are *many* things that need to be polished as well.
>>
>
> That line is in the old patch, but using the one attached to my second mail
> (the one you replied to) results in code that has no line reading
> "if (WEXITSTATUS(status))".
>
> Perhaps you applied the old patch again?
>
> The current code goes like this:
> --%<---%<---%<---%<---
> /* only use the configured return codes if the program
> * exited in a normal fashion */
> if (WIFEXITED(status)) {
> result = WEXITSTATUS(status);
> if (result > 0 && result < sizeof(state) / sizeof(int))
> return state[result];
> }
>
> /* if the program didn't exit normally, we're clueless */
> return STATE_UNKNOWN;
> ---%<---%<---%<---%<---
>
> Since the size of the state-table is sizeof(int) * 4, the code will
> always return UNKNOWN for return-codes that nagios doesn't understand.
The problem is the "if (WIFEXITED(status)". If the status code is 0,
WIFEXITED(status) returns 0 and the if statement is skipped. You should
probably do:
result = WEXITSTATUS(status);
if (result > 0 && result < sizeof(state) / sizeof(int))
return state[result];
}
Though I'd like to know the possible return codes for WEXITSTATUS first.
As I said I can work on this patch at a later time if you like. The test
script is in cvs, just do:
$ ../test.pl.in t/negate.pl
or
prove t/negate.pl
from the plugins directory.
Thomas
Thomas
More information about the Devel
mailing list