OPNsense Forum

Archive => 23.7 Legacy Series => Topic started by: alexkgr on November 04, 2023, 07:32:49 AM

Title: Telegram Notifications
Post by: alexkgr on November 04, 2023, 07:32:49 AM
Hello everyone,

New user trying to migrate from pfsense (4 years setup with many tweaks)

I am used to have telegram notifications whatever happens to my networks.
New device, gw down etc.

Trying to find something at opnsense but all based to monit and custom setup and and and.

Is it so difficult to integrate to telegram plugin that pfsense has? Or something equivalent.

Thanks in advance.
Title: Re: Telegram Notifications
Post by: mimugmail on November 04, 2023, 09:49:27 AM
There is a Telegram plugin for pf? Where?
Title: Re: Telegram Notifications
Post by: alexkgr on November 04, 2023, 09:55:02 AM
Quote from: mimugmail on November 04, 2023, 09:49:27 AM
There is a Telegram plugin for pf? Where?
Embedded at the pf.
System - advanced - notifications

Sent from my SM-S918B using Tapatalk

Title: Re: Telegram Notifications
Post by: mimugmail on November 04, 2023, 10:14:03 AM
Do you have a screenshot available please?
I was always thinking about a plugin to add predefined actions to monit
Title: Re: Telegram Notifications
Post by: alexkgr on November 04, 2023, 11:43:34 AM
here it is

thanks and hope for something

Title: Re: Telegram Notifications
Post by: mimugmail on November 04, 2023, 03:10:09 PM
And where do you define which messages should go to this group?
Title: Re: Telegram Notifications
Post by: alexkgr on November 04, 2023, 04:10:17 PM
There is no option. Everything happens to fw, connectivity etc...you have a notification

Sent from my SM-S918B using Tapatalk

Title: Re: Telegram Notifications
Post by: ajohn on November 11, 2023, 09:54:08 AM
I would like to +1 this request. Recently migrated from pfSense to OPNsense and really like OPNsense a lot. But Monitoring is one of the features that works much easier and more intuitive in pfSense.

An easy way to setup e-mail and Telegram notifications would be very much appreciated. Monit seems extremely versatile, but it is difficult to understand as a new user. E.g. I would like to be notified if someone succesfully connects to Wireguard. Can't figure it out (yet).
Title: Re: Telegram Notifications
Post by: alexkgr on November 11, 2023, 09:58:44 AM
Quote from: ajohn on November 11, 2023, 09:54:08 AM
I would like to +1 this request. Recently migrated from pfSense to OPNsense and really like OPNsense a lot. But Monitoring is one of the features that works much easier and more intuitive in pfSense.

An easy way to setup e-mail and Telegram notifications would be very much appreciated. Monit seems extremely versatile, but it is difficult to understand as a new user. E.g. I would like to be notified if someone succesfully connects to Wireguard. Can't figure it out (yet).
Totally agree with this....still using old install of pfsense due to notifications

Sent from my SM-S918B using Tapatalk

Title: Re: Telegram Notifications
Post by: connervt on November 11, 2023, 04:33:02 PM
Another +1 for Telegram notifications.

People do not watch their email (unless sitting at a desk in their work environment) like the once did 15 years ago.  I use Telegram nearly exclusively for my network and server notifications, be it those generated by OS itself, applications running on servers, or even in my self generated bash scripts.  I use two different Telegram bots (one for system stuff, one for applications) that have different notification tones.  This is much more useful, as I can immediately know which are notifying me even before I take my phone out of my pocket.  With email, you get one ding, be it from your system or the third email about sales at Best Buy.
Title: Re: Telegram Notifications
Post by: Nitin on November 12, 2023, 01:59:03 PM
Wonder if this still works: https://github.com/matriphe/monit2telegram

Anyone tried it?
Title: Re: Telegram Notifications
Post by: alexkgr on November 12, 2023, 03:21:55 PM
Quote from: gniting on November 12, 2023, 01:59:03 PM
Wonder if this still works: https://github.com/matriphe/monit2telegram

Anyone tried it?
There is nginx I think at opnsense. I have read somewhere that it is difficult to implement but it is working

Sent from my SM-S918B using Tapatalk

Title: Re: Telegram Notifications
Post by: alexkgr on November 13, 2023, 12:12:12 PM
anything new about this?
Title: Re: Telegram Notifications
Post by: franco on November 13, 2023, 12:14:49 PM
Since yesterday? Likely not. ;)
Title: Re: Telegram Notifications
Post by: alexkgr on November 13, 2023, 12:16:26 PM
Quote from: franco on November 13, 2023, 12:14:49 PM
Since yesterday? Likely not. ;)
In general i am saying. It's almost 10 days since i have proposed it.
I am not asking for implementing...just for discussion

