Page 1 of 1

Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Sun Dec 31, 2017 6:18 am
by baggins
I wondered why I did not receive any notifications (neither email nor telegram).

As far as email is concerned, there is already a report on an error regarding the "from" field.

As I did also not receive any telegrams, I first tested the telegram_nems.lua script and that worked.
Looking at the command line in NConf however showed that both notify-service-by-telegram and notify-host-by-telegram refer to the old command:

            /usr/local/bin/telegram_nagios.lua

Obviously the command line arguments are not complete either.

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Tue Jan 30, 2018 3:31 am
by baggins
Hi Robbie,

Could you have a look at this?
This should be an easy fix.

Thanks.

BR

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Tue Jan 30, 2018 11:27 am
by Robbie Ferguson
Hmm, thanks baggins. I could actually really use your assistance with this one because I couldn't figure out how Telegram works. I'm looking for someone who uses it to test and even assist with writing the documentation for this feature.

Please see this message I'd posted to you a long time ago which went unanswered: https://forum.category5.tv/thread-96-po ... tml#pid757

Let me know what needs changing, specifically (eg., what NConf should have the commands set to) and I'll get working on it.

Thanks!

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Tue Jan 30, 2018 1:16 pm
by baggins
Hi Robbie,

You have in fact already done most of the work, but probably forgotten about it!

To start with: in /usr/local/bin you have now a script called telegram_nems.lua which is a modified version of my original script called telegram_nagios.lua.
The new script takes two additional arguments: the bot (arg[1] and the chat_id arg[2]. 
The bot and the chat_id are now stored in the resource.cfg as $USER11$ and $USER12$.

In Nconf however you have still the old command line: (This is for notify-host-by telegram, notify-service-by telegram is similar)

/usr/local/bin/telegram_nagios.lua "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$LONGDATETIME$"

so this should be changed to:

/usr/local/bin/telegram_nems.lua $USER11$ $USER12$ "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$LONGDATETIME$"

That should do it.

Sorry about not responding to the previous message, I must have overlooked it.


BR

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Tue Jan 30, 2018 2:34 pm
by Robbie Ferguson
Easy peasy, thanks baggins. :) Yeah, I snuck this feature in at the last minute of 1.3 feature freeze... so I'll get it fixed and ready for the next release (perhaps 1.3.1).

There's such an overlap right now between 1.3 and 1.4 so I'll decide how best to do this.

Thanks again!

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Sat Jun 09, 2018 2:12 am
by lonehorse
Posting this here in case it helps someone since I couldn't find a straight forward explanation.  There may be a simpler way of doing this, but this is how I made it work.  None of this is my original work, so I've included links to where I found the answers.  

First create a bot: 

Within the Telegram app, send a message to @BotFather
/start
/newbot <botname>

Make note of the Token you receive in return.  This is what you'll use for the "Your Bot" field in NEMS System Settings Tool (must add 'bot' before the token). 
https://core.telegram.org/bots#3-how-do-i-create-a-bot

Allow your bot to join groups: 
send a message to @BotFather
/setjoingroups
<botname>

The Chat ID seems to be a bit tricky to obtain.  
Compose a new message in Telegram, choosing the new group option.   
Add <botname> to the group.

Message your bot. 
/my_id <botname>
https://api.telegram.org/bot<Token>/getUpdates

Look for 'chat":{"id":'.   The id will be something like -12345678910. This is what you'll use for the Chat ID.   

https://stackoverflow.com/questions/324 ... up-chat-id


Hit save and hopefully you'll be in business.

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Mon Jun 11, 2018 2:29 pm
by Robbie Ferguson
That's wonderful, thank you lonehorse.

I'll add a link to your post in the docs for now, and inevitably write it in to the docs.

Cheers!
Robbie

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Tue May 21, 2019 7:29 am
by IMBACalimba
Hi @lonehorse first of all thanks for your help

I have 2 questions regarding what you have written.

1.
Make note of the Token you receive in return.  This is what you'll use for the "Your Bot" field in NEMS System Settings Tool (must add 'bot' before the token). 
If i understand this right i have to fill into the Field "Your Bot" my API key and in front of it "bot" so combined it looks something like this "bot12345:xyz54321xxxXXXxxx" is this correct?

2.
Look for 'chat":{"id":'.   The id will be something like -12345678910. This is what you'll use for the Chat ID.  
Do i have to fill in this ID with or without the minus "-" in the beginning? For example should i fill into the "Telegram Chat ID" field, this "-123454321" or this "123454321"?

Sorry for those stupid questions but so far i tried it in different ways and i could not getting it to work so im trying to find the where i made a mistake but so far i had no luck :-/

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Tue May 21, 2019 10:00 am
by leomezza
Same question from my side, adding "bot" in front of the token is not working for me

RE: Error in commands notify-service-by-telegram and notify-host-by-telegram

Posted: Mon Aug 19, 2019 7:12 pm
by Robbie Ferguson
The official documentation is now complete and should help clarify how to setup your Telegram bot. https://docs.nemslinux.com/usage/notify-host-by-telegram