[Nagiosplug-devel] [PATCH] negate: Let the user specify what end result of specific return code

Andreas Ericsson ae at op5.se
Thu Jun 21 14:47:05 CEST 2007


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.


> Also I have these two suggestions:
> 
> 1. The default behaviour should only happen if none of -o, -w, -c and -u are
> present (That's what is in negate.pl too). I.e. in the last example above
> the correct result would be:
> 
> 0 0 2 3
> 

As the status table is pre-filled with the default values, whatever values are
missing will always be translated to their default values. I'm not sure if the
defaults I've set in this modified negate program matches the ones in the original
program, but that's a minor thing to fix.


> 2. We should accept numeric values:
> 
> $ ./negate -w 2 
> 

I have no opinion on this. It might be handy for testing, but I imagine users
will most likely want to use the readable arguments.

> If you're not going to work on this anymore I'll finish up the work whenever
> I can (Not before 2-3 weeks...).
> 

I'll fix what bugs are found that I can reproduce, but I won't add more features.
I'll have a look at the test thing as well.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231




More information about the Devel mailing list