245
SEND_PD="YES"
246
SEND_FLEEP="YES"
247
SEND_IRC="YES"
248
+SEND_AWSSNS="YES"
249
SEND_SYSLOG="NO"
250
SEND_CUSTOM="YES"
251
335
DEFAULT_RECIPIENT_FLEEP=
336
declare -A role_recipients_fleep=()
337
338
+# Amazon SNS configs
339
+DEFAULT_RECIPIENT_AWSSNS=
340
+AWSSNS_MESSAGE_FORMAT=
341
+declare -A role_recipients_awssns=()
342
+
343
# syslog configs
344
SYSLOG_FACILITY=
345
declare -A role_recipients_syslog=()
458
declare -A arr_fleep=()
459
declare -A arr_irc=()
460
declare -A arr_syslog=()
461
+declare -A arr_awssns=()
462
463
# netdata may call us with multiple roles, and roles may have multiple but
464
# overlapping recipients - so, here we find the unique recipients.
604
[ "${r}" != "disabled" ] && filter_recipient_by_criticality irc "${r}" && arr_irc[${r/|*/}]="1"
605
done
606
607
+ # awssns
608
+ a="${role_recipients_awssns[${x}]}"
609
+ [ -z "${a}" ] && a="${DEFAULT_RECIPIENT_awssns}"
610
+ for r in ${a//,/ }
611
+ do
612
+ [ "${r}" != "disabled" ] && filter_recipient_by_criticality awssns "${r}" && arr_awssns[${r/|*/}]="1"
613
+ done
614
+
615
# syslog
616
a="${role_recipients_syslog[${x}]}"
617
[ -z "${a}" ] && a="${DEFAULT_RECIPIENT_SYSLOG}"
707
to_irc="${!arr_irc[*]}"
708
[ -z "${to_irc}" ] && SEND_IRC="NO"
709
710
+# build the list of awssns recipients (facilities, servers, and prefixes)
711
+to_awssns="${!arr_awssns[*]}"
712
+[ -z "${to_awssns}" ] && SEND_AWSSNS="NO"
713
+
714
# build the list of syslog recipients (facilities, servers, and prefixes)
715
to_syslog="${!arr_syslog[*]}"
716
[ -z "${to_syslog}" ] && SEND_SYSLOG="NO"
841
fi
842
fi
843
844
+# if we need aws, check for the aws command
845
+if [ "${SEND_AWSSNS}" = "YES" -a -z "${aws}" ]
846
+ then
847
+ aws="$(which aws 2>/dev/null || command -v aws 2>/dev/null)"
848
+ if [ -z "${aws}" ]
849
+ then
850
+ debug "Cannot find aws command in the system path. Disabling Amazon SNS notifications."
851
+ SEND_AWSSNS="NO"
852
+ fi
853
+fi
854
+
855
# check that we have at least a method enabled
856
if [ "${SEND_EMAIL}" != "YES" \
857
-a "${SEND_PUSHOVER}" != "YES" \
871
-a "${SEND_FLEEP}" != "YES" \
872
-a "${SEND_CUSTOM}" != "YES" \
873
-a "${SEND_IRC}" != "YES" \
874
+ -a "${SEND_AWSSNS}" != "YES" \
875
-a "${SEND_SYSLOG}" != "YES" \
876
-a "${SEND_MSTEAM}" != "YES" \
877
]
1816
return 1
1817
}
1818
1819
+# -----------------------------------------------------------------------------
1820
+# Amazon SNS sender
1821
+
1822
+send_awssns() {
1823
+ local targets="${1}" message='' sent=0 region=''
1824
+ local default_format="${status} on ${host} at ${date}: ${chart} ${value_string}"
1825
+
1826
+ [ "${SEND_AWSSNS}" = "YES" ] || return 1
1827
+
1828
+ message=${AWSSNS_MESSAGE_FORMAT:-${default_format}}
1829
+
1830
+ for target in ${targets} ; do
1831
+ # Extract the region from the target ARN. We need to explicitly specify the region so that it matches up correctly.
1832
+ region="$(echo ${target} | cut -f 4 -d ':')"
1833
+ ${aws} --region "${region}" --subject "${host} ${status_message} - ${name//_/ } - ${chart}" --message "${message}" --target-arn ${target} &>/dev/null
1834
+ if [ $? = 0 ]; then
1835
+ info "sent Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
1836
+ sent=$((${sent} + 1))
1837
+ else
1838
+ error "failed to send Amazon SNS notification for: ${host} ${chart}.${name} is ${status} to '${target}'"
1839
+ fi
1840
+ done
1841
+
1842
+ [ ${sent} -gt 0 ] && return 0
1843
+
1844
+ return 1
1845
+}
1846
+
1847
# -----------------------------------------------------------------------------
1848
# syslog sender
1849
2198
SENT_HIPCHAT=$?
2199
2200
2201
+# -----------------------------------------------------------------------------
2202
+# send the Amazon SNS message
2203
+
2204
+send_awssns ${to_awssns}
2205
+
2206
+SENT_AWSSNS=$?
2207
+
2208
+
2209
# -----------------------------------------------------------------------------
2210
# send the syslog message
2211
2358
-o ${SENT_PD} -eq 0 \
2359
-o ${SENT_FLEEP} -eq 0 \
2360
-o ${SENT_IRC} -eq 0 \
2361
+ -o ${SENT_AWSSNS} -eq 0 \
2362
-o ${SENT_CUSTOM} -eq 0 \
2363
-o ${SENT_SYSLOG} -eq 0 \
2364
]