add a debug mode for the CLI
this allows to debug the telegram api with verbose output which is very useful when setting up this module the first time
This commit is contained in:
parent
d35cdf14d4
commit
4fa596ca47
2 changed files with 44 additions and 18 deletions
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
## /etc/icinga2/scripts/host-by-telegram.sh / 20170330
|
## /etc/icinga2/scripts/host-by-telegram.sh / 20170330
|
||||||
## Marianne M. Spiller <github@spiller.me>
|
## Marianne M. Spiller <github@spiller.me>
|
||||||
## Last updated 20170424
|
## Last updated 20190722
|
||||||
## Tested icinga2-2.6.3-1
|
## Tested icinga2-2.10.3
|
||||||
|
|
||||||
PROG="`basename $0`"
|
PROG="`basename $0`"
|
||||||
HOSTNAME="`hostname`"
|
HOSTNAME="`hostname`"
|
||||||
TRANSPORT="curl"
|
TRANSPORT="curl"
|
||||||
|
unset DEBUG
|
||||||
|
|
||||||
if [ -z "`which $TRANSPORT`" ] ; then
|
if [ -z "`which $TRANSPORT`" ] ; then
|
||||||
echo "$TRANSPORT not in \$PATH. Consider installing it."
|
echo "$TRANSPORT not in \$PATH. Consider installing it."
|
||||||
|
@ -36,13 +37,14 @@ And these are optional:
|
||||||
-c NOTIFICATIONCOMMENT (\$notification.comment$)
|
-c NOTIFICATIONCOMMENT (\$notification.comment$)
|
||||||
-i HAS_ICINGAWEB2 (\$icingaweb2url$, Default: unset)
|
-i HAS_ICINGAWEB2 (\$icingaweb2url$, Default: unset)
|
||||||
-v (\$notification_logtosyslog$, Default: false)
|
-v (\$notification_logtosyslog$, Default: false)
|
||||||
|
-D DEBUG enable debug output - meant for CLI debug only
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts 4:6::b:c:d:hi:l:n:o:p:q:r:s:t:u:v: opt
|
while getopts 4:6::b:c:d:hi:l:n:o:p:q:r:s:t:u:v:D opt
|
||||||
do
|
do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
4) HOSTADDRESS=$OPTARG ;;
|
4) HOSTADDRESS=$OPTARG ;;
|
||||||
|
@ -61,6 +63,7 @@ do
|
||||||
s) HOSTSTATE=$OPTARG ;;
|
s) HOSTSTATE=$OPTARG ;;
|
||||||
t) NOTIFICATIONTYPE=$OPTARG ;;
|
t) NOTIFICATIONTYPE=$OPTARG ;;
|
||||||
v) VERBOSE=$OPTARG ;;
|
v) VERBOSE=$OPTARG ;;
|
||||||
|
D) DEBUG=1; echo -e "\n**********************************************\nWARNING: DEBUG MODE, DEACTIVATE ASAP\n**********************************************\n" ;;
|
||||||
\?) echo "ERROR: Invalid option -$OPTARG" >&2
|
\?) echo "ERROR: Invalid option -$OPTARG" >&2
|
||||||
Usage ;;
|
Usage ;;
|
||||||
:) echo "Missing option argument for -$OPTARG" >&2
|
:) echo "Missing option argument for -$OPTARG" >&2
|
||||||
|
@ -108,10 +111,20 @@ if [ "$VERBOSE" == "true" ] ; then
|
||||||
logger "$PROG sends $SUBJECT => Telegram Channel $TELEGRAM_BOT"
|
logger "$PROG sends $SUBJECT => Telegram Channel $TELEGRAM_BOT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## debug output or not
|
||||||
|
if [ -z $DEBUG ];then
|
||||||
|
CURLARGS="--silent --output /dev/null"
|
||||||
|
else
|
||||||
|
CURLARGS=-v
|
||||||
|
set -x
|
||||||
|
echo -e "DEBUG MODE!"
|
||||||
|
fi
|
||||||
|
|
||||||
## And finally, send the message
|
## And finally, send the message
|
||||||
/usr/bin/curl --silent --output /dev/null \
|
/usr/bin/curl $CURLARGS \
|
||||||
--data-urlencode "chat_id=${TELEGRAM_BOTID}" \
|
--data-urlencode "chat_id=${TELEGRAM_CHATID}" \
|
||||||
--data-urlencode "text=${NOTIFICATION_MESSAGE}" \
|
--data-urlencode "text=${NOTIFICATION_MESSAGE}" \
|
||||||
--data-urlencode "parse_mode=HTML" \
|
--data-urlencode "parse_mode=HTML" \
|
||||||
--data-urlencode "disable_web_page_preview=true" \
|
--data-urlencode "disable_web_page_preview=true" \
|
||||||
"https://api.telegram.org/bot${TELEGRAM_BOTTOKEN}/sendMessage"
|
"https://api.telegram.org/bot${TELEGRAM_BOTTOKEN}/sendMessage"
|
||||||
|
set +x
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
## /etc/icinga2/scripts/service-by-telegram.sh / 20170330
|
## /etc/icinga2/scripts/service-by-telegram.sh / 20170330
|
||||||
## Marianne M. Spiller <github@spiller.me>
|
## Marianne M. Spiller <github@spiller.me>
|
||||||
## Last updated 20170424
|
## Last updated 20190722
|
||||||
## Tested icinga2-2.6.3-1
|
## Tested icinga2-2.10.3
|
||||||
|
|
||||||
PROG="`basename $0`"
|
PROG="`basename $0`"
|
||||||
HOSTNAME="`hostname`"
|
HOSTNAME="`hostname`"
|
||||||
TRANSPORT="curl"
|
TRANSPORT="curl"
|
||||||
|
unset DEBUG
|
||||||
|
|
||||||
if [ -z "`which $TRANSPORT`" ] ; then
|
if [ -z "`which $TRANSPORT`" ] ; then
|
||||||
echo "$TRANSPORT not in \$PATH. Consider installing it."
|
echo "$TRANSPORT not in \$PATH. Consider installing it."
|
||||||
|
@ -38,12 +39,13 @@ And these are optional:
|
||||||
-c NOTIFICATIONCOMMENT (\$notification.comment$)
|
-c NOTIFICATIONCOMMENT (\$notification.comment$)
|
||||||
-i HAS_ICINGAWEB2 (\$icingaweb2url$, Default: unset)
|
-i HAS_ICINGAWEB2 (\$icingaweb2url$, Default: unset)
|
||||||
-v (\$notification_logtosyslog$, Default: false)
|
-v (\$notification_logtosyslog$, Default: false)
|
||||||
|
-D DEBUG enable debug output - meant for CLI debug only
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts 4:6:b:c:d:e:f:hi:l:n:o:p:q:r:s:t:u:v: opt
|
while getopts 4:6:b:c:d:e:f:hi:l:n:o:p:q:r:s:t:u:v:D opt
|
||||||
do
|
do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
4) HOSTADDRESS=$OPTARG ;;
|
4) HOSTADDRESS=$OPTARG ;;
|
||||||
|
@ -64,6 +66,7 @@ do
|
||||||
t) NOTIFICATIONTYPE=$OPTARG ;;
|
t) NOTIFICATIONTYPE=$OPTARG ;;
|
||||||
u) SERVICEDISPLAYNAME=$OPTARG ;;
|
u) SERVICEDISPLAYNAME=$OPTARG ;;
|
||||||
v) VERBOSE=$OPTARG ;;
|
v) VERBOSE=$OPTARG ;;
|
||||||
|
D) DEBUG=1; echo -e "\n**********************************************\nWARNING: DEBUG MODE, DEACTIVATE ASAP\n**********************************************\n" ;;
|
||||||
\?) echo "ERROR: Invalid option -$OPTARG" >&2
|
\?) echo "ERROR: Invalid option -$OPTARG" >&2
|
||||||
Usage ;;
|
Usage ;;
|
||||||
:) echo "Missing option argument for -$OPTARG" >&2
|
:) echo "Missing option argument for -$OPTARG" >&2
|
||||||
|
@ -110,10 +113,20 @@ if [ "$VERBOSE" == "true" ] ; then
|
||||||
logger "$PROG sends $SUBJECT => Telegram Channel $TELEGRAM_BOT"
|
logger "$PROG sends $SUBJECT => Telegram Channel $TELEGRAM_BOT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
## debug output or not?
|
||||||
|
if [ -z $DEBUG ];then
|
||||||
|
CURLARGS="--silent --output /dev/null"
|
||||||
|
else
|
||||||
|
CURLARGS=-v
|
||||||
|
set -x
|
||||||
|
echo -e "DEBUG MODE!"
|
||||||
|
fi
|
||||||
|
|
||||||
## And finally, send the message
|
## And finally, send the message
|
||||||
/usr/bin/curl --silent --output /dev/null \
|
/usr/bin/curl $CURLARGS \
|
||||||
--data-urlencode "chat_id=${TELEGRAM_BOTID}" \
|
--data-urlencode "chat_id=${TELEGRAM_CHATID}" \
|
||||||
--data-urlencode "text=${NOTIFICATION_MESSAGE}" \
|
--data-urlencode "text=${NOTIFICATION_MESSAGE}" \
|
||||||
--data-urlencode "parse_mode=HTML" \
|
--data-urlencode "parse_mode=HTML" \
|
||||||
--data-urlencode "disable_web_page_preview=true" \
|
--data-urlencode "disable_web_page_preview=true" \
|
||||||
"https://api.telegram.org/bot${TELEGRAM_BOTTOKEN}/sendMessage"
|
"https://api.telegram.org/bot${TELEGRAM_BOTTOKEN}/sendMessage"
|
||||||
|
set +x
|
||||||
|
|
Loading…
Reference in a new issue