From f96d6ae4f43ff6350e339eb895f13a6dd4c6cc6f Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Wed, 7 Oct 2020 11:06:54 -0400 Subject: [PATCH] only send loss if timestamp on data has changed --- salt/telegraf/scripts/zeekcaptureloss.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/salt/telegraf/scripts/zeekcaptureloss.sh b/salt/telegraf/scripts/zeekcaptureloss.sh index 19be68280..f6302566d 100644 --- a/salt/telegraf/scripts/zeekcaptureloss.sh +++ b/salt/telegraf/scripts/zeekcaptureloss.sh @@ -2,9 +2,15 @@ # This script returns the average of all the workers average capture loss to telegraf / influxdb in influx format include nanosecond precision timestamp {%- set WORKERS = salt['pillar.get']('sensor:zeek_lbprocs', salt['pillar.get']('sensor:zeek_pins') | length) %} ZEEKLOG=/host/nsm/zeek/spool/logger/capture_loss.log +LASTCAPTURELOSSLOG=/script/lastcaptureloss.txt if [ -f "$ZEEKLOG" ]; then - LOSS=$(tail -{{WORKERS}} $ZEEKLOG | awk -F, '{print $NF}' | sed 's/}//' | awk -F: '{LOSS += $2 / {{WORKERS}}} END { print LOSS}') - TS=$(tail -1 $ZEEKLOG | jq .ts | sed 's/"//g') - TSNANO=$(echo "$(date -d "$TS" +"%s.%N") 1000000000 * p" | dc | awk -F. {'print $1'}) - echo "zeekcaptureloss loss=$LOSS $TSNANO" + CURRENTTS=$(tail -1 $ZEEKLOG | jq .ts | sed 's/"//g') + if [ -f "$LASTCAPTURELOSSLOG" ]; then + LASTTS=$(cat /script/lastcaptureloss.txt) + if [[ "$LASTTS" != "$CURRENTTS" ]]; then + LOSS=$(tail -{{WORKERS}} $ZEEKLOG | awk -F, '{print $NF}' | sed 's/}//' | awk -F: '{LOSS += $2 / {{WORKERS}}} END { print LOSS}') + echo "zeekcaptureloss loss=$LOSS" + fi + fi + echo "$CURRENTS" > "$LASTCAPTURELOSSLOG" fi \ No newline at end of file