Last active
December 27, 2019 07:18
-
-
Save bearice/c135bf0fb19cdb099c4581a3d4b1cd98 to your computer and use it in GitHub Desktop.
simple scripts to merge and delay sending zabbix alert emails.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_msg_to:.[0].to; | |
def get_msg_subject: "\(.[0].subject) and \(.|length) Others"; | |
def get_msg_body: .|map("Subject: \(.subject)\n\(.msg)")|join("\n======================\n"); | |
def to_msg: {to: .|get_msg_to, subject: .|get_msg_subject, body: .|get_msg_body}; | |
def to_script: "aws ses send-email "+(["--region", "us-west-2", "--from", "[email protected]", "--to", .to, "--subject", .subject, "--text", .body]|@sh); | |
group_by(.to)|.[]|to_msg|to_script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -f /var/tmp/delayed-messages.json ]]; then | |
cat /var/tmp/delayed-messages.json| jq -f /usr/lib/zabbix/alertscripts/msggrp.jq -r | bash | |
rm /var/tmp/delayed-messages.json | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script parameters | |
TO="$1" | |
SUBJECT="$2" | |
MESSAGE="$3" | |
function do_send { | |
test -f /var/tmp/delayed-messages.json || echo '[]' > /var/tmp/delayed-messages.json | |
cat /var/tmp/delayed-messages.json | jq --arg to "$TO" --arg subject "$SUBJECT" --arg msg "$MESSAGE" '.+[{$to,$subject,$msg}]' > /var/tmp/delayed-messages.json.new | |
mv /var/tmp/delayed-messages.json.new /var/tmp/delayed-messages.json | |
} | |
if [[ "$TO"x == x ]]; then echo $0 "<to> <subject> <message>"; exit 1; fi | |
(flock 200; do_send;)200>/var/tmp/delayed-messages.lock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment