Additionally, I discovered that the original check script didn’t handle quoted commas in the CSV (ex: server name and location), for me all of my columns were off by one. Now data is accurate:
su - cmkplugin -c “/usr/bin/speedtest --format=tsv --accept-license” > /dev/null 2>&1
echo "0 speedtest ping=$PING;;|upload=${UPLOAD}Mbps;;|download=${DOWNLOAD}Mbps;; ping $PING upload ${UPLOAD}Mbps download ${DOWNLOAD}Mbps "
···
Mike Hanby
mhanby @ uab.edu
Systems Analyst III - Enterprise
IT Research Computing Services
The University of Alabama at Birmingham
From: “Hanby, Mike” mhanby@uab.edu
Date: Wednesday, November 27, 2019 at 9:20 PM
Cc: “checkmk-en@lists.mathias-kettner.de” checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Linux Asynchronous Execution of Local Check returning UNKOWN
I made a slight modification to the ‘speedtest’ script in case anyone else runs across this. I didn’t want to run the ‘speedtest-cli’ Python script as root, so I modified it to run as a user named ‘cmkplugin’ (which has to be manually created
on the host). The user doesn’t need any special privileges.
If the script is run as a user other than root, it will continue to run as that user:
#! /bin/bash
if type speedtest-cli > /dev/null 2>&1 ; then
LOGFILE=“$(mktemp “/tmp/speedtest.XXXXXXXX”)”
if [ “$EUID” -ne 0 ]; then
speedtest-cli --csv > “$LOGFILE”
else
chown cmkplugin $LOGFILE
chmod 660 $LOGFILE
su - cmkplugin -c “/usr/bin/speedtest-cli --csv > $LOGFILE”
fi
CSV=$(cat “$LOGFILE”)
IFS=, VALUES=($CSV)
PING=${VALUES[5]}
DOWNLOAD=${VALUES[6]}
UPLOAD=${VALUES[7]}
DOWNLOAD=“$(numfmt --to=iec-i --suffix=B <<< $DOWNLOAD)”
UPLOAD=“$(numfmt --to=iec-i --suffix=B <<< $UPLOAD)”
echo “<<>>”
echo "0 speedtest ping=$PING;;|upload=$UPLOAD;;|download=$DOWNLOAD;; ping $PING upload $UPLOAD download $DOWNLOAD "
fi
rm -rf “$LOGFILE”
The end result is a process tree like this:
root 26992 0.2 0.0 126192 3392 ? S 21:18 0:00 _ su - cmkplugin -c /usr/bin/speedtest-cli --csv > /tmp/speedtest.9G4rSNjn
cmkplug+ 26995 0.0 0.0 115312 1704 ? Ss 21:18 0:00 _ -bash -c /usr/bin/speedtest-cli --csv > /tmp/speedtest.9G4rSNjn
cmkplug+ 27020 28.9 1.3 1164100 222104 ? Sl 21:18 0:04 _ /usr/bin/python2 /usr/bin/speedtest-cli --csv
Mike Hanby
mhanby @ uab.edu
Systems Analyst III - Enterprise
IT Research Computing Services
The University of Alabama at Birmingham
From: “Hanby, Mike” mhanby@uab.edu
Date: Wednesday, November 27, 2019 at 8:51 PM
To: Andreas Döhler andreas.doehler@gmail.com
Cc: “checkmk-en@lists.mathias-kettner.de” checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Linux Asynchronous Execution of Local Check returning UNKOWN
Thanks Andreas,
I jumped the gun. I moved on to another task, came later and the cached async execution is working.
speedtest OK - ping 4.75310622473674 upload 88MiB download 22B
Thanks for the feedback,
Mike
Mike Hanby
mhanby @ uab.edu
Systems Analyst III - Enterprise
IT Research Computing Services
The University of Alabama at Birmingham
From: Andreas Döhler andreas.doehler@gmail.com
Date: Wednesday, November 27, 2019 at 4:27 PM
To: “Hanby, Mike” mhanby@uab.edu
Cc: “checkmk-en@lists.mathias-kettner.de” checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Linux Asynchronous Execution of Local Check returning UNKOWN
Hi Mike,
I tested your script inside one of my test hosts and it was working fine.
Copy speedtest script to /usr/lib/check_mk_agent/plugins/3600 and waited 3-4 minutes.
Then the check was correctly visible inside checkmk.
Can you have a look at your folder /var/lib/check_mk_agent/cache/. There should be a file with a name like ‘plugins_3600\speedtest.sh.cache’.
Inside this file is the output of your script.
Best regards
Andreas
Am Mi., 27. Nov. 2019 um 20:01 Uhr schrieb Hanby, Mike mhanby@uab.edu:
Howdy (CheckMK Raw 1.6.0p6),
I have a plugin installed locally on a system to perform a periodic Internet speed test (https://github.com/jas31085/CheckMK-plugin/blob/master/speedtest)
With the script (speedtest) copied to the local host under /usr/lib/check_mk_agent/plugins it works find and provides the graphing data I’m looking for. However, the problem is
that the script takes about a minute to run and it sends / receives about 80MB of data. With that in mind, I’d like it to only execute hourly.
According to the docs, " Asynchronous Execution" is what I need.
In the same way as with MRPE plug-ins can process asynchronously. This is very useful if the plug-ins have a very long runtime, and the acquired status data in any case does not need to be refreshed every minute.
An asynchronous execution is not configured with a file. Instead, create a subdirectory in plugins whose name is a numeric: representing a count of seconds. Plug-ins in this directory
will not only be executed asynchronously, at the same time with the second count a minimum waiting time is also specified before the plug-in can be run again. If the agent is again called before the specified time has elapsed, it will use cached data from
the last run of the plug-in. In this way an interval longer than the typical one minute can in effect be configured for the plug-in.
root@linuxhost# cd /usr/lib/check_mk_agent/plugins
root@linuxhost# mkdir 3600
root@linuxhost# mv speedtest 3600
After moving the script into the cached seconds directory, CheckMK reports the service as UNKNOWN:
’ SPEEDTEST UNKN - Item not found in agent output’
Mike Hanby
mhanby @
uab.edu
Systems Analyst III - Enterprise
IT Research Computing Services
The University of Alabama at Birmingham
checkmk-en mailing list
checkmk-en@lists.mathias-kettner.de
Manage your subscription or unsubscribe
https://lists.mathias-kettner.de/cgi-bin/mailman/listinfo/checkmk-en