Browse Source

space

pull/3051/head
Daniel Gibbs 5 years ago
parent
commit
4d102eca2a
  1. 76
      lgsm/functions/alert_discord.sh
  2. 14
      lgsm/functions/alert_ifttt.sh
  3. 16
      lgsm/functions/alert_pushbullet.sh
  4. 64
      lgsm/functions/alert_rocketchat.sh
  5. 108
      lgsm/functions/alert_slack.sh
  6. 16
      lgsm/functions/alert_telegram.sh

76
lgsm/functions/alert_discord.sh

@ -8,44 +8,44 @@
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
if ! command -v jq > /dev/null; then if ! command -v jq > /dev/null; then
fn_print_fail_nl "Sending Discord alert: jq is missing." fn_print_fail_nl "Sending Discord alert: jq is missing."
fn_script_log_fatal "Sending Discord alert: jq is missing." fn_script_log_fatal "Sending Discord alert: jq is missing."
fi fi
json=$(cat <<EOF json=$(cat <<EOF
{ {
"username":"LinuxGSM", "username":"LinuxGSM",
"avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png", "avatar_url":"https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png",
"file":"content", "file":"content",
"embeds": [{ "embeds": [{
"color": "2067276", "color": "2067276",
"author": { "author": {
"name": "${alertemoji} ${alertsubject} ${alertemoji}", "name": "${alertemoji} ${alertsubject} ${alertemoji}",
"icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"}, "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.png"},
"title": "${escaped_servername}", "title": "${escaped_servername}",
"description": ${escaped_alertbody}, "description": ${escaped_alertbody},
"url": "", "url": "",
"type": "content", "type": "content",
"thumbnail": {}, "thumbnail": {},
"footer": {"text": "Hostname: ${HOSTNAME} / More info: ${alerturl}", "icon_url": ""}, "footer": {"text": "Hostname: ${HOSTNAME} / More info: ${alerturl}", "icon_url": ""},
"fields": [ "fields": [
{ {
"name": "Game", "name": "Game",
"value": "${gamename}", "value": "${gamename}",
"inline": true "inline": true
}, },
{ {
"name": "Server IP", "name": "Server IP",
"value": "[${alertip}:${port}](https://www.gametracker.com/server_info/${alertip}:${port})", "value": "[${alertip}:${port}](https://www.gametracker.com/server_info/${alertip}:${port})",
"inline": true "inline": true
}, },
{ {
"name": "Server Name", "name": "Server Name",
"value": ${escaped_servername}, "value": ${escaped_servername},
"inline": true "inline": true
} }
] ]
}] }]
} }
EOF EOF
) )
@ -55,9 +55,9 @@ fn_print_dots "Sending Discord alert"
discordsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${discordwebhook}") discordsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${discordwebhook}")
if [ "${discordsend}" ]; then if [ "${discordsend}" ]; then
fn_print_fail_nl "Sending Discord alert: ${discordsend}" fn_print_fail_nl "Sending Discord alert: ${discordsend}"
fn_script_log_fatal "Sending Discord alert: ${discordsend}" fn_script_log_fatal "Sending Discord alert: ${discordsend}"
else else
fn_print_ok_nl "Sending Discord alert" fn_print_ok_nl "Sending Discord alert"
fn_script_log_pass "Sending Discord alert" fn_script_log_pass "Sending Discord alert"
fi fi

14
lgsm/functions/alert_ifttt.sh

