Projet

Général

Profil

Révision ee4f4ce2

IDee4f4ce22f8ef274db2db5d4336a32412199a8b9
Parent 8654230b
Enfant 144f333c

Ajouté par Younes Ichiche il y a presque 4 ans

add catching of error code on ssh

Voir les différences:

plugins/router/mikrotik_system
45 45
ssh_host=${ssh_host:-192.168.2.1}
46 46
c=0 # zähler; wird für verschiedene Schleifen benötigt
47 47

  
48
# Function to get stderr from command
49
# USAGE: catch STDOUT STDERR cmd args..
50
catch()
51
{
52
eval "$({
53
__2="$(
54
  { __1="$("${@:3}")"; } 2>&1;
55
  ret=$?;
56
  printf '%q=%q\n' "$1" "$__1" >&2;
57
  exit $ret
58
  )";
59
ret="$?";
60
printf '%s=%q\n' "$2" "$__2" >&2;
61
printf '( exit %q )' "$ret" >&2;
62
} 2>&1 )";
63
}
64

  
48 65
# Funktionen
49 66
function get_name {
50 67
  while read -r line; do
......
71 88
    fi
72 89
  done <<< "$data"
73 90
}
91
catch()
92
{
93
eval "$({
94
__2="$(
95
  { __1="$("${@:3}")"; } 2>&1;
96
  ret=$?;
97
  printf '%q=%q\n' "$1" "$__1" >&2;
98
  exit $ret
99
  )";
100
ret="$?";
101
printf '%s=%q\n' "$2" "$__2" >&2;
102
printf '( exit %q )' "$ret" >&2;
103
} 2>&1 )";
104
}
74 105
function get_data {
75 106
  # hole daten per ssh
76
  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')
107
  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'
108
  data_ret=$?
109
}
110
function validate_data {
111
  if [ $data_ret -ne 0 ]; then
112
    echo "SSH returned errorcode = $data_ret:"
113
    echo "$stderr"
114
    exit $data_ret
115
  fi
77 116
}
78 117
function get_mem_total {
79 118
  mem_total=$(
......
368 407

  
369 408
# rufe funktionen auf, reihenfolge ist wichtig
370 409
get_data
410
validate_data
371 411
get_name
372 412
get_cpu_count
373 413
# munin-Logik

Formats disponibles : Unified diff