Sent from my SM-S918B using Tapatalk

Title: Re: Telegram Notifications
Post by: mimugmail on November 14, 2023, 07:53:11 AM
I'll have a look, but it takes some time.
Title: Re: Telegram Notifications
Post by: InTeL3D on December 08, 2023, 07:00:04 PM
+1
Thank you minugmail
Title: Re: Telegram Notifications
Post by: sammyke007 on December 15, 2023, 11:47:49 PM
Would be nice...

This works for OPNarp by the way:
https://mephiz.sh/2023/06/10/opnarp-telegram (https://mephiz.sh/2023/06/10/opnarp-telegram)
Title: Re: Telegram Notifications
Post by: Fright on December 16, 2023, 07:57:18 PM
@franco @mimugmail
Hi!
so what's the plan? )
integrate in core? make it a plugin and call it with the exec action with the script path?
Or is this only for Michael's repo for now?
Title: Re: Telegram Notifications
Post by: oscars on December 17, 2023, 01:11:17 AM
Request @ github

https://github.com/opnsense/core/issues/7080
Title: Re: Telegram Notifications
Post by: mimugmail on December 17, 2023, 02:01:38 AM
Quote from: Fright on December 16, 2023, 07:57:18 PM
@franco @mimugmail
Hi!
so what's the plan? )
integrate in core? make it a plugin and call it with the exec action with the script path?
Or is this only for Michael's repo for now?

Best would start with a plugin, do you want to work on it? :)
Title: Re: Telegram Notifications
Post by: Fright on December 17, 2023, 07:12:18 AM
only if you haven't started yet  :)
a simple script seems to work. wanted to try it with the markdownv2 markup allowed. and add a bit of logging
Title: Re: Telegram Notifications
Post by: mimugmail on December 17, 2023, 07:39:52 AM
I didnt, so, happy when you take care :)
Title: Re: Telegram Notifications
Post by: Fright on December 17, 2023, 07:16:16 PM
got it, thanks )
skeleton is ready, some polishing needed
Title: Re: Telegram Notifications
Post by: alexkgr on December 17, 2023, 07:19:59 PM
i didn't understand.

Someone has made a script that it is working?
do you want to test it?
Title: Re: Telegram Notifications
Post by: Fright on December 17, 2023, 07:30:51 PM
script is not standalone. it uses params from gui\config.
Sure, i'll ask for testing when everything is ready, thanks
Title: Re: Telegram Notifications
Post by: Fright on December 19, 2023, 06:25:36 PM
@alexkgr Hi
if you are ready to help with testing, take a look please
https://github.com/kulikov-a/opn-monit2t
pkg add https://github.com/kulikov-a/opn-monit2t/raw/main/work/pkg/os-monit2t-1.0.pkg
Title: Re: Telegram Notifications
Post by: alexkgr on December 19, 2023, 07:42:35 PM
@Fright

i will check the next days and report.
thank you very much
Title: Re: Telegram Notifications
Post by: alexkgr on December 20, 2023, 07:43:47 AM
Quote from: Fright on December 19, 2023, 06:25:36 PM
@alexkgr Hi
if you are ready to help with testing, take a look please
https://github.com/kulikov-a/opn-monit2t
pkg add https://github.com/kulikov-a/opn-monit2t/raw/main/work/pkg/os-monit2t-1.0.pkg


i am really new to opnsense.
can you help me how to setup it with monit and have notifications?

I have entered telegram token and chat id and i received the test message.
But i don't know what to with this "In order to use this plugin, "Execute" Action should be set for Service Test and "/usr/local/opnsense/scripts/OPNsense/Monit2T/monit2t.sh" as a path. "
Title: Re: Telegram Notifications
Post by: Fright on December 20, 2023, 07:52:53 AM
for example, if you use example 3 from docs
https://docs.opnsense.org/manual/monit.html#example-3
it will look like in the picture attached
Title: Re: Telegram Notifications
Post by: alexkgr on December 20, 2023, 07:58:50 AM
Quote from: Fright on December 20, 2023, 07:52:53 AM
for example, if you use example 3 from docs
https://docs.opnsense.org/manual/monit.html#example-3
it will look like in the picture attached

so we have to change all service tests settings?
Title: Re: Telegram Notifications
Post by: Fright on December 20, 2023, 08:06:33 AM
only those that are used (in Service Settings) and notifications for which should be received in Telegram
Title: Re: Telegram Notifications
Post by: alexkgr on December 20, 2023, 08:13:59 AM
i am trying to trigger an alert but it is not successful.
Title: Re: Telegram Notifications
Post by: Fright on December 20, 2023, 08:18:27 AM
triggered alerts should be visible in monit log
Title: Re: Telegram Notifications
Post by: alexkgr on December 20, 2023, 08:29:43 AM
i have an error at monit logs.

