[Nagiosplug-devel] spopen and pipes?

Andreas Ericsson ae at op5.se
Tue Feb 1 16:19:48 CET 2005

Andrew Perron wrote:
> I've taken over some old netsaint plugins that a developer made for us and they 
> were not working in nagios, so I was trying to convert them (i.e. rewrite from 
> scratch).
> One thing, in comparing how he did it vs. what the guide recommends is the use  
> of popen instead of spopen and writing information to temporary files.
> I would like to do what amounts to the following to a log file on a syslog 
> server:
>  - use grep to find relevant entries (many)
>  - use sort to ensure that they are in order (may not be)
>  - use tail to get the most recent entry

This is a job for perl (shell is too slow and it's too trivial to make 
it a fullblown regex scanning C app). Practical Extract and Report 
Language means just that (although I absolutely loathe its weird shell 
spinoff syntax and it's structure in general, it's actually ideal for this).

Properly written it shouldn't even use a lot of memory.

In shell it would look something like this;
grep <strings> | sort | uniq | tail -n 1
In this sequence, both grep and sort are CPU intensive, and sort will 
use (total_amount_of_data * 2) + 4096 bytes of memory, so that's not an 
option for a log server.

> Seems only under certain specific circumstances can I use pipes or redirects in  
> the spopen command string, so my question is whether there's a way to pipe the  
> output of spopen pipes from one to another or if there is another workaround.
> I tried using the output from the command executed and then writing to a file, 
>  but due to the volume this seems to cause unreasonable delays causing plugins 
> to timeout.

With huge (as opposed to large) amounts of data you would probably want 
to whip up something to scan each incoming message for a regex and send 
passive check results for it instead.

Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer

More information about the Devel mailing list