Skip to content

Instantly share code, notes, and snippets.

@bearice
Last active December 27, 2019 07:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bearice/c135bf0fb19cdb099c4581a3d4b1cd98 to your computer and use it in GitHub Desktop.
simple scripts to merge and delay sending zabbix alert emails.
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", "zabbix@example.com", "--to", .to, "--subject", .subject, "--text", .body]|@sh);
group_by(.to)|.[]|to_msg|to_script
#!/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
#!/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