-
Notifications
You must be signed in to change notification settings - Fork 52
/
notify-script.example
executable file
·82 lines (72 loc) · 2.46 KB
/
notify-script.example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# Example tsdecrypt notify script
# Written by Georgi Chorbadzhiyski
#
# *** Released as PUBLIC DOMAIN ***
# *** Do whatever you want with this code ***
# tsdecrypt sets its stack size to 64k which is very low and
# causes sendmail to segfault, so increase the stack size to 2Mb
ulimit -s 2048
EMAIL_ENABLED="yes"
EMAIL_TO="[email protected]" # !!! Change this !!!
EMAIL_FROM="[email protected]" # !!! Change this !!!
EMAIL_SUBJECT_PREFIX="[tsdecrypt]"
EMAIL_PROGRAM="/usr/sbin/sendmail -t -i"
LOG_ENABLED="yes"
LOG_DIR="."
LOG_FILE="$LOG_DIR/notify.${_IDENT}.notify.log"
STATUS_ENABLED="yes"
STATUS_FILE="$LOG_DIR/status.${_IDENT}"
# Environmental vars that are set by the calling process (tsdecrypt):
# _TS Unix timestamp of the event.
# _IDENT tsdecrypt ident (--ident parameter).
# _INPUT_ADDR Input address and port (for example 239.1.2.3:5000).
# _OUTPUT_ADDR Output address and port (for example 239.9.8.7:5000).
# _MESSAGE_ID Event message id (For example START, STOP, etc...).
# _MESSAGE_TEXT Event message text. Human readable event message.
# _MESSAGE_MSG Event message id lower cased and "_" is replaced with " "
export PATH="/bin:/usr/bin:/usr/local/bin"
export LC_ALL=C
if [ -z "${_IDENT}" -o -z "${_TS}" ]
then
echo "This script must be run from tsdecrypt."
echo "In order for tsdecrypt to run this script use --ident and --notify-prg options."
echo
echo "Example:"
echo " tsdecrypt --ident SOURCE/CHANNEL --notify-program ./notify-script.example --camd-server x.x.x.x"
echo
exit 1
fi
if [ "$LOG_ENABLED" = "yes" ]
then
LOG_DATE="$(date +%F\ %T\ %z -d @${_TS})"
printf "%s | %s | %-16s | %s\n" \
"$LOG_DATE" \
"${_IDENT}" \
"${_MESSAGE_ID}" \
"${_MESSAGE_TEXT}" \
>> $LOG_FILE
fi
if [ "$STATUS_ENABLED" = "yes" ]; then
# Run tsdecrypt with --notify-wait otherwise the events might get here out of order
echo "${_IDENT}|${_TS}|${_MESSAGE_ID}|${_MESSAGE_TEXT}|${_INPUT_ADDR}|${_OUTPUT_ADDR}" > $STATUS_FILE.tmp
mv $STATUS_FILE.tmp $STATUS_FILE
fi
if [ "$EMAIL_ENABLED" = "yes" ]
then
if [ -x $EMAIL_PROGRAM ]; then
(
echo "To: <$EMAIL_TO>"
echo "From: <$EMAIL_FROM>"
echo "Return-Path: <$EMAIL_FROM>"
echo "Subject: $EMAIL_SUBJECT_PREFIX ${_IDENT} ${_MESSAGE_MSG}"
echo "X-IDENT: ${_IDENT}"
echo "X-MSG-ID: ${_MESSAGE_ID}"
echo "X-Input: ${_INPUT_ADDR}"
echo "X-Output: ${_OUTPUT_ADDR}"
echo "X-Mailer: tsdecrypt"
echo
echo "${_IDENT} ${_MESSAGE_TEXT}"
) | $EMAIL_PROGRAM
fi
fi