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

Found something amiss in NEMS? Confirm first that you are running the latest version, and then post your bug report here.
Post Reply
baggins
Member
Posts: 50
Joined: Tue Oct 03, 2017 4:46 am

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

Post 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.
baggins
Member
Posts: 50
Joined: Tue Oct 03, 2017 4:46 am

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

Post by baggins »

Hi Robbie,

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

Thanks.

BR
User avatar
Robbie Ferguson
Posting Freak
Posts: 830
Joined: Wed Mar 07, 2012 3:23 pm
Location: Ontario, Canada
Contact:

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

Post 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!
Robbie Ferguson // The Bald Nerd

Did I help you out? Appreciate what I do? Please consider saying thanks:
baggins
Member
Posts: 50
Joined: Tue Oct 03, 2017 4:46 am

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

Post 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
User avatar
Robbie Ferguson
Posting Freak
Posts: 830
Joined: Wed Mar 07, 2012 3:23 pm
Location: Ontario, Canada
Contact:

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

Post 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!
Robbie Ferguson // The Bald Nerd

Did I help you out? Appreciate what I do? Please consider saying thanks:
lonehorse
Junior Member
Posts: 1
Joined: Sat Jun 09, 2018 1:18 am

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

Post 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.
User avatar
Robbie Ferguson
Posting Freak
Posts: 830
Joined: Wed Mar 07, 2012 3:23 pm
Location: Ontario, Canada
Contact:

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

Post 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
Robbie Ferguson // The Bald Nerd

Did I help you out? Appreciate what I do? Please consider saying thanks:
User avatar
IMBACalimba
Junior Member
Posts: 3
Joined: Mon Feb 18, 2019 8:14 am

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

Post 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 :-/
leomezza
Junior Member
Posts: 1
Joined: Tue May 21, 2019 9:56 am

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

Post by leomezza »

Same question from my side, adding "bot" in front of the token is not working for me
User avatar
Robbie Ferguson
Posting Freak
Posts: 830
Joined: Wed Mar 07, 2012 3:23 pm
Location: Ontario, Canada
Contact:

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

Post 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
Robbie Ferguson // The Bald Nerd

Did I help you out? Appreciate what I do? Please consider saying thanks:
Post Reply