Created
September 22, 2014 05:49
-
-
Save rjsalts/87c4ff23481d396d8514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Analyze log file and send result to zabbix. | |
# Usage: bash analog_send.sh /path/to/analog.ini /path/to/nginx/access.log | |
HOST=$1 # name of host in Zabbix frontend, *not* IP or hostname! | |
ARGS_FILE=$2 | |
LOG_FILE=$3 | |
LOG_NAME=$(basename $LOG_FILE) | |
ZABBIX='zabbix-proxy.int.dc.au.ubimet.com' | |
analyze() { | |
analog @$ARGS_FILE $LOG_FILE | \ | |
awk " | |
NR==1{n=split(\$0, h,\"\t\")} | |
NR>1{ | |
for(i=2;i<=n;i++) { | |
printf(\"- analog.receive[%s,%s,%s] %f\n\", | |
\"$LOG_NAME\", \$1, h[i],\$i); | |
} | |
} | |
" | tr -cd '[:print:]\n' | |
} | |
# Send the batch to the Zabbix server: | |
OUTPUT=$(zabbix_sender -z $ZABBIX -s $HOST -i <(analyze) ) | |
RETURN=$? # Exit with exit code. | |
if [ $RETURN -ne 0 ] | |
then echo $0 failed with return code: $RETURN | |
echo $OUTPUT | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment