35
# - Microsoft Team notification by @tioumen
36
# - RocketChat notifications by @Hermsi1337 #3777
37
# - Google Hangouts Chat notifications by @EnzoAkira and @hendrikhofstadt
38
+# - Dynatrace Event by @illumine
39
40
# -----------------------------------------------------------------------------
41
# testing notifications
171
rocketchat
172
sms
173
hangouts
174
+dynatrace
175
"
176
177
# -----------------------------------------------------------------------------
368
# hangouts configs
369
declare -A HANGOUTS_WEBHOOK_URI
370
371
+# dynatrace configs
372
+DYNATRACE_SPACE=
373
+DYNATRACE_SERVER=
374
+DYNATRACE_TOKEN=
375
+DYNATRACE_TAG_VALUE=
376
+DYNATRACE_ANNOTATION_TYPE=
377
+DYNATRACE_EVENT=
378
+SEND_DYNATRACE=
379
+
380
+
381
# load the stock and user configuration files
382
# these will overwrite the variables above
383
515
#shellcheck disable=SC2153
516
{ [ -z "${FLEEP_SERVER}" ] || [ -z "${FLEEP_SENDER}" ]; } && SEND_FLEEP="NO"
517
518
+# check dynatrace
519
+{ [ -z "${DYNATRACE_SPACE}" ] ||
520
+ [ -z "${DYNATRACE_SERVER}" ] ||
521
+ [ -z "${DYNATRACE_TOKEN}" ] ||
522
+ [ -z "${DYNATRACE_TAG_VALUE}" ] ||
523
+ [ -z "${DYNATRACE_EVENT}" ]; } && SEND_DYNATRACE="NO"
524
+
525
+
526
if [ "${SEND_PUSHOVER}" = "YES" ] ||
527
[ "${SEND_SLACK}" = "YES" ] ||
528
[ "${SEND_ROCKETCHAT}" = "YES" ] ||
541
[ "${SEND_PROWL}" = "YES" ] ||
542
[ "${SEND_HANGOUTS}" = "YES" ] ||
543
[ "${SEND_CUSTOM}" = "YES" ] ||
524
- [ "${SEND_MSTEAM}" = "YES" ]; then
544
+ [ "${SEND_MSTEAM}" = "YES" ] ||
545
+ [ "${SEND_DYNATRACE}" = "YES" ]; then
546
# if we need curl, check for the curl command
547
if [ -z "${curl}" ]; then
548
curl="$(command -v curl 2>/dev/null)"
568
SEND_PROWL="NO"
569
SEND_HANGOUTS="NO"
570
SEND_CUSTOM="NO"
571
+ SEND_DYNATRACE="NO"
572
fi
573
fi
574
695
"${SEND_AWSSNS}" \
696
"${SEND_SYSLOG}" \
697
"${SEND_SMS}" \
676
- "${SEND_MSTEAM}"; do
698
+ "${SEND_MSTEAM}" \
699
+ "${SEND_DYNATRACE}"; do
700
+
701
if [ "${method}" == "YES" ]; then
702
proceed=1
703
break
1911
1912
return 1
1913
}
1914
+# -----------------------------------------------------------------------------
1915
+# Dynatrace sender
1916
+send_dynatrace() {
1917
+ local dynatrace_url="${DYNATRACE_SERVER}/e/${DYNATRACE_SPACE}/api/v1/events"
1918
+ local description="NetData Notification for: ${host} ${chart}.${name} is ${status}"
1919
+ local payload=""
1920
+
1921
+ payload=$(cat <<EOF
1922
+{
1923
+ "title": "NetData Alarm from ${host}",
1924
+ "source" : "${DYNATRACE_ANNOTATION_TYPE}",
1925
+ "description" : "${description}",
1926
+ "eventType": "${DYNATRACE_EVENT}",
1927
+ "attachRules":{
1928
+ "tagRule":[{
1929
+ "meTypes":["HOST"],
1930
+ "tags":["${DYNATRACE_TAG_VALUE}"]
1931
+ }]
1932
+ },
1933
+ "customProperties":{
1934
+ "description": "${description}"
1935
+ }
1936
+}
1937
+EOF
1938
+)
1939
+
1940
+ # echo ${payload}
1941
+
1942
+ httpcode=$(docurl -X POST -H "Authorization: Api-token ${DYNATRACE_TOKEN}" -H "Content-Type: application/json" -d "${payload}" ${dynatrace_url})
1943
+ ret=$?
1944
+
1945
+
1946
+ if [ ${ret} -eq 0 ]; then
1947
+ if [ "${httpcode}" = "200" ]; then
1948
+ info "sent ${DYNATRACE_EVENT} to ${DYNATRACE_SERVER}"
1949
+ return 0
1950
+ else
1951
+ warning "Dynatrace ${DYNATRACE_SERVER} responded ${httpcode} notification for: ${host} ${chart}.${name} is ${status} was not sent!"
1952
+ return 1
1953
+ fi
1954
+ else
1955
+ error "failed to sent ${DYNATRACE_EVENT} notification for: ${host} ${chart}.${name} is ${status} to ${DYNATRACE_SERVER} with error code ${ret}."
1956
+ return 1
1957
+ fi
1958
+}
1959
1960
# -----------------------------------------------------------------------------
1961
# prepare the content of the notification
2460
2461
SENT_EMAIL=$?
2462
2463
+# -----------------------------------------------------------------------------
2464
+# send the EVENT to Dynatrace
2465
+send_dynatrace "${host}" "${chart}" "${name}" "${status}"
2466
+SENT_DYNATRACE=$?
2467
+
2468
+
2469
# -----------------------------------------------------------------------------
2470
# let netdata know
2471
for state in "${SENT_EMAIL}" \
2491
"${SENT_AWSSNS}" \
2492
"${SENT_SYSLOG}" \
2493
"${SENT_SMS}" \
2419
- "${SENT_MSTEAM}"; do
2494
+ "${SENT_MSTEAM}" \
2495
+ "${SENT_DYNATRACE}"; do
2496
if [ "${state}" -eq 0 ]; then
2497
# we sent something
2498
exit 0