#!/bin/sh
#
# uWSGI PMDA "plugin" for pmcheck
#

. $PCP_DIR/etc/pcp.env || exit 1
. $PCP_SHARE_DIR/lib/checkproc.sh

_do_args "$@"

_check()
{
    test -n "$@" && echo "$@" >> $tmp/out
    [ "$verbose" -gt 0 -a -s $tmp/out ] && cat $tmp/out
    [ $status -eq 0 ] || exit
}

iam=uwsgi
if $lflag
then
    [ "$verbose" -gt 0 ] && echo "uWSGI PMDA - metrics from uWSGI servers"
elif $sflag
then
    status=0  # assume active until proven not to be
    _ctl_pmda state $iam || status=$?
    _check "$iam PMDA status: $status"
    PROBE="$PCP_PYTHON_PROG $PCP_PMDAS_DIR/$iam/pmda$iam.python"
    PCP_PYTHON_PROBE=1 $PROBE || status=2
    _check "$iam probe status: $status"
elif $aflag
then
    _ctl_pmda activate $iam pmda$iam.python || status=1
elif $dflag
then
    _ctl_pmda deactivate $iam || status=1
else
    [ $verbose -gt 0 ] && echo "botch sflag=$sflag aflag=$aflag dflag=$dflag show_me=$show_me verbose=$verbose"
    status=99
fi

exit