Title: Re: Telegram Notifications
Post by: Fright on December 20, 2023, 08:42:32 AM
did you changed message template?
is the test message sent successfully?
Title: Re: Telegram Notifications
Post by: alexkgr on December 20, 2023, 08:46:17 AM
Quote from: Fright on December 20, 2023, 08:42:32 AM
did you changed message template?
is the test message sent successfully?

haven't changed anything.
i am trying to trigger an alert with the opn-arp pkg

i am typing this at a console

" echo "<29>1 2022-08-29T20:16:44+03:00 router.home root 59285 - [meta sequenceId=1] New IPv4/MAC pair seen: (10.1.3.22)3a:d1:ee:bc:79:2f" >> /var/log/system/latest.log"

to have triggered an alert
Title: Re: Telegram Notifications
Post by: Fright on December 20, 2023, 08:59:45 AM
got it, thanks. html tags should be encoded in MONIT_DESCRIPTION text then. will make a patch today
Title: Re: Telegram Notifications
Post by: alexkgr on December 20, 2023, 09:21:00 AM
Quote from: Fright on December 20, 2023, 08:59:45 AM
got it, thanks. html tags should be encoded in MONIT_DESCRIPTION text then. will make a patch today

thanks!
Title: Re: Telegram Notifications
Post by: Fright on December 20, 2023, 09:45:18 AM

pkg delete os-monit2t
pkg add https://github.com/kulikov-a/opn-monit2t/raw/main/work/pkg/os-monit2t-1.0.pkg
Title: Re: Telegram Notifications
Post by: alexkgr on December 20, 2023, 09:52:21 AM
Quote from: Fright on December 20, 2023, 09:45:18 AM

pkg delete os-monit2t
pkg add https://github.com/kulikov-a/opn-monit2t/raw/main/work/pkg/os-monit2t-1.0.pkg



ok it is fixed!
thanks
Title: Re: Telegram Notifications
Post by: Fright on December 20, 2023, 10:28:11 AM
thanks! please, test it.
maybe I missed something else or something can be added  ;)
Title: Re: Telegram Notifications
Post by: halasizs on January 04, 2024, 07:41:31 PM
Any progress in the development? Just wondering!  :)
Title: Re: Telegram Notifications
Post by: alexkgr on January 04, 2024, 07:43:00 PM
Quote from: halasizs on January 04, 2024, 07:41:31 PM
Any progress in the development? Just wondering!  :)
It is working

Sent from my SM-S916B using Tapatalk

Title: Re: Telegram Notifications
Post by: halasizs on January 04, 2024, 07:46:19 PM
Will it be included in the plugins?
Title: Re: Telegram Notifications
Post by: Fright on January 04, 2024, 08:04:45 PM
@halasizs
more feedback - more chances )
you can test it (https://forum.opnsense.org/index.php?topic=36805.msg184572#msg184572)
and share your opinion
I still don't know if it makes sense to make a PR for it
Title: Re: Telegram Notifications
Post by: halasizs on January 04, 2024, 09:01:03 PM
Well, now I'm not in the mood for opnsession. After refreshing /23.10_1-> 23.11/ the web interface does not load. https://192.168.0.1 . SSH disabled, I can't reach it. Luckily I have internet and it is not interrupted.
On restart 2x the situation was unchanged. The weekend programme is here.
I know I shouldn't be writing here, but I'm angry.  Sorry.
Title: Re: Telegram Notifications
Post by: vrabac on January 05, 2024, 09:04:41 AM
I was looking for this, and seems it works, at least the Test is working. I am not sure how to trigger some alarms manually over cli.

One thing maybe to consider, when entering the Token and Chat ID and pressing Test, without saving settings firstly, will trow an error message, not sure is this by design or it should say please save first then do test messages.
Title: Re: Telegram Notifications
Post by: Fright on January 05, 2024, 08:00:47 PM
@vrabac
Thanks!
I'll take a look - may be its better to send test message with the form values and not from config values (so it's possible to test settings without saving to config)
Title: Re: Telegram Notifications
Post by: vrabac on January 05, 2024, 08:28:26 PM
@Fright
That would even be better, to use values from Form and not from config, as in initial setup there is no values in config, and I guess because of that there is that error then trying to test.

Do you know the way to trigger some test in CLI to see this in action. I changed all monit Services Test Settings  (11 by default) to Execute and that path, but would like to see this in real action :). I am also loking for some more monit Services Test.
Title: Re: Telegram Notifications
Post by: Fright on January 05, 2024, 08:45:24 PM
edit(say 15%)\enable CPUUsageTest and run something cpu-consuming. like IDS rulesets update )

