-
Notifications
You must be signed in to change notification settings - Fork 130
/
dd_public_ip.sh
48 lines (42 loc) · 1.32 KB
/
dd_public_ip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
function usage
{
echo 'usage dd-public-ip-tag.sh --api_key "<key>" --app_key "<key>"'
}
#### Main
api_key=""
app_key=""
while [ "$1" != "" ]; do
case $1 in
-i | --api_key ) shift
api_key=$1
;;
-p | --app_key ) shift
app_key=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
if [ "$api_key" = "" -o "$app_key" = "" ]; then
usage
exit 1
fi
private_ip=`wget -q -O - http://instance-data/latest/meta-data/local-ipv4`
private_ip='ip-'`echo $private_ip | sed 's/\./-/g'`
instance_id=`wget -q -O - http://instance-data/latest/meta-data/instance-id`
public_ip=`wget -qO- http://instance-data/latest/meta-data/public-ipv4`
tag='"tags" : ["public_ip:'$public_ip'"]'
echo 'api_key: '$api_key
echo 'app_key: '$app_key
echo 'instance_id: '$instance_id
echo 'public_ip: '$public_ip
curl -X POST -H "Content-type: application/json" \
-d '{
"tags" : ["public_ip:'$public_ip'"]
}' \
"https://app.datadoghq.com/api/v1/tags/hosts/${instance_id}?api_key=${api_key}&application_key=${app_key}"