Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from kreatoo/main
Browse files Browse the repository at this point in the history
monomail-postal-health.sh, monodb-mysql/pgsql-health.sh: Add multiple alarm support
  • Loading branch information
omertahaoztop authored Apr 18, 2024
2 parents 451a86f + ae5a095 commit 98643cb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .bin/monodb-mysql-health.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ALARM_WEBHOOK_URL=example.com
ALARM_WEBHOOK_URLS=("example.com")
ALARM_BOT_API_URL=https://example.com
[email protected]
ALARM_BOT_API_KEY=testkey
ALARM_BOT_USER_EMAIL=[email protected]
ALARM_BOT_USER_EMAILS=("[email protected]")
IDENTIFIER="test"
SEND_ALARM=1
SEND_DM_ALARM=1
Expand Down
4 changes: 2 additions & 2 deletions .bin/monodb-pgsql-health.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ALARM_WEBHOOK_URL=example.com
ALARM_WEBHOOK_URLS=("example.com")
ALARM_BOT_API_URL=https://example.com
[email protected]
ALARM_BOT_API_KEY=testkey
ALARM_BOT_USER_EMAIL=[email protected]
ALARM_BOT_USER_EMAILS=("[email protected]")
IDENTIFIER="test"
PATRONI_API="http://localhost:8008/cluster"
SEND_ALARM=1
Expand Down
9 changes: 7 additions & 2 deletions .bin/monomail-postal-health.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
ALARM_WEBHOOK_URL=example.com
ALARM_WEBHOOK_URLS=("example.com")
ALARM_BOT_API_URL=https://example.com
[email protected]
ALARM_BOT_API_KEY=testkey
ALARM_BOT_USER_EMAILS=("[email protected]")
IDENTIFIER="test"
SEND_ALARM=1
SEND_DM_ALARM=1
LOAD_LIMIT=10
RAM_LIMIT=90
message_threshold=100
rmq_port=15672
rmq_port=15672
22 changes: 15 additions & 7 deletions monodb/monodb-mysql-health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ function print_colour() {

function alarm() {
if [ "$SEND_ALARM" == "1" ]; then
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$ALARM_WEBHOOK_URL" 1>/dev/null
if [ -z "$ALARM_WEBHOOK_URLS" ]; then
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$ALARM_WEBHOOK_URL" 1>/dev/null
else
for webhook in "${ALARM_WEBHOOK_URLS[@]}"; do
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$webhook" 1>/dev/null
done
fi
fi

if [ "$SEND_DM_ALARM" = "1" ] && [ -n "$ALARM_BOT_API_KEY" ] && [ -n "$ALARM_BOT_EMAIL" ] && [ -n "$ALARM_BOT_API_URL" ] && [ -n "$ALARM_BOT_USER_EMAIL" ]; then
curl -s -X POST "$ALARM_BOT_API_URL"/api/v1/messages \
-u "$ALARM_BOT_EMAIL:$ALARM_BOT_API_KEY" \
--data-urlencode type=direct \
--data-urlencode "to=$ALARM_BOT_USER_EMAIL" \
--data-urlencode "content=$1" 1> /dev/null
if [ "$SEND_DM_ALARM" = "1" ] && [ -n "$ALARM_BOT_API_KEY" ] && [ -n "$ALARM_BOT_EMAIL" ] && [ -n "$ALARM_BOT_API_URL" ] && [ -n "$ALARM_BOT_USER_EMAILS" ]; then
for user_email in "${ALARM_BOT_USER_EMAILS[@]}"; do
curl -s -X POST "$ALARM_BOT_API_URL"/api/v1/messages \
-u "$ALARM_BOT_EMAIL:$ALARM_BOT_API_KEY" \
--data-urlencode type=direct \
--data-urlencode "to=$user_email" \
--data-urlencode "content=$1" 1> /dev/null
done
fi
}

Expand Down
22 changes: 15 additions & 7 deletions monodb/monodb-pgsql-health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ function print_colour() {

function alarm() {
if [ "$SEND_ALARM" == "1" ]; then
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$ALARM_WEBHOOK_URL" 1>/dev/null
if [ -z "$ALARM_WEBHOOK_URLS" ]; then
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$ALARM_WEBHOOK_URL" 1>/dev/null
else
for webhook in "${ALARM_WEBHOOK_URLS[@]}"; do
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$webhook" 1>/dev/null
done
fi
fi

if [ "$SEND_DM_ALARM" = "1" ] && [ -n "$ALARM_BOT_API_KEY" ] && [ -n "$ALARM_BOT_EMAIL" ] && [ -n "$ALARM_BOT_API_URL" ] && [ -n "$ALARM_BOT_USER_EMAIL" ]; then
curl -s -X POST "$ALARM_BOT_API_URL"/api/v1/messages \
-u "$ALARM_BOT_EMAIL:$ALARM_BOT_API_KEY" \
--data-urlencode type=direct \
--data-urlencode "to=$ALARM_BOT_USER_EMAIL" \
--data-urlencode "content=$1" 1> /dev/null
if [ "$SEND_DM_ALARM" = "1" ] && [ -n "$ALARM_BOT_API_KEY" ] && [ -n "$ALARM_BOT_EMAIL" ] && [ -n "$ALARM_BOT_API_URL" ] && [ -n "$ALARM_BOT_USER_EMAILS" ]; then
for user_email in "${ALARM_BOT_USER_EMAILS[@]}"; do
curl -s -X POST "$ALARM_BOT_API_URL"/api/v1/messages \
-u "$ALARM_BOT_EMAIL:$ALARM_BOT_API_KEY" \
--data-urlencode type=direct \
--data-urlencode "to=$user_email" \
--data-urlencode "content=$1" 1> /dev/null
done
fi
}

Expand Down
23 changes: 20 additions & 3 deletions monomail/monomail-postal-health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,27 @@ RESET=$(tput sgr0)

if [ "$1" == "test" ]; then postal_config="./test.yaml"; else postal_config=/opt/postal/config/postal.yml; fi


function alarm() {
if [ "$SEND_ALARM" == "1" ]; then
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$ALARM_WEBHOOK_URL" 1>/dev/null
fi
if [ "$SEND_ALARM" == "1" ]; then
if [ -z "$ALARM_WEBHOOK_URLS" ]; then
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$ALARM_WEBHOOK_URL" 1>/dev/null
else
for webhook in "${ALARM_WEBHOOK_URLS[@]}"; do
curl -fsSL -X POST -H "Content-Type: application/json" -d "{\"text\": \"$1\"}" "$webhook" 1>/dev/null
done
fi
fi

if [ "$SEND_DM_ALARM" = "1" ] && [ -n "$ALARM_BOT_API_KEY" ] && [ -n "$ALARM_BOT_EMAIL" ] && [ -n "$ALARM_BOT_API_URL" ] && [ -n "$ALARM_BOT_USER_EMAILS" ]; then
for user_email in "${ALARM_BOT_USER_EMAILS[@]}"; do
curl -s -X POST "$ALARM_BOT_API_URL"/api/v1/messages \
-u "$ALARM_BOT_EMAIL:$ALARM_BOT_API_KEY" \
--data-urlencode type=direct \
--data-urlencode "to=$user_email" \
--data-urlencode "content=$1" 1> /dev/null
done
fi
}

function get_time_diff() {
Expand Down

0 comments on commit 98643cb

Please sign in to comment.