Skip to content
Snippets Groups Projects
Commit 29f73d10 authored by Eduardo Luis Buratti's avatar Eduardo Luis Buratti
Browse files

Merge branch 'review' into 'master'

Review

Esse é um review que acabou virando um commit só.
Ele resolve o problema de dados incorretos que pode acontecer no improvável evento do script ser executado duas vezes no mesmo intervalo de 5 minutos.

O problema é que haveriam duas linhas com o mesmo INTERVALID no arquivo de dados de rede, evento não esperado pelo script que transforma esses dados em um XML, ocasionando em um SHIFT em todos os intervalos de 5 minutos subsequentes.
parents 1ba54395 a5c4fd62
Branches
No related tags found
No related merge requests found
...@@ -123,8 +123,23 @@ OUTPUT_COUNT=$(sudo $IPTABLES -nvxL OUTPUT | grep DS_OUTPUT_COUNTS | \ ...@@ -123,8 +123,23 @@ OUTPUT_COUNT=$(sudo $IPTABLES -nvxL OUTPUT | grep DS_OUTPUT_COUNTS | \
{pkts+=$1; bytes+=$2} \ {pkts+=$1; bytes+=$2} \
END{print pkts,bytes}') END{print pkts,bytes}')
# Add new entry to traffic file
echo "$INTERVALID $INPUT_COUNT $OUTPUT_COUNT" >> $TRAFFIC echo "$INTERVALID $INPUT_COUNT $OUTPUT_COUNT" >> $TRAFFIC
# If this script is run more than once in less than a five minutes interval we
# might end up with duplicated lines, which could mess with the XML file
# later, so better make sure this doesn't happen.
if [ $(grep -cw "^$INTERVALID" $TRAFFIC) -gt 1 ]; then
# If we are unfortunate enough to have duplicated lines we sum up them with
# the new network data aquired.
IN_OUT=$(awk -v inp=$INTERVALID 'BEGIN{rxpkts=0; rxbytes=0; txpkts=0; txbytes=0} $1==inp \
{rxpkts+=$2; rxbytes+=$3; txpkts+=$4; txbytes+=$5} \
END{print rxpkts,rxbytes,txpkts,txbytes}' $TRAFFIC)
# Remove all lines and add only the sum of them.
sed -i "/^$INTERVALID/d" $TRAFFIC
echo "$INTERVALID $IN_OUT" >> $TRAFFIC
fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Create or update iptables rules (used for counting) based on the interfaces # Create or update iptables rules (used for counting) based on the interfaces
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment