Now you can run script on watchdog startup. File structure changed on *nix. Some changes in config file and scripts, please check on upgrade.

Now you can run script on watchdog startup. File structure changed on *nix. Some changes in config file and scripts, please check on upgrade.
This commit is contained in:
2022-10-29 16:57:57 +03:00
parent fa19c8327b
commit f1d16093b6
15 changed files with 362 additions and 216 deletions

View File

@@ -1,29 +1,25 @@
[main]
check_interval = 10
rules_count = 3
[notifications]
email = admin@server.local
command = send-telegram <message>
service_start = true
on_start_command = /etc/cai-watchdog/on-start
[rule1]
service = Test1
uri = http://127.0.0.1:3000/api/v1/
process =
email = admin@server.local
command = send-telegram <message>
command = /etc/cai-watchdog/send-telegram <message>
[rule2]
service = Test2
uri = http://127.0.0.1:3300/api/v1/
process =
email = admin@server.local
command = send-telegram <message>
command = /etc/cai-watchdog/send-telegram <message>
[rule3]
service = Apache
uri =
process = httpd
email = admin@server.local
command = send-telegram <message>
command = /etc/cai-watchdog/send-telegram <message>

View File

@@ -0,0 +1,5 @@
#!/bin/bash
ICON_INFO=$(echo -e "\U2139")
ICON_WARNING=$(echo -e "\U26A0")
ICON_OK=$(echo -e "\U2705")
ICON_FAIL=$(echo -e "\U274C")

View File

@@ -0,0 +1,4 @@
#!/bin/bash
APP_PATH=/etc/cai-watchdog
source ${APP_PATH}/inc-icons
${APP_PATH}/send-telegram "${ICON_INFO} ATTENTION! Watchdog is stopped!"

View File

@@ -0,0 +1,4 @@
#!/bin/bash
APP_PATH=/etc/cai-watchdog
source ${APP_PATH}/inc-icons
${APP_PATH}/send-telegram "${ICON_WARNING} ATTENTION! Watchdog is stopped!"

View File

@@ -0,0 +1,41 @@
#!/bin/bash
rcpt=$1
subj=$2
message=$3
ARGS=$(xargs echo $(perl -anle 's/^[^:]+//g && s/:\s+//g && print' /etc/cai-watchdog/email.conf) < /dev/null)
set -- $ARGS "$@";
declare -A email;
email['user']=$1
email['pass']=$2
email['smtp']=$3
email['port']=$4
email_content='From: "Watchdog" <'"${email['user']}"'>
To: "Subscriber" <'"${rcpt}"'>
Subject: '"${subj}"'
Date: '"$(date)"'
'"${message}"'
-----
'"${HOSTNAME}"'
';
echo "$email_content" | curl -s \ # -vvv \
--url "smtps://${email['smtp']}:${email['port']}" \
--user "${email['user']}:${email['pass']}" \
--mail-from "${email['user']}" \
--mail-rcpt "${rcpt}" \
--upload-file - \
-T -
if [[ $? == 0 ]]; then
echo;
echo 'okay';
else
echo "curl error code $?";
man curl | grep "^ \+$? \+"
fi

View File

@@ -0,0 +1,28 @@
#!/bin/bash
SCRIPT_NAME=$0
MESSAGE_TEXT=$1
if [ "$#" -ne 1 ]; then
echo "You can pass only one argument. For string with spaces put it on quotes"
exit 0
fi
ARGS=$(xargs echo $(perl -anle 's/^[^:]+//g && s/:\s+//g && print' /etc/cai-watchdog/email.conf) < /dev/null)
set -- $ARGS "$@";
GROUP_ID=$1
BOT_TOKEN=$2
# this 3 checks (if) are not necessary but should be convenient
if [ "${MESSAGE_TEXT}" == "-h" ]; then
echo "Usage: `basename ${SCRIPT_NAME}` \"text message\""
exit 0
fi
if [ -z "${MESSAGE_TEXT}" ]
then
echo "Add message text as second arguments"
exit 0
fi
curl -s --data "text=${MESSAGE_TEXT}" --data "chat_id=$GROUP_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null