-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathddhelper.sh
executable file
·111 lines (107 loc) · 3.81 KB
/
ddhelper.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
#set -xe
function sentEvent() {
if [ -z "$DATADOG_API_KEY" ]
then
echo "ERROR: Please specify the DATADOG_API_KEY as env variable."
exit -1
fi
if [ -z "$1" ]
then
echo "ERROR: Please specify the host as the first argument."
else
if [ -z "$2" ]
then
echo "ERROR: Please specify the coin as the second argument."
else
if [ -z "$3" ]
then
echo "ERROR: Please specify the title as the third argument."
else
if [ -z "$4" ]
then
echo "ERROR: Please specify the message as the fourth argument."
else
if [ -z "$5" ]
then
echo "ERROR: Please specify the role as the fifth argument."
else
if [ -z "$6" ]
then
echo "ERROR: Please specify the username as the sixth argument."
exit -1
else
if [ -z "$7" ]
then
alertType=info
else
alertType=$7
fi
echo "$3=$4"
/usr/bin/curl -sX POST -H "Content-type: application/json" \
-d "{
\"title\": \"[$3][$5][$2][$1]\",
\"text\": \"$4\",
\"priority\": \"normal\",
\"tags\":[\"coin:$2\", \"role:$5\", \"user:$6\", \"eventType:$3\"],
\"alert_type\": \"$alertType\"
}" \
"https://api.datadoghq.com/api/v1/events?api_key=$DATADOG_API_KEY" > /dev/null
fi
fi
fi
fi
fi
fi
}
function sentMetric() {
if [ -z "$DATADOG_API_KEY" ]
then
echo "ERROR: Please specify the DATADOG_API_KEY as env variable."
exit -1
fi
if [ -z "$1" ]
then
echo "ERROR: Please specify the host as the first argument."
else
if [ -z "$2" ]
then
echo "ERROR: Please specify the coin as the second argument."
else
if [ -z "$3" ]
then
echo "ERROR: Please specify the metricname as the third argument."
else
if [ -z "$4" ]
then
echo "ERROR: Please specify the value as the fourth argument."
else
if [ -z "$5" ]
then
echo "ERROR: Please specify the role as the fifth argument."
else
if [ -z "$6" ]
then
echo "ERROR: Please specify the username as the sixth argument."
exit -1
else
currenttime=$(/bin/date +%s)
echo "$3=$4"
/usr/bin/curl -sX POST -H "Content-type: application/json" \
-d "{ \"series\" :
[{
\"metric\":\"$3\",
\"points\":[[$currenttime, $4]],
\"type\":\"gauge\",
\"host\":\"$1\",
\"tags\":[\"coin:$2\", \"role:$5\", \"user:$6\"]
}]
}" \
"https://app.datadoghq.com/api/v1/series?api_key=$DATADOG_API_KEY" > /dev/null
fi
fi
fi
fi
fi
fi
}