Skip to content

Instantly share code, notes, and snippets.

@eerien
Last active August 29, 2015 14:05
Show Gist options
  • Save eerien/b5f2f065f81339d9744b to your computer and use it in GitHub Desktop.
Save eerien/b5f2f065f81339d9744b to your computer and use it in GitHub Desktop.
Zabbix externalscript for CloudWatch on AWS (Amazon Web Services). It returns latest statistic value.
#!/bin/bash
# $1: Region
# $2: Namespace
# $3: Dimensions
# $4: Metric Name
# $5: Start Time (before n min)
# $6: Period (min)
# $7: Statistics (SampleCount, Average, Sum, Minimum, Maximum)
# $8: Output value when the result is null
if [ $# -lt 7 ]; then
exit 1
fi
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
output() {
read ret
if [ $ret == "null" ]; then
if [ $1 ]; then echo $1; fi
exit 1
else
echo $ret
fi
}
/usr/local/bin/aws cloudwatch get-metric-statistics --region "$1" --namespace AWS/"$2" --dimensions "$3" --metric-name "$4" --start-time=`date --date '-'"$5"' min' --utc +%FT%TZ` --end-time=`date --utc +%FT%TZ` --period `echo $((60*$6))` --statistics "$7" | jq '.Datapoints | sort_by(.Timestamp)[-1:][0].'"$7" | output $8
@ankush-grover-3pg
Copy link

Hi Erien,

Do you have the template for the above script to associate with a host in Zabbix or how do I use this script with a host in Zabbix. Sorry I am pretty new to Zabbix and eagerly learning it..

Regards

Ankush Grover

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment