Thoughts on external commands

by Andreas Ericsson Email

Yesterday I had the opportunity to take a look at how external commands are implemented, as I need some way to let merlin decide if commands submitted to the pipe should be applied to the Nagios daemon that receives it as well as the ones we're supposed to propagate it to.

First I started taking a look at how to undo the action of each of the external commands, but there are 100+ of the damn buggers so I quickly gave this up.

I noticed that I can pass "custom" external commands that get sent to neb-modules only that Nagios has no idea about, if I prepend an underscore to the command as written to the pipe. While this is all fine and well, I think I have a better idea.

Imagine the extcmd api working something like this instead:


    struct extcmd {
        int command_id;
        char *command_name;
        int command_args;
        int (*handler)(struct extcmd *, char **, int);
    };

    /* set an external command handler */
    int set_extcmd_handler(struct extcmd *cmd, int overwrite);

When a command is read, it gets looked up in a hash table, its arguments are parsed into an argument vector with at least "command_args" entries (giving the additional bonus that Nagios can now log a warning if the argument doesn't have at least the minimum number of arguments, which it couldn't do before) and the handler is run for that command. A handler could be defined like this:


    int extcmd_handler(struct extcmd *cmd, char **argv, int argc);

If that was the case, all I'd have to do in my NEB-modules would be to register a new handler for the commands I don't want Nagios to handle by itself and it would get called instead of the default handler. Nifty, eh? :)

Feedback awaiting moderation

This post has 3 feedbacks awaiting moderation...

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)