| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/bin/bash
- # LinuxGSM alert_slack.sh module
- # Author: Daniel Gibbs
- # Contributors: http://linuxgsm.com/contrib
- # Website: https://linuxgsm.com
- # Description: Sends Slack alert.
- functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
- if ! command -v jq > /dev/null; then
- fn_print_fail_nl "Sending Slack alert: jq is missing."
- fn_script_log_fatal "Sending Slack alert: jq is missing."
- fi
- json=$(cat <<EOF
- {
- "attachments": [
- {
- "blocks": [
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "*${alertemoji} ${alertsubject} ${alertemoji}*"
- }
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "*${servername}*"
- }
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "${alertbody} \n More info: ${alerturl}"
- }
- },
- {
- "type": "divider"
- },
- {
- "type": "section",
- "fields": [
- {
- "type": "mrkdwn",
- "text": "*Game:* \n ${gamename}"
- },
- {
- "type": "mrkdwn",
- "text": "*Server IP:* \n ${alertip}:${port}"
- }
- ]
- },
- {
- "type": "divider"
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "*Hostname:* ${HOSTNAME}"
- }
- }
- ]
- }
- ]
- }
- EOF
- )
- fn_print_dots "Sending Slack alert"
- slacksend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${slackwebhook}")
- if [ "${slacksend}" == "ok" ]; then
- fn_print_ok_nl "Sending Slack alert"
- fn_script_log_pass "Sending Slack alert"
- else
- fn_print_fail_nl "Sending Slack alert: ${slacksend}"
- fn_script_log_fatal "Sending Slack alert: ${slacksend}"
- fi
|