Monitoring: Porovnání verzí
Z Freenetis Wiki
Řádek 65: | Řádek 65: | ||
chmod +x /usr/local/sbin/freenetis-monitor | chmod +x /usr/local/sbin/freenetis-monitor | ||
+ | |||
+ | == Spuštění == | ||
+ | |||
+ | Skript je nutné spouštět ve věčném cyklu (např. ve [http://cs.wikipedia.org/wiki/GNU_Screen screenu]): | ||
+ | |||
+ | while true; do freenetis-monitor; done |
Verze z 2. 8. 2012, 04:24
Instalace
Závislosti
apt-get install fping
Skript
Následující kód uložit jako /usr/local/sbin/freenetis-monitor (nastavit správně proměnné HOSTS_INPUT_URL a HOSTS_OUTPUT_URL):
#!/bin/bash # URL with IP addresses to monitor HOSTS_INPUT_URL="http://freenetis.example.org/cs/web_interface/monitoring_hosts/" # URL to which we send result HOSTS_OUTPUT_URL="http://freenetis.example.org/cs/web_interface/monitoring_states/" # temporary file with list of IP addresses to monitor HOSTS_INPUT=`mktemp` # temporary file with result to send HOSTS_OUTPUT=`mktemp` echo "Downloading list of IP addresses to monitor..." # get ip addresses from FreenetIS wget -q "$HOSTS_INPUT_URL$1" -O "$HOSTS_INPUT" # use fping to get ip addresses states fping -e -f "$HOSTS_INPUT" 2>/dev/null | while read host do # ip address ip=`echo $host | awk '{print $1}'` # state of host (alive or unreachable) state=`echo $host | awk '{print $3}'` # latency of host (only for alive state) lat=`echo $host | awk '{print $4}' | sed 's/(//'` # do not add ampersand to beginning of file with result if [ -s "$HOSTS_OUTPUT" ]; then echo -n "&" >> "$HOSTS_OUTPUT"; fi # add variables to file with result echo "ip[]=$ip&state[]=$state&lat[]=$lat" >> "$HOSTS_OUTPUT" done # remove temporary file with IP addresses to monitor rm "$HOSTS_INPUT" echo "Sending result data back to FreenetIS..." # send file with result back to FreenetIS wget -q --post-file="$HOSTS_OUTPUT" "$HOSTS_OUTPUT_URL" # remove temporary file with result rm "$HOSTS_OUTPUT"
Nastavit práva pro spouštění:
chmod +x /usr/local/sbin/freenetis-monitor
Spuštění
Skript je nutné spouštět ve věčném cyklu (např. ve screenu):
while true; do freenetis-monitor; done