@ -8,9 +8,9 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
json=$(cat <<EOF json=$(cat <<EOF
{ {
"value1": "${selfname}", "value1": "${selfname}",
"value2": "${alertemoji} ${alertsubject} ${alertemoji}", "value2": "${alertemoji} ${alertsubject} ${alertemoji}",
"value3": "Message: \n${escaped_alertbody}\n\nGame: \n${gamename}\n\nServer name: \n${escaped_servername}\n\nHostname: \n${HOSTNAME}\n\nServer IP: \n${alertip}:${port}\n\nMore info: \n${alerturl}" "value3": "Message: \n${escaped_alertbody}\n\nGame: \n${gamename}\n\nServer name: \n${escaped_servername}\n\nHostname: \n${HOSTNAME}\n\nServer IP: \n${alertip}:${port}\n\nMore info: \n${alerturl}"
} }
EOF EOF
) )
@ -19,9 +19,9 @@ fn_print_dots "Sending IFTTT alert"
iftttsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://maker.ifttt.com/trigger/${iftttevent}/with/key/${ifttttoken}" | grep "Bad Request") iftttsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://maker.ifttt.com/trigger/${iftttevent}/with/key/${ifttttoken}" | grep "Bad Request")
if [ "${iftttsend}" ]; then if [ "${iftttsend}" ]; then
fn_print_fail_nl "Sending IFTTT alert: ${pushbulletsend}" fn_print_fail_nl "Sending IFTTT alert: ${pushbulletsend}"
fn_script_log_fatal "Sending IFTTT alert: ${pushbulletsend}" fn_script_log_fatal "Sending IFTTT alert: ${pushbulletsend}"
else else
fn_print_ok_nl "Sending IFTTT alert" fn_print_ok_nl "Sending IFTTT alert"
fn_script_log_pass "Sent IFTTT alert" fn_script_log_pass "Sent IFTTT alert"
fi fi

16
lgsm/functions/alert_pushbullet.sh