good example of shell quick test (via logs monitoring): https://mephiz.sh/2023/06/10/opnarp-telegram#monit-settings
Title: Re: Telegram Notifications
Post by: kozistan on January 07, 2024, 08:28:51 PM
Hi Fright, this is working for me. As i press apply on MONIT setting i get message regarding CPUUsage, but just once after apply. No other messages regarding CPUUsage are coming, even the load is more that 15%
Title: Re: Telegram Notifications
Post by: Fright on January 07, 2024, 09:26:21 PM
@kozistan
Hi! any clue in monit log?
matches and actions should be visible in monit log with Info (and above) severity level selected
Title: Re: Telegram Notifications
Post by: kozistan on January 07, 2024, 09:55:23 PM
That is correct, log is full of reports. Please check the attached screenshot.
Title: Re: Telegram Notifications
Post by: Fright on January 07, 2024, 10:21:15 PM
after the 'SYSTEM' cpu usage of **% matches resource limit ' message there should be messages like:
'SYSTEM' exec: '/usr/local/opnsense/scripts/OPNsense/Monit2T/monit2t.sh' (with Info severity) if action is set for the service test and then
'Telegram message sent' with Notice severity (if message is sent) or
'Telegram API endpoint returned error..' with Error severity if something goes wrong
Title: Re: Telegram Notifications
Post by: kozistan on January 07, 2024, 10:28:14 PM
screenshot from my config + message on telegram
Title: Re: Telegram Notifications
Post by: Fright on January 07, 2024, 11:35:18 PM
ah. this is how Monit works.
exec (and Alert) action triggers once on state change (or 'repeat every XXX cycle(s)' should be used) .
so cpu usage should drop below threshold first, then exec will work on next match.
you can see in log that your cpu usage is above threshold on every poll
Title: Re: Telegram Notifications
Post by: kozistan on January 08, 2024, 12:19:04 AM
just checked the service monit status is not reseting after it reaches the limit. it's stuck somewhere

Also tried 3 CYCLES with no change.
Title: Re: Telegram Notifications
Post by: Fright on January 08, 2024, 08:07:05 AM
try to set CpuLoad to 25% - i think you will see how it works
Title: Re: Telegram Notifications
Post by: kozistan on January 08, 2024, 08:25:51 PM
thanks @Fright. I did not even changed the value, i've just duplicated those default tests with execute option and everything is working. No issues and can tell you i was sleeping better before, soon I'm going to turn monit off :)

So yes, monit is working with telegram with no issues. At least for me
Title: Re: Telegram Notifications
Post by: vrabac on January 09, 2024, 08:44:29 PM
Quote from: kozistan on January 07, 2024, 08:28:51 PM
Hi Fright, this is working for me. As i press apply on MONIT setting i get message regarding CPUUsage, but just once after apply. No other messages regarding CPUUsage are coming, even the load is more that 15%

I was able to configure like in example on link you provided and Notification are working as expected, great work indeed.
I am not sure if there is possibility somehow to setup monit to use Telegram and not SMTP, would save us work to setup everything to execute and your script, but I personal can live with that, I don't have that much Notifications.
Title: Re: Telegram Notifications
Post by: Fright on January 26, 2024, 07:13:46 PM
@vrabac thanks!
Quoteif there is possibility somehow to setup monit to use Telegram and not SMTP
hmm, I'm not sure I understood correctly, but for telegram to work it is not necessary to configure "Alert settings",
and any (fake) smtp server address can be specified (just so the form validation would be happy)
Title: Re: Telegram Notifications
Post by: JohnnyBeGood on January 31, 2024, 06:03:04 AM
I'm on v23.7.12 and would love to see the official integration. If I can help with testing, I will.
Title: Re: Telegram Notifications
Post by: giopan on April 11, 2024, 01:59:07 AM
Hi,
I was trying to setup a notification to be sent when a host goes down.
It works, but in the message that I receive on Telegram I would like to see the IP that failed.
I'm attaching my configuration.

Thanks!
Title: Re: Telegram Notifications
Post by: Fright on April 12, 2024, 02:13:49 PM
Hi
i think the quickest way to do this with the $SERVICE monit variable:
change "Service name" to something like "My_server_check" and
change Telegram message template ('Message' field with 'Advanced mode' enabled in Telegram settings) to something like:

<b>DATE:</b> {MONIT_DATE}
<b>HOST:</b> {MONIT_HOST}
<b>SERVICE:</b> {MONIT_SERVICE}
<b>DESCRIPTION:</b>
<pre>{MONIT_DESCRIPTION}</pre>

to include this variable to message