#!/usr/bin/bash

# The following restraint variables are defined just for plugins
# RSTRNT_RESULT_URL, This is the url to the parent which kicked off this plugin.
# RSTRNT_PLUGIN_DIR, Will either be localwatchdog or report_result. These are the only 
#                    spots where we support plugins currently.
# RSTRNT_NOPLUGINS=1, This is defined for report_result.  Otherwise reporting results
#                     From plugins would cause additional plugins to be called.

if [ ! -f /usr/share/restraint/plugins/helpers ]; then
    . ./../helpers # For running tests
else
    . /usr/share/restraint/plugins/helpers
fi

for PLUGIN_DIR in $RSTRNT_PLUGINS_DIR; do
    pushd $PLUGIN_DIR >/dev/null || continue
    for PLUGIN in *; do
        # Skip any disabled plugins
        for DISABLED in $RSTRNT_DISABLED; do
            if [ "$PLUGIN" = "$DISABLED" ]; then
                rstrnt_info "Skipping Disabled Plugin: $PLUGIN"
                continue 2
            fi
        done
        rstrnt_info "Running Plugin: $RSTRNT_PLUGINS_DIR/$PLUGIN"
        ./$PLUGIN
    done
    popd >/dev/null
done
