Error in AIX Agent - cache age of plugins wrong

Hi,
there is a bug in AIX agent runing plugins asychron. The code is wrong in function run_cached at the following line:

function run_cached {
NAME=$1
# Be aware: Maxage was expected to be given in minutes but this was
# confusing because all other agents use seconds here. So this has
# been changed to be compatible.
MAXAGE=$2
shift 2
CMDLINE=$*

if [ ! -e $MK_VARDIR/cache ] ; then mkdir -p $MK_VARDIR/cache ; fi
CACHEFILE=$MK_VARDIR/cache/$NAME.cache

USE_CACHEFILE=""
# Check if file exists and is recent enough
if [ -s $CACHEFILE ]
then
    MTIME=$(/usr/bin/perl -e 'if (! -f $ARGV[0]){die "0000000"};$mtime=(stat($ARGV[0]))[9];print ($^T-$mtime);' $CACHEFILE )
    if (( $MTIME < $MAXAGE )) ; then
        USE_CACHEFILE=1
    fi
    CACHE_INFO="cached($MTIME,$MAXAGE)"
    if [[ $NAME == local_* ]]; then
        sed -e "s/^/$CACHE_INFO /" "$CACHEFILE"
    else
        # insert the cache info in the section header (^= after '!'),
        # if none is present (^= before '!')
        sed -e '/^<<<.*\(:cached(\).*>>>/!s/^<<<\([^>]*\)>>>$/<<<\1:'$CACHE_INFO'>>>/' "$CACHEFILE"
    fi
fi
if [ -z "$USE_CACHEFILE" -a ! -e "$CACHEFILE.new" ]
then
    nohup sh -c $CMDLINE > $CACHEFILE.new 2> /dev/null && mv $CACHEFILE.new $CACHEFILE  &
fi

}

The code can fixed (see following code lines):

function run_cached {
NAME=$1
# Be aware: Maxage was expected to be given in minutes but this was
# confusing because all other agents use seconds here. So this has
# been changed to be compatible.
MAXAGE=$2
shift 2
CMDLINE=$*

if [ ! -e $MK_VARDIR/cache ] ; then mkdir -p $MK_VARDIR/cache ; fi
CACHEFILE=$MK_VARDIR/cache/$NAME.cache

USE_CACHEFILE=""
# Check if file exists and is recent enough
if [ -s $CACHEFILE ]
then
    MTIME=$(/usr/bin/perl -e 'if (! -f $ARGV[0]){die "0000000"};$mtime=(stat($ARGV[0]))[9];print ($^T-$mtime);' $CACHEFILE )
    if (( $MTIME < $MAXAGE )) ; then
        USE_CACHEFILE=1
    fi
    FTIME=$(perl -le 'print((stat shift)[9])' $CACHEFILE)
    CACHE_INFO="cached($FTIME,$MAXAGE)"
    if [[ $NAME == local_* ]]; then
        sed -e "s/^/$CACHE_INFO /" "$CACHEFILE"
    else
        # insert the cache info in the section header (^= after '!'),
        # if none is present (^= before '!')
        sed -e '/^<<<.*\(:cached(\).*>>>/!s/^<<<\([^>]*\)>>>$/<<<\1:'$CACHE_INFO'>>>/' "$CACHEFILE"
    fi
fi
if [ -z "$USE_CACHEFILE" -a ! -e "$CACHEFILE.new" ]
then
    nohup sh -c $CMDLINE > $CACHEFILE.new 2> /dev/null && mv $CACHEFILE.new $CACHEFILE  &
fi

}

Regards,
Christian

1 Like

Hi Christian,

I am on the way to improve AIX agent. We added SSL encryption and cron job monitoring already.
I will test your solution soon.
May you send a pull request to tribe29 for changing this in master.

regards

Michael

I changed the code and made a pull request.
Regards, Christian

The new code is described as werk #10830 and will be available at 1.6.0p10.

3 Likes