Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature-Request] Multiple Alert Profiles #3

Closed
sectary-want-holly opened this issue Mar 13, 2021 · 5 comments
Closed

[Feature-Request] Multiple Alert Profiles #3

sectary-want-holly opened this issue Mar 13, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@sectary-want-holly
Copy link

Hi -

Thanks for this script. It works great. Quick question though, how would one go about utilising the script for multiple different alert Groups in Telegram? Clone the script and change reference to an individualised config.xml file?

@filipnet
Copy link
Owner

Hi, thanks, nice to hear.

You want to granularly differentiate in Check_MK, which alert group should be notified via Telegram? Then a clone would certainly be a pragmatic way to go. To meet this requirement, I would personally take the following approach:

Under notification rules > notification method there is also an option to call the method "Push Notification (using Telegram)" with a parameter (Call with the following parameter).

Here you could pass the Telegram GroupID (maybe also the token) directly. Take a look at the manual:
Check_MK Manual > Notifications > Chapter: 11.3. A simple example

OMD[mysite]:~$ grep PARAMETER $OMD_ROOT/tmp/telegram.out
NOTIFY_PARAMETERS=bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 -123456789
NOTIFY_PARAMETER_1=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
NOTIFY_PARAMETER_2=-123456789

Inside check_mk_telegram-notify.sh, the lines

TOKEN=$(xmllint --xpath 'string(/config/telegram_api_token)' $CONFIGFILE)
CHAT_ID=$(xmllint --xpath 'string(/config/telegram_chat_id)' $CONFIGFILE)

need to be changed to something like

TOKEN=$NOTIFY_PARAMETER_1
CHAT_ID=$NOTIFY_PARAMETER_2

So far the theory, the config.xml might even be omitted completely. I don't have time to try it out myself at the moment. If you are faster, I would be glad about a feedback. I would then adapt the code and documentation accordingly.

@filipnet filipnet changed the title Multiple Alert Profiles [Feature-Request] Multiple Alert Profiles Mar 15, 2021
@filipnet filipnet added the enhancement New feature or request label Mar 15, 2021
@filipnet
Copy link
Owner

Good morning sectary-want-holly, I was up early and then curious myself. I tested it on one of my Check_MK instances, works with parameter passing as described above. Code and documentation are adjusted, don't forget to restart the OMD instance. Thanks for your question, this is now much more charmingly solved.

@sectary-want-holly
Copy link
Author

Hey @filipnet - apologies for the delayed replies. We're in different TZ's and I read the reply in the morning then forget to reply later! Just wanted to say many thanks for this - I have it working beautifully now!

@ThomasKaiser
Copy link
Contributor

A different approach is to use the 'Pager address' field in Check_MK's user properties. This gets exported as $NOTIFY_CONTACTPAGER variable to the script and as such all that's needed is

if [ -z ${NOTIFY_CONTACTPAGER} ]; then
        echo "No pager address provided to be used as Chat-ID. Exiting" >&2
        exit 2
else
        CHAT_ID="${NOTIFY_CONTACTPAGER}"
fi

@tuannt76
Copy link

i am having a problem that i can only send to 1 telegram user.How can send notifications to multiple users telegram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants