[Nagiosplug-devel] check_load arg parsing bugfix and cleanup
Andreas Ericsson
ae at op5.se
Fri May 27 18:54:20 CEST 2005
sean finney wrote:
> hey,
>
> On Fri, May 27, 2005 at 05:55:16PM +0200, Andreas Ericsson wrote:
>
>>Here's a patch to check_load.c which removes a lot of duplicate code and
>>some unnecessary complexity. It also fixes the argument parsing bug.
>
>
> i'll take a look at the latest patch as soon as i have a chance.
>
Thanks, and thanks for applying it. :)
>
>>Next I'll rework the api for running commands, since that's the area
>>where most plugins duplicate efforts and does so in a very non-efficient
>>way. If someone else is already working on this, gimme a holler so we
>>can coordinate the efforts.
>
>
> i'm not working directly on this, but i have been messing around with
> more general api-related stuff. while i don't have much to show on
> my end (apart from the beginnings of some plugin-friendly snmp functions),
> i'd be interested in what you have to propose.
>
It's at http://oss.op5.se/nagios/runcmd.tar.gz. It's basically a
revamped spopen() with an output-buf-to-stringarray parsing-routine
attached. I've made sure that used values aren't wasted so the
complexity of parsing multi-line output is no O(n) instead of O(n+m)
like it was before. It makes for quite a save on multiple serial executions.
I've also made it async-safe so it should be fairly straight-forward to
implement it in the nagios core later on, although that will most likely
involve the shell or at least a more shell-like argument parsing routine.
Compile with make and run like so:
./runcmd '/usr/bin/find /usr/bin'
You can run any command really, but paths aren't understood and it's
fairly nice to see that dynamic memory allocation works nicely. I'm
particularly fond of the array size calculation which wastes a minimum
of memory while making calculations simple and does a maximum of 5
realloc()'s for any average input strlen(). Look for --rsf and you'll
see what I mean.
It should work well with running snmpget/snmpwalk from a plugin until
time and energy has been found to make use of the net-snmp library.
--
Andreas Ericsson andreas.ericsson at op5.se
OP5 AB www.op5.se
Lead Developer
More information about the Devel
mailing list