From f5cacd66b8e5c946bdaf093bdee9319b93429ec8 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Fri, 9 Oct 2020 11:39:44 -0400 Subject: [PATCH 1/2] correct zeekcaptureloss script to work on zeek standalone --- salt/telegraf/scripts/zeekcaptureloss.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/salt/telegraf/scripts/zeekcaptureloss.sh b/salt/telegraf/scripts/zeekcaptureloss.sh index a6f9f3531..dded2ee81 100644 --- a/salt/telegraf/scripts/zeekcaptureloss.sh +++ b/salt/telegraf/scripts/zeekcaptureloss.sh @@ -1,14 +1,24 @@ #!/bin/bash # 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 + +if [ -d "/host/nsm/zeek/spool/logger" ]; then + WORKERS={{ salt['pillar.get']('sensor:zeek_lbprocs', salt['pillar.get']('sensor:zeek_pins') | length) }} + ZEEKLOG=/host/nsm/zeek/spool/logger/capture_loss.log +elif [ -d "/host/nsm/zeek/spool/zeeksa" ]; then + WORKERS=1 + ZEEKLOG=/host/nsm/zeek/spool/zeeksa/capture_loss.log +else + echo 'Zeek capture_loss.log not found' >/dev/stderr + exit 2 +fi + LASTCAPTURELOSSLOG=/var/log/telegraf/lastcaptureloss.txt if [ -f "$ZEEKLOG" ]; then CURRENTTS=$(tail -1 $ZEEKLOG | jq .ts | sed 's/"//g') if [ -f "$LASTCAPTURELOSSLOG" ]; then LASTTS=$(cat $LASTCAPTURELOSSLOG) if [[ "$LASTTS" != "$CURRENTTS" ]]; then - LOSS=$(tail -{{WORKERS}} $ZEEKLOG | awk -F, '{print $NF}' | sed 's/}//' | awk -F: '{LOSS += $2 / {{WORKERS}}} END { print LOSS}') + LOSS=$(tail -$WORKERS $ZEEKLOG | awk -F, '{print $NF}' | sed 's/}//' | awk -F: '{LOSS += $2 / $WORKERS END { print LOSS}') echo "zeekcaptureloss loss=$LOSS" fi fi From ea1324e4988525c4acd1185a0f53cb3d32225adf Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Fri, 9 Oct 2020 11:54:39 -0400 Subject: [PATCH 2/2] fix LOSS calc line --- salt/telegraf/scripts/zeekcaptureloss.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/telegraf/scripts/zeekcaptureloss.sh b/salt/telegraf/scripts/zeekcaptureloss.sh index dded2ee81..a2e350212 100644 --- a/salt/telegraf/scripts/zeekcaptureloss.sh +++ b/salt/telegraf/scripts/zeekcaptureloss.sh @@ -18,7 +18,7 @@ if [ -f "$ZEEKLOG" ]; then if [ -f "$LASTCAPTURELOSSLOG" ]; then LASTTS=$(cat $LASTCAPTURELOSSLOG) if [[ "$LASTTS" != "$CURRENTTS" ]]; then - LOSS=$(tail -$WORKERS $ZEEKLOG | awk -F, '{print $NF}' | sed 's/}//' | awk -F: '{LOSS += $2 / $WORKERS END { print LOSS}') + LOSS=$(tail -$WORKERS $ZEEKLOG | awk -F, '{print $NF}' | sed 's/}//' | awk -v WORKERS=$WORKERS -F: '{LOSS += $2 / WORKERS} END { print LOSS}') echo "zeekcaptureloss loss=$LOSS" fi fi