[collectd] Exec plugin - stdin vs. environment

Trent W. Buck twb-mailman-collectd at cyber.com.au
Thu Jun 23 05:26:15 CEST 2011


Currently when you write an exec notify handler, you get a stdin
stream that looks a bit like an RFC822 or Debian thing:

    Plugin: foo
    PluginInstance: bar
    <field>: <field value>
    ...

    <message body>

This means the handler needs to parse these out each time, e.g.

        #!/bin/bash
        data=$(cat)
        Plugin=$(field Plugin)
        #PluginInstance=$(field PluginInstance)
        #Type=$(field Type)
        #TypeInstance=$(field TypeInstance)
        Host=$(field Host)
        #Severity=$(field Severity)
        #Time=$(field Time)
        Message=$(sed '1,/^$/d' <<<"$data")

        if [[ "$Plugin" != foo -a $Host =~ \.example\.net$ ]]; then
           mail fred at example.net <<< "$Message"
        fi

Collectd presumably already has the constituent components, so I think
it would be easier to simply pass the key/value pairs via the
environment, and reserve stdin for the message body.  If the body is
guaranteed to be short, that might also be feasible to pass as
environment.  Thus, the above toy example would reduce to

        #!/bin/bash
        if [[ "$Plugin" != foo -a $Host =~ \.example\.net$ ]]; then
           mail fred at example.net  # consumes message from stdin
        fi



More information about the collectd mailing list