Skip to content

Instantly share code, notes, and snippets.

@eerien eerien/cloudwatch.sh

Last active Aug 29, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

ankush-grover-3pg commented Mar 4, 2015

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
You can’t perform that action at this time.