| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- #!/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]}")")"
- json=$(cat <<EOF
- {
- "blocks": [
- {
- "type": "context",
- "elements": [
- {
- "type": "image",
- "image_url": "https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/lgsm/data/alert_discord_logo.jpg",
- "alt_text": "LinuxGSM"
- },
- {
- "type": "mrkdwn",
- "text": "*LinuxGSM Alert*"
- }
- ]
- },
- {
- "type": "context",
- "elements": [
- {
- "type": "image",
- "image_url": "${alerticon}",
- "alt_text": "${alerticonalt}"
- },
- {
- "type": "mrkdwn",
- "text": "${gamename}"
- }
- ]
- },
- {
- "type": "header",
- "text": {
- "type": "plain_text",
- "text": "${servername}",
- "emoji": true
- }
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "*${alertemoji} ${alerttitle} ${alertemoji}*"
- },
- "accessory": {
- "type": "image",
- "image_url": "${alertimage}",
- "alt_text": "${alertimagealt}"
- }
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "*Game*\n${gamename}"
- }
- },
- {
- "type": "section",
- "fields": [
- {
- "type": "mrkdwn",
- "text": "*Map*"
- },
- {
- "type": "mrkdwn",
- "text": "*${alertplayerstitle}*"
- },
- {
- "type": "mrkdwn",
- "text": "${alertmap}"
- },
- {
- "type": "mrkdwn",
- "text": "${alertplayers}"
- }
- ]
- },
- {
- "type": "section",
- "fields": [
- {
- "type": "mrkdwn",
- "text": "*Version*"
- },
- {
- "type": "mrkdwn",
- "text": "*Country*"
- },
- {
- "type": "mrkdwn",
- "text": "${alertversion}"
- },
- {
- "type": "mrkdwn",
- "text": "${country}"
- }
- ]
- },
- {
- "type": "section",
- "fields": [
- {
- "type": "mrkdwn",
- "text": "*Server IP*"
- },
- {
- "type": "mrkdwn",
- "text": "*Hostname*"
- },
- {
- "type": "mrkdwn",
- "text": "${alertip}:${port}"
- },
- {
- "type": "mrkdwn",
- "text": "${HOSTNAME}"
- }
- ]
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "*Trigger Message*\n${alerttriggermessage}"
- }
- },
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": "*More info*\n${alertmoreinfourl}"
- }
- },
- {
- "type": "divider"
- },
- {
- "type": "context",
- "elements": [
- {
- "type": "image",
- "image_url": "https://raw.githubusercontent.com/GameServerManagers/LinuxGSM/master/lgsm/data/alert_discord_logo.jpg",
- "alt_text": "LinuxGSM Logo"
- },
- {
- "type": "plain_text",
- "text": "Powered by LinuxGSM ${version}",
- "emoji": true
- }
- ]
- },
- {
- "type": "divider"
- }
- ]
- }
- 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
|