@ -8,10 +8,10 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
json=$(cat <<EOF json=$(cat <<EOF
{ {
"channel_tag": "${channeltag}", "channel_tag": "${channeltag}",
"type": "note", "type": "note",
"title": "${alertemoji} ${alertsubject} ${alertemoji}", "title": "${alertemoji} ${alertsubject} ${alertemoji}",
"body": "Message\n${escaped_alertbody}\n\nGame\n${gamename}\n\nServer name\n${escaped_servername}\n\nHostname\n${HOSTNAME}\n\nServer IP\n${alertip}:${port}\n\nMore info\n${alerturl}" "body": "Message\n${escaped_alertbody}\n\nGame\n${gamename}\n\nServer name\n${escaped_servername}\n\nHostname\n${HOSTNAME}\n\nServer IP\n${alertip}:${port}\n\nMore info\n${alerturl}"
} }
EOF EOF
) )
@ -20,9 +20,9 @@ fn_print_dots "Sending Pushbullet alert"
pushbulletsend=$(curl -sSL -u """${pushbullettoken}"":" -H "Content-Type: application/json" -X POST -d """${json}""" "https://api.pushbullet.com/v2/pushes" | grep "error_code") pushbulletsend=$(curl -sSL -u """${pushbullettoken}"":" -H "Content-Type: application/json" -X POST -d """${json}""" "https://api.pushbullet.com/v2/pushes" | grep "error_code")
if [ "${pushbulletsend}" ]; then if [ "${pushbulletsend}" ]; then
fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}" fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}"
fn_script_log_fatal "Sending Pushbullet alert: ${pushbulletsend}" fn_script_log_fatal "Sending Pushbullet alert: ${pushbulletsend}"
else else
fn_print_ok_nl "Sending Pushbullet alert" fn_print_ok_nl "Sending Pushbullet alert"
fn_script_log_pass "Sent Pushbullet alert" fn_script_log_pass "Sent Pushbullet alert"
fi fi

64
lgsm/functions/alert_rocketchat.sh

@ -7,38 +7,38 @@
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
if ! command -v jq > /dev/null; then if ! command -v jq > /dev/null; then
fn_print_fail_nl "Sending Rocketchat alert: jq is missing." fn_print_fail_nl "Sending Rocketchat alert: jq is missing."
fn_script_log_fatal "Sending Rocketchat alert: jq is missing." fn_script_log_fatal "Sending Rocketchat alert: jq is missing."
fi fi
json=$(cat <<EOF json=$(cat <<EOF
{ {
"alias": "LinuxGSM", "alias": "LinuxGSM",
"text": "*${alertemoji} ${alertsubject} ${alertemoji}* + \n ${escaped_alertbody}", "text": "*${alertemoji} ${alertsubject} ${alertemoji}* + \n ${escaped_alertbody}",
"attachments": [ "attachments": [
{ {
"title": "Linuxgsm Alert", "title": "Linuxgsm Alert",
"text": "Hostname: ${HOSTNAME}", "text": "Hostname: ${HOSTNAME}",
"color": "#36a64f", "color": "#36a64f",
"fields": [ "fields": [
{ {
"short": true, "short": true,
"title": "Game:", "title": "Game:",
"value": "${gamename}" "value": "${gamename}"
}, },
{ {
"short": true, "short": true,
"title": "Server IP:", "title": "Server IP:",
"value": "${alertip}:${port}" "value": "${alertip}:${port}"
}, },
{ {
"short": true, "short": true,
"title": "Server Name:", "title": "Server Name:",
"value": "${escaped_servername}" "value": "${escaped_servername}"
} }
] ]
} }
] ]
} }
EOF EOF
) )
@ -48,9 +48,9 @@ fn_print_dots "Sending Rocketchat alert"
rocketlaunch=$(curl -sSL -H "Content-Type:application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${rocketchatwebhook}") rocketlaunch=$(curl -sSL -H "Content-Type:application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${rocketchatwebhook}")
if [ "${rocketlaunch}" == "ok" ]; then if [ "${rocketlaunch}" == "ok" ]; then
fn_print_ok_nl "Sending Rocketchat alert" fn_print_ok_nl "Sending Rocketchat alert"
fn_script_log_pass "Sending Rocketchat alert" fn_script_log_pass "Sending Rocketchat alert"
else else
fn_print_fail_nl "Sending Rocketchat alert: ${rocketlaunch}" fn_print_fail_nl "Sending Rocketchat alert: ${rocketlaunch}"
fn_script_log_fatal "Sending Rocketchat alert: ${rocketlaunch}" fn_script_log_fatal "Sending Rocketchat alert: ${rocketlaunch}"
fi fi

108
lgsm/functions/alert_slack.sh

@ -7,60 +7,60 @@
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
if ! command -v jq > /dev/null; then if ! command -v jq > /dev/null; then
fn_print_fail_nl "Sending Slack alert: jq is missing." fn_print_fail_nl "Sending Slack alert: jq is missing."
fn_script_log_fatal "Sending Slack alert: jq is missing." fn_script_log_fatal "Sending Slack alert: jq is missing."
fi fi
json=$(cat <<EOF json=$(cat <<EOF
{ {
"attachments": [ "attachments": [
{ {
"color": "#36a64f", "color": "#36a64f",
"blocks": [ "blocks": [
{ {
"type": "section", "type": "section",
"text": { "text": {
"type": "mrkdwn", "type": "mrkdwn",
"text": "*LinuxGSM Alert*" "text": "*LinuxGSM Alert*"
} }
}, },
{ {
"type": "section", "type": "section",
"text": { "text": {
"type": "mrkdwn", "type": "mrkdwn",
"text": "*${alertemoji} ${alertsubject} ${alertemoji}* \n ${escaped_alertbody}" "text": "*${alertemoji} ${alertsubject} ${alertemoji}* \n ${escaped_alertbody}"
} }
}, },
{ {
"type": "divider" "type": "divider"
}, },
{ {
"type": "section", "type": "section",
"fields": [ "fields": [
{ {
"type": "mrkdwn", "type": "mrkdwn",
"text": "*Game:* \n ${gamename}" "text": "*Game:* \n ${gamename}"
}, },
{ {
"type": "mrkdwn", "type": "mrkdwn",
"text": "*Server IP:* \n ${alertip}:${port}" "text": "*Server IP:* \n ${alertip}:${port}"
}, },
{ {
"type": "mrkdwn", "type": "mrkdwn",
"text": "*Server Name:* \n ${escaped_servername}" "text": "*Server Name:* \n ${escaped_servername}"
} }
] ]
}, },
{ {
"type": "section", "type": "section",
"text": { "text": {
"type": "mrkdwn", "type": "mrkdwn",
"text": "Hostname: ${HOSTNAME} / More info: ${alerturl}" "text": "Hostname: ${HOSTNAME} / More info: ${alerturl}"
} }
} }
] ]
} }
] ]
} }
EOF EOF
) )
@ -70,9 +70,9 @@ fn_print_dots "Sending Slack alert"
slacksend=$(curl -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${slackwebhook}") slacksend=$(curl -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${slackwebhook}")
if [ "${slacksend}" == "ok" ]; then if [ "${slacksend}" == "ok" ]; then
fn_print_ok_nl "Sending Slack alert" fn_print_ok_nl "Sending Slack alert"
fn_script_log_pass "Sending Slack alert" fn_script_log_pass "Sending Slack alert"
else else
fn_print_fail_nl "Sending Slack alert: ${slacksend}" fn_print_fail_nl "Sending Slack alert: ${slacksend}"
fn_script_log_fatal "Sending Slack alert: ${slacksend}" fn_script_log_fatal "Sending Slack alert: ${slacksend}"
fi fi

16
lgsm/functions/alert_telegram.sh

@ -11,10 +11,10 @@ escaped_alertbody=$(echo -n "${alertbody}" | jq -sRr "@json")
json=$(cat <<EOF json=$(cat <<EOF
{ {
"chat_id": "${telegramchatid}", "chat_id": "${telegramchatid}",
"parse_mode": "HTML", "parse_mode": "HTML",
"text": "<b>${alertemoji} ${alertsubject} ${alertemoji}</b>\n\n<b>Message</b>\n${escaped_alertbody}\n\n<b>Game</b>\n${gamename}\n\n<b>Server name</b>\n${escaped_servername}\n\n<b>Hostname</b>\n${HOSTNAME}\n\n<b>Server IP</b>\n<a href='https://www.gametracker.com/server_info/${alertip}:${port}'>${alertip}:${port}</a>\n\n<b>More info</b>\n<a href='${alerturl}'>${alerturl}</a>", "text": "<b>${alertemoji} ${alertsubject} ${alertemoji}</b>\n\n<b>Message</b>\n${escaped_alertbody}\n\n<b>Game</b>\n${gamename}\n\n<b>Server name</b>\n${escaped_servername}\n\n<b>Hostname</b>\n${HOSTNAME}\n\n<b>Server IP</b>\n<a href='https://www.gametracker.com/server_info/${alertip}:${port}'>${alertip}:${port}</a>\n\n<b>More info</b>\n<a href='${alerturl}'>${alerturl}</a>",
"disable_web_page_preview": "yes", "disable_web_page_preview": "yes",
EOF EOF
) )
@ -22,9 +22,9 @@ fn_print_dots "Sending Telegram alert"
telegramsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """${json}""" ${curlcustomstring} "https://api.telegram.org/bot${telegramtoken}/sendMessage" | grep "error_code") telegramsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """${json}""" ${curlcustomstring} "https://api.telegram.org/bot${telegramtoken}/sendMessage" | grep "error_code")
if [ "${telegramsend}" ]; then if [ "${telegramsend}" ]; then
fn_print_fail_nl "Sending Telegram alert: ${telegramsend}" fn_print_fail_nl "Sending Telegram alert: ${telegramsend}"
fn_script_log_fatal "Sending Telegram alert: ${telegramsend}" fn_script_log_fatal "Sending Telegram alert: ${telegramsend}"
else else
fn_print_ok_nl "Sending Telegram alert" fn_print_ok_nl "Sending Telegram alert"
fn_script_log_pass "Sent Telegram alert" fn_script_log_pass "Sent Telegram alert"
fi fi

Loading…
Cancel
Save