Zaimplementowałem poniższe rozwiązanie. Mam niestety problem ze skryptem, a właściwie to z mrtg. Skrypt w swym zamierzeniu zlicza aktualny transfer danego hosta.
Oto skrypt:
Kod: Zaznacz cały
#!/bin/bash
download=`iptables -L mrtg_traffic -v -x -n | grep " $1 " | head -1 | awk '{print $2}'`
upload=`iptables -L mrtg_traffic -v -x -n | grep " $1 " | tail -1 | awk '{print $2}'`
echo $download
echo $upload
uptime | sed -e 's/^.*up *//g' -e 's/, *[0-9] *u.*$//g'
hostname
Skrypt na moje oko działa poprawnie, ponieważ po uruchomieniu go ręcznie zwraca oczekiwane wartości:
Kod: Zaznacz cały
Alpha:/etc/mrtg/bin# ./traffic 10.0.0.213
1749276230
29383756
1 day, 3:05
Alpha
Mrtg natomiast pluje błędem:
Kod: Zaznacz cały
/etc/mrtg/bin/traffic: line 2: iptables: command not found
/etc/mrtg/bin/traffic: line 3: iptables: command not found
2010-03-18 12:10:01: WARNING: Problem with External get '/etc/mrtg/bin/traffic 10.0.0.213':
Expected a Number for 'in' but got ''
2010-03-18 12:10:01: WARNING: Problem with External get '/etc/mrtg/bin/traffic 10.0.0.213':
Expected a Number for 'out' but got ''
2010-03-18 12:10:01: ERROR: Target[traffic_10.0.0.213][_IN_] ' $target->[7]{$mode} ' did not eval into defined data
2010-03-18 12:10:01: ERROR: Target[traffic_10.0.0.213][_OUT_] ' $target->[7]{$mode} ' did not eval into defined data
Tak natomiast wygląda wpis w mrtg.conf dla tego skryptu:
Kod: Zaznacz cały
Target[traffic_10.0.0.213]: `/etc/mrtg/bin/traffic 10.0.0.213`
Title[traffic_10.0.0.213]: 10.0.0.213
Options[traffic_10.0.0.213]: growright, nopercent, integer, nobanner, noinfo, noborder
MaxBytes[traffic_10.0.0.213]: 512000
kilo[traffic_10.0.0.213]: 1024
ShortLegend[traffic_10.0.0.213]: B/s
YLegend[traffic_10.0.0.213]: Transfer
Legend1[traffic_10.0.0.213]: Download
Legend2[traffic_10.0.0.213]: Upload
LegendI[traffic_10.0.0.213]: download
LegendO[traffic_10.0.0.213]: upload
PageTop[traffic_10.0.0.213]: 10.0.0.213
PageFoot[traffic_10.0.0.213]:
Nie wiem już gdzie szukać przyczyny błędów?