2021-09-17 11:58:26 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
# Michael Grote
|
|
|
|
# michael.grote ät posteo.de
|
2021-09-21 14:41:08 +02:00
|
|
|
# This plugin fetches multiple Values from a mikrotik device.
|
|
|
|
# tested with a RB750GR3 and CRS309.
|
2021-09-17 11:58:26 +02:00
|
|
|
|
2021-09-21 14:41:08 +02:00
|
|
|
# A User is needed for this plugin to work:
|
|
|
|
# /user add name=munin group=read password=hallowelt address=<munin-server-ip>
|
|
|
|
|
|
|
|
# plugin config:
|
2021-09-17 11:58:26 +02:00
|
|
|
# [mt_system_<name>]
|
|
|
|
# user root
|
|
|
|
# env.ssh_user munin
|
|
|
|
# env.ssh_password hallowelt
|
|
|
|
# env.ssh_host 192.168.2.1
|
|
|
|
|
2021-09-21 14:41:08 +02:00
|
|
|
# TODO:
|
|
|
|
# - [ ] free-hdd-space: 4760.0KiB
|
|
|
|
# - [ ] total-hdd-space: 16.3MiB
|
|
|
|
# - [ ] free-memory: 210.2MiB
|
|
|
|
# - [ ] total-memory: 256.0MiB
|
2021-09-21 20:46:26 +02:00
|
|
|
# - [ ] limit als % von total
|
2021-09-21 14:41:08 +02:00
|
|
|
# - [ ] uptime: 1w4d22h29m28s
|
2021-09-21 20:46:26 +02:00
|
|
|
# - [ ] linter
|
|
|
|
# - [ ] diagramm erklärungen label
|
|
|
|
# - [ ] doku depencies
|
|
|
|
# - [ ] check bc
|
2021-09-21 14:41:08 +02:00
|
|
|
|
|
|
|
# setze Variablen mit default-Werten
|
|
|
|
ssh_user=${ssh_user:-user}
|
|
|
|
ssh_password=${ssh_password:-password}
|
|
|
|
ssh_host=${ssh_host:-192.168.2.1}
|
|
|
|
c=0 # zähler; wird für verschiedene Schleifen benötigt
|
|
|
|
|
|
|
|
|
2021-09-21 14:45:27 +02:00
|
|
|
# Funktionen
|
2021-09-21 15:50:23 +02:00
|
|
|
function get_name {
|
|
|
|
while read -r line; do
|
|
|
|
if echo $line | grep 'name:' > /dev/null; then
|
2021-09-21 18:53:34 +02:00
|
|
|
name=$(echo $line | grep name: | awk '{ print $2 }')
|
|
|
|
fi
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
2021-09-21 15:50:23 +02:00
|
|
|
function get_cpu_count {
|
|
|
|
while read -r line; do
|
|
|
|
if echo $line | grep 'cpu-count' > /dev/null; then
|
|
|
|
anzahl_cpu=$(echo $line grep cpu-count: | sed -r 's/(cpu-count: )([0-9]+)/\2/g' | tr -dc '[0-9]')
|
|
|
|
fi
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
|
|
|
function check_sshpass {
|
|
|
|
if [[ $(dpkg -l sshpass > /dev/null 2>&1) -ne "0" ]] ; then
|
|
|
|
echo "could not find sshpass"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-09-21 14:45:27 +02:00
|
|
|
function get_voltage_label {
|
|
|
|
while read -r line; do # für jede zeile in... ; siehe "done"
|
|
|
|
# gebe die zeile aus
|
|
|
|
# suche mit awk nach "voltage:"
|
|
|
|
# wenn gefunden:
|
|
|
|
# gebe jede zeile per print text aus
|
|
|
|
# externe/bash-variablen mit "'"<var>"'"
|
|
|
|
echo $line | awk '/voltage:/{
|
|
|
|
print "multigraph voltage_graph_""'"$name"'";
|
|
|
|
print "graph_title voltage " "'"$name"'";
|
|
|
|
print "graph_vlabel volt";
|
|
|
|
print "graph_category mikrotik";
|
|
|
|
print "graph_args -l 0";
|
|
|
|
print "voltage.label voltage"
|
|
|
|
}'
|
|
|
|
done <<< "$data" # der variable data
|
|
|
|
}
|
2021-09-21 15:50:23 +02:00
|
|
|
function get_voltage_value {
|
|
|
|
while read -r line; do
|
|
|
|
# funktion wie bei den "label"-funktionen
|
2021-09-21 17:00:58 +02:00
|
|
|
# gib überschrift aus wenn dirtyconfig nicht gesetzt ist
|
|
|
|
# weil aufruf dann nicht in "config" erfolgt
|
|
|
|
# wenn dirtyconfig nicht gesetzt sind, gebe überschrift aus
|
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "0" ]; then
|
|
|
|
echo $line | awk '/voltage:/{
|
|
|
|
print "multigraph voltage_graph_""'"$name"'";
|
|
|
|
}'
|
|
|
|
fi
|
2021-09-21 15:50:23 +02:00
|
|
|
# entferne mit gsub das zeichen % in wert $2
|
|
|
|
# gebe $2 aus
|
|
|
|
echo $line | awk '/voltage:/{
|
|
|
|
gsub(/V/,"",$2);
|
|
|
|
print "voltage.value " $2
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
|
|
|
|
2021-09-21 14:45:27 +02:00
|
|
|
function get_bad_blocks_label {
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/bad-blocks:/{
|
|
|
|
print "multigraph bad_blocks_graph_""'"$name"'";
|
|
|
|
print "graph_title bad blocks " "'"$name"'";
|
|
|
|
print "graph_vlabel %";
|
|
|
|
print "graph_category mikrotik";
|
|
|
|
print "graph_args -l 0 --upper-limit 100";
|
|
|
|
print "bad_blocks.label bad_blocks";
|
|
|
|
print "bad_blocks.warning 2";
|
|
|
|
print "bad_blocks.critical 25"
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
2021-09-21 15:50:23 +02:00
|
|
|
function get_bad_blocks_value {
|
|
|
|
while read -r line; do
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "0" ]; then
|
2021-09-21 15:50:23 +02:00
|
|
|
echo $line | awk '/bad-blocks:/{
|
|
|
|
print "multigraph bad_blocks_graph_""'"$name"'";
|
2021-09-21 17:00:58 +02:00
|
|
|
}'
|
|
|
|
fi
|
|
|
|
echo $line | awk '/bad-blocks:/{
|
2021-09-21 15:50:23 +02:00
|
|
|
gsub(/%/,"",$2);
|
|
|
|
print "bad_blocks.value " $2
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
|
|
|
|
2021-09-21 14:45:27 +02:00
|
|
|
function get_write_sect_total_label {
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/write-sect-total:/{
|
|
|
|
print "multigraph write_sect_total_graph_""'"$name"'";
|
|
|
|
print "graph_title Total sector writes " "'"$name"'";
|
|
|
|
print "graph_vlabel count";
|
|
|
|
print "graph_category mikrotik";
|
|
|
|
print "graph_args -l 0";
|
|
|
|
print "write_sect_total.label write_sect_total"
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
2021-09-21 15:50:23 +02:00
|
|
|
function get_write_sect_total_value {
|
|
|
|
while read -r line; do
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "0" ]; then
|
|
|
|
echo $line | awk '/write-sect-total:/{
|
|
|
|
print "multigraph write_sect_total_graph_""'"$name"'";
|
|
|
|
}'
|
|
|
|
fi
|
2021-09-21 15:50:23 +02:00
|
|
|
echo $line | awk '/write-sect-total:/{
|
|
|
|
print "write_sect_total.value " $2
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
|
|
|
|
2021-09-21 14:45:27 +02:00
|
|
|
function get_write_sect_since_reboot_label {
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/write-sect-since-reboot:/{
|
|
|
|
print "multigraph write_sect_since_reboot_graph_""'"$name"'";
|
|
|
|
print "graph_title Sector writes since reboot " "'"$name"'";
|
|
|
|
print "graph_vlabel count";
|
|
|
|
print "graph_category mikrotik";
|
|
|
|
print "graph_args -l 0";
|
|
|
|
print "write_sect_since_reboot.label write_sect_since_reboot"
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
2021-09-21 15:50:23 +02:00
|
|
|
function get_write_sect_since_reboot_value {
|
|
|
|
while read -r line; do
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "0" ]; then
|
|
|
|
echo $line | awk '/write-sect-since-reboot:/{
|
|
|
|
print "multigraph write_sect_since_reboot_graph_""'"$name"'";
|
|
|
|
}'
|
|
|
|
fi
|
2021-09-21 15:50:23 +02:00
|
|
|
echo $line | awk '/write-sect-since-reboot:/{
|
|
|
|
print "write_sect_since_reboot.value " $2
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
|
|
|
|
2021-09-21 14:45:27 +02:00
|
|
|
function get_temperature_label {
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/temperature:/{
|
|
|
|
print "multigraph temperature_graph_""'"$name"'";
|
|
|
|
print "graph_title temperature " "'"$name"'";
|
|
|
|
print "graph_vlabel °C";
|
|
|
|
print "graph_category mikrotik";
|
|
|
|
print "graph_args -l 0";
|
|
|
|
print "temperature.label cpu temperature";
|
|
|
|
print "temperature.warning 75";
|
|
|
|
print "temperature.critical 90"
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
2021-09-21 15:50:23 +02:00
|
|
|
function get_temperature_value {
|
|
|
|
while read -r line; do
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "0" ]; then
|
|
|
|
echo $line | awk '/temperature:/{
|
|
|
|
print "multigraph temperature_graph_""'"$name"'";
|
|
|
|
}'
|
|
|
|
fi
|
2021-09-21 15:50:23 +02:00
|
|
|
echo $line | awk '/temperature:/{
|
|
|
|
gsub(/C/,"",$2);
|
|
|
|
print "temperature.value " $2
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
|
|
|
|
2021-09-21 20:47:36 +02:00
|
|
|
function get_cpu_label {
|
|
|
|
echo multigraph cpu_load_graph_$name
|
2021-09-21 14:45:27 +02:00
|
|
|
echo graph_title cpu load $name
|
|
|
|
echo graph_vlabel %
|
|
|
|
echo graph_category mikrotik
|
|
|
|
echo graph_args -l 0 --upper-limit 100
|
2021-09-21 16:29:23 +02:00
|
|
|
echo cpu_total.label total load
|
2021-09-21 16:24:32 +02:00
|
|
|
echo cpu_total.warning 75
|
|
|
|
echo cpu_total.critical 90
|
2021-09-21 14:45:27 +02:00
|
|
|
while [ "$c" -lt "$anzahl_cpu" ]; do
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | grep cpu$c | awk '{
|
2021-09-21 16:29:23 +02:00
|
|
|
print "cpu"'"$c"'"_load.label " "cpu" "'"$c"'" " load"
|
|
|
|
print "cpu"'"$c"'"_irq.label " "cpu" "'"$c"'" " irq"
|
|
|
|
print "cpu"'"$c"'"_disk.label " "cpu" "'"$c"'" " disk"
|
2021-09-21 14:45:27 +02:00
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
c=$(( $c + 1 ))
|
|
|
|
done
|
|
|
|
}
|
2021-09-21 20:47:36 +02:00
|
|
|
function get_cpu_value {
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "0" ]; then
|
2021-09-21 20:47:36 +02:00
|
|
|
echo multigraph cpu_load_graph_$name
|
2021-09-21 17:00:58 +02:00
|
|
|
fi
|
2021-09-21 16:27:45 +02:00
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/cpu-load:/{
|
|
|
|
gsub(/%/,"",$2);
|
|
|
|
print "cpu_total.value " $2
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
2021-09-21 14:45:27 +02:00
|
|
|
c=0
|
|
|
|
while [ "$c" -lt "$anzahl_cpu" ]; do
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | grep cpu$c | awk '{
|
|
|
|
gsub(/%/,"",$3);
|
|
|
|
gsub(/%/,"",$4);
|
|
|
|
gsub(/%/,"",$5);
|
|
|
|
print "cpu"'"$c"'"_load.value " $3
|
|
|
|
print "cpu"'"$c"'"_irq.value " $4
|
|
|
|
print "cpu"'"$c"'"_disk.value " $5
|
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
c=$(( $c + 1 ))
|
|
|
|
done
|
|
|
|
}
|
2021-09-17 11:58:26 +02:00
|
|
|
|
2021-09-21 18:17:47 +02:00
|
|
|
function get_memory_label {
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/free-memory:/{
|
|
|
|
print "multigraph memory_graph_""'"$name"'";
|
|
|
|
print "graph_title memory " "'"$name"'";
|
|
|
|
print "graph_vlabel MiB";
|
|
|
|
print "graph_category mikrotik";
|
|
|
|
print "graph_args -l 0";
|
2021-09-21 18:21:34 +02:00
|
|
|
print "total_memory.label total memory";
|
2021-09-21 18:32:10 +02:00
|
|
|
print "used_memory.label used memory";
|
2021-09-21 18:21:34 +02:00
|
|
|
print "free_memory.label free memory";
|
2021-09-21 18:17:47 +02:00
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
}
|
|
|
|
function get_memory_value {
|
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "0" ]; then
|
|
|
|
echo multigraph memory_$name
|
|
|
|
fi
|
2021-09-21 19:03:47 +02:00
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/total-memory:/{
|
2021-09-21 19:05:59 +02:00
|
|
|
gsub(/MiB/,"",$2);
|
|
|
|
print "total_memory.value " $2
|
2021-09-21 19:03:47 +02:00
|
|
|
}'
|
|
|
|
done <<< "$data"
|
|
|
|
while read -r line; do
|
|
|
|
echo $line | awk '/free-memory:/{
|
2021-09-21 19:05:59 +02:00
|
|
|
gsub(/MiB/,"",$2);
|
|
|
|
print "free_memory.value " $2
|
2021-09-21 19:03:47 +02:00
|
|
|
}'
|
|
|
|
done <<< "$data"
|
2021-09-21 18:53:34 +02:00
|
|
|
# berechne used-memory
|
|
|
|
# gesamt + frei = benutzt
|
2021-09-21 19:24:29 +02:00
|
|
|
mem_total=$(
|
|
|
|
while read -r line; do
|
2021-09-21 20:01:41 +02:00
|
|
|
echo $line | awk '/total-memory:/{ gsub(/MiB/,"",$2); print $2 }' | tr -dc '[0-9.]'
|
2021-09-21 19:24:29 +02:00
|
|
|
done <<< "$data")
|
|
|
|
mem_free=$(
|
|
|
|
while read -r line; do
|
2021-09-21 20:01:41 +02:00
|
|
|
echo $line | awk '/free-memory:/{ gsub(/MiB/,"",$2); print $2 }' | tr -dc '[0-9.]'
|
2021-09-21 19:24:29 +02:00
|
|
|
done <<< "$data")
|
2021-09-21 19:59:20 +02:00
|
|
|
echo used_memory.value $(echo $mem_total-$mem_free| bc)
|
2021-09-21 19:18:24 +02:00
|
|
|
# prufe noch ob war gesetzt
|
2021-09-21 18:17:47 +02:00
|
|
|
}
|
2021-09-21 14:50:09 +02:00
|
|
|
|
|
|
|
# rufe funktionen auf, reihenfolge ist wichtig
|
|
|
|
check_sshpass
|
|
|
|
# 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')
|
|
|
|
get_name
|
|
|
|
get_cpu_count
|
2021-09-21 19:07:07 +02:00
|
|
|
|
2021-09-21 14:50:09 +02:00
|
|
|
|
2021-09-21 14:41:08 +02:00
|
|
|
# munin-Logik
|
|
|
|
# wenn $1 = X; dann
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
if [ "$1" = "config" ]; then
|
2021-09-21 17:00:58 +02:00
|
|
|
# gebe label aus
|
|
|
|
# wenn dirtyconfig gesetzt rufe value funktion auf
|
2021-09-21 14:50:09 +02:00
|
|
|
get_voltage_label
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then
|
|
|
|
get_voltage_value
|
|
|
|
fi
|
2021-09-21 14:50:09 +02:00
|
|
|
get_bad_blocks_label
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then
|
|
|
|
get_bad_blocks_value
|
|
|
|
fi
|
2021-09-21 14:50:09 +02:00
|
|
|
get_write_sect_total_label
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then
|
|
|
|
get_write_sect_total_value
|
|
|
|
fi
|
2021-09-21 14:50:09 +02:00
|
|
|
get_write_sect_since_reboot_label
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then
|
|
|
|
get_write_sect_since_reboot_value
|
|
|
|
fi
|
2021-09-21 14:50:09 +02:00
|
|
|
get_temperature_label
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then
|
|
|
|
get_temperature_value
|
|
|
|
fi
|
2021-09-21 20:47:36 +02:00
|
|
|
get_cpu_label
|
2021-09-21 17:00:58 +02:00
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then
|
2021-09-21 20:47:36 +02:00
|
|
|
get_cpu_value
|
2021-09-21 17:00:58 +02:00
|
|
|
fi
|
2021-09-21 18:17:47 +02:00
|
|
|
get_memory_label
|
|
|
|
if [ "$MUNIN_CAP_DIRTYCONFIG" = "1" ]; then
|
|
|
|
get_memory_value
|
|
|
|
fi
|
2021-09-21 14:41:08 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2021-09-21 17:07:11 +02:00
|
|
|
# wird nie aufgerufen wenn dirtyconfig gesetzt ist
|
|
|
|
# dann wird nur config aufgerufen und dabei werden zusätzlich die values ausgegeben
|
2021-09-21 14:50:09 +02:00
|
|
|
get_voltage_value
|
|
|
|
get_bad_blocks_value
|
|
|
|
get_write_sect_total_value
|
|
|
|
get_write_sect_since_reboot_value
|
|
|
|
get_temperature_value
|
2021-09-21 20:47:36 +02:00
|
|
|
get_cpu_value
|
2021-09-21 18:17:47 +02:00
|
|
|
get_memory_value
|
2021-09-21 14:41:08 +02:00
|
|
|
exit 0
|
|
|
|
|
|
|
|
|
|
|
|
# Beispieloutput:
|
2021-09-21 14:09:15 +02:00
|
|
|
# voltage: 24.5V
|
|
|
|
# temperature: 46C
|
|
|
|
# uptime: 1w6d17h12m25s
|
|
|
|
# version: 6.48.4 (stable)
|
|
|
|
# build-time: Aug/18/2021 06:43:27
|
|
|
|
# factory-software: 6.46.3
|
|
|
|
# free-memory: 209.9MiB
|
|
|
|
# total-memory: 256.0MiB
|
|
|
|
# cpu: MIPS 1004Kc V2.15
|
|
|
|
# cpu-count: 4
|
|
|
|
# cpu-frequency: 880MHz
|
|
|
|
# cpu-load: 0%
|
|
|
|
# free-hdd-space: 4760.0KiB
|
|
|
|
# total-hdd-space: 16.3MiB
|
|
|
|
# write-sect-since-reboot: 46412
|
|
|
|
# write-sect-total: 62012
|
|
|
|
# bad-blocks: 0%
|
|
|
|
# architecture-name: mmips
|
|
|
|
# board-name: hEX
|
|
|
|
# platform: MikroTik
|
|
|
|
# # CPU LOAD IRQ DISK
|
|
|
|
# 0 cpu0 0% 0% 0%
|
|
|
|
# 1 cpu1 1% 1% 0%
|
|
|
|
# 2 cpu2 0% 0% 0%
|
|
|
|
# 3 cpu3 1% 0% 0%
|
2021-09-21 14:41:08 +02:00
|
|
|
# name: hEX
|