1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

add catching of error code on ssh

This commit is contained in:
Younes Ichiche 2021-11-27 09:42:40 +01:00 committed by Lars Kruse
parent 8654230bb2
commit ee4f4ce22f

View file

@ -45,6 +45,23 @@ ssh_password=${ssh_password:-password}
ssh_host=${ssh_host:-192.168.2.1} ssh_host=${ssh_host:-192.168.2.1}
c=0 # zähler; wird für verschiedene Schleifen benötigt c=0 # zähler; wird für verschiedene Schleifen benötigt
# Function to get stderr from command
# USAGE: catch STDOUT STDERR cmd args..
catch()
{
eval "$({
__2="$(
{ __1="$("${@:3}")"; } 2>&1;
ret=$?;
printf '%q=%q\n' "$1" "$__1" >&2;
exit $ret
)";
ret="$?";
printf '%s=%q\n' "$2" "$__2" >&2;
printf '( exit %q )' "$ret" >&2;
} 2>&1 )";
}
# Funktionen # Funktionen
function get_name { function get_name {
while read -r line; do while read -r line; do
@ -71,9 +88,31 @@ function get_cpu_count {
fi fi
done <<< "$data" done <<< "$data"
} }
catch()
{
eval "$({
__2="$(
{ __1="$("${@:3}")"; } 2>&1;
ret=$?;
printf '%q=%q\n' "$1" "$__1" >&2;
exit $ret
)";
ret="$?";
printf '%s=%q\n' "$2" "$__2" >&2;
printf '( exit %q )' "$ret" >&2;
} 2>&1 )";
}
function get_data { function get_data {
# hole daten per ssh # hole daten per ssh
data=$(sshpass -p "$ssh_password" ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$ssh_user"@"$ssh_host" -q ':delay 6s; /system health print; /system resource print; /system resource cpu print; /system identity print') catch data stderr sshpass -p "$ssh_password" ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$ssh_user"@"$ssh_host" ':delay 6s; /system health print; /system resource print; /system resource cpu print; /system identity print'
data_ret=$?
}
function validate_data {
if [ $data_ret -ne 0 ]; then
echo "SSH returned errorcode = $data_ret:"
echo "$stderr"
exit $data_ret
fi
} }
function get_mem_total { function get_mem_total {
mem_total=$( mem_total=$(
@ -368,6 +407,7 @@ function get_disk_value {
# rufe funktionen auf, reihenfolge ist wichtig # rufe funktionen auf, reihenfolge ist wichtig
get_data get_data
validate_data
get_name get_name
get_cpu_count get_cpu_count
# munin-Logik # munin-Logik