Code Monkey home page Code Monkey logo

deexno / checkmk-telegram-plus Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 1.0 7.82 MB

This Telegram bot provides an interface to your Check_MK server. It allows you to send automatic error messages (alerts) via Telegram and to manually read out information about hosts and services.

License: Apache License 2.0

Python 94.93% Shell 5.07%
bash checkmk checkmk-extension checkmk-plugin mobile mobile-app monitoring monitoring-plugins nagios notifications

checkmk-telegram-plus's Introduction

Telegram Bot

This Telegram bot provides an interface to your Check_MK server. It allows you to send automatic error messages (alerts) via Telegram and to manually read out information about hosts and services.

Examples

Info

This bot is NOT meant to be used in groups.

System recommendations

  • CheckMK Version 2.1.p25 or higher
  • The programs python3, pip3, git, runuser & sed installed on the server

The Installation / Update process

  1. Install the bot.
    Replace the variables in <> with your respective information.
  • omd_site_name (Your OMD Check_MK site which you want to monitor)
  • api_token (You get this token from the BotFather of Telegram)
  • bot_password (This can be a password of your choice, which will be used later to authenticate to the bot)
wget https://raw.githubusercontent.com/deexno/checkmk-telegram-plus/main/install.sh
bash install.sh <omd_site_name> <api_token> <bot_password>
  1. Create a rule that exports the notifications using our new Notification Plugin.

Telegram Bot

For your information, you can use the first parameter to determine whether a notification should be sent loud (notifications_loud) or silent (notifications_silent). Silent notifications pop up in the chat, but the device does not vibrate or make a notification sound. This method can be used, for example, to differentiate between important and unimportant notifications.

To update the bot, simply download the install.sh file again as mentioned above and run it with the 3 required arguments

Uninstall the Bot

  1. Stop the bot
omd_site_name=<omd_site_name>
systemctl stop checkmk-telegram-plus-$omd_site_name
rm /etc/systemd/system/checkmk-telegram-plus-$omd_site_name.service
systemctl daemon-reload
  1. Delete all notification rules you have created regarding this bot (as described in step 2 of the installation).

  2. Clean and remove all data concerning the bot

rm -Rf /omd/sites/$omd_site_name/local/share/check_mk/notifications/telegram_plus_notify_listener
rm -Rf /omd/sites/$omd_site_name/local/share/checkmk-telegram-plus

Usage

Authenticate

By default, the bot doesn't allow any communication until you authenticate with the previously set password in the configuration file. Here's an example:
Telegram Bot

Receive information about hosts and services

Retrieving data manually is easy. After authentication, you should see a new icon next to the keyboard โ€“ the menu button. Open the menu and select an option. The bot will ask for necessary info and provide results (as seen in the examples).

Enable and disable notifications

You can enable or disable messages through the bot. "Loud" and "silent" notifications can also be toggled independently. Note that this setting is ONLY FOR YOU, and all other users will still receive their notifications as normal. And they are decativated by default! So don't forget to activate them!
Telegram Bot

Troubleshooting Guide

TROUBLESHOOTING GUIDE ๐Ÿ”จ

Mentions and articles about the bot

TUTONAUT
DEVINSIDER

Support my work

Buy Me A Coffee

checkmk-telegram-plus's People

Contributors

bili123 avatar deexno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

bili123

checkmk-telegram-plus's Issues

Debian 12 compatibility

Hi,

since i updated to Debian 12 the bot isn't working anymore ๐Ÿ˜ญ

I tried to uninstall it and reinstall it. There are some warnings regarding "Running pip as the 'root' user can result in broken permissions and conflicting behaviour". But the installation seems to work.

Installation log
  Collecting python-telegram-bot==20.1
    Using cached python_telegram_bot-20.1-py3-none-any.whl (518 kB)
  Collecting httpx[http2]~=0.23.3
    Using cached httpx-0.23.3-py3-none-any.whl (71 kB)
  Collecting certifi
    Using cached certifi-2023.7.22-py3-none-any.whl (158 kB)
  Collecting httpcore<0.17.0,>=0.15.0
    Using cached httpcore-0.16.3-py3-none-any.whl (69 kB)
  Collecting rfc3986[idna2008]<2,>=1.3
    Using cached rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)
  Collecting sniffio
    Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)
  Collecting h2<5,>=3
    Using cached h2-4.1.0-py3-none-any.whl (57 kB)
  Collecting hyperframe<7,>=6.0
    Using cached hyperframe-6.0.1-py3-none-any.whl (12 kB)
  Collecting hpack<5,>=4.0
    Using cached hpack-4.0.0-py3-none-any.whl (32 kB)
  Collecting h11<0.15,>=0.13
    Using cached h11-0.14.0-py3-none-any.whl (58 kB)
  Collecting anyio<5.0,>=3.0
    Using cached anyio-4.0.0-py3-none-any.whl (83 kB)
  Collecting idna
    Using cached idna-3.4-py3-none-any.whl (61 kB)
  Installing collected packages: rfc3986, sniffio, idna, hyperframe, hpack, h11, certifi, h2, anyio, httpcore, httpx, python-telegram-bot
  Successfully installed anyio-4.0.0 certifi-2023.7.22 h11-0.14.0 h2-4.1.0 hpack-4.0.0 httpcore-0.16.3 httpx-0.23.3 hyperframe-6.0.1 idna-3.4 python-telegram-bot-20.1 rfc3986-1.5.0 sniffio-1.3.0
  WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  Collecting python-telegram-bot[job-queue]==20.1
    Using cached python_telegram_bot-20.1-py3-none-any.whl (518 kB)
  Collecting httpx[http2]~=0.23.3
    Using cached httpx-0.23.3-py3-none-any.whl (71 kB)
  Collecting APScheduler~=3.10.0
    Using cached APScheduler-3.10.4-py3-none-any.whl (59 kB)
  Collecting pytz>=2018.6
    Using cached pytz-2023.3.post1-py2.py3-none-any.whl (502 kB)
  Collecting six>=1.4.0
    Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
  Collecting tzlocal!=3.*,>=2.0
    Using cached tzlocal-5.0.1-py3-none-any.whl (20 kB)
  Collecting certifi
    Using cached certifi-2023.7.22-py3-none-any.whl (158 kB)
  Collecting httpcore<0.17.0,>=0.15.0
    Using cached httpcore-0.16.3-py3-none-any.whl (69 kB)
  Collecting rfc3986[idna2008]<2,>=1.3
    Using cached rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)
  Collecting sniffio
    Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)
  Collecting h2<5,>=3
    Using cached h2-4.1.0-py3-none-any.whl (57 kB)
  Collecting hyperframe<7,>=6.0
    Using cached hyperframe-6.0.1-py3-none-any.whl (12 kB)
  Collecting hpack<5,>=4.0
    Using cached hpack-4.0.0-py3-none-any.whl (32 kB)
  Collecting h11<0.15,>=0.13
    Using cached h11-0.14.0-py3-none-any.whl (58 kB)
  Collecting anyio<5.0,>=3.0
    Using cached anyio-4.0.0-py3-none-any.whl (83 kB)
  Collecting idna
    Using cached idna-3.4-py3-none-any.whl (61 kB)
  Installing collected packages: rfc3986, pytz, tzlocal, sniffio, six, idna, hyperframe, hpack, h11, certifi, h2, APScheduler, anyio, httpcore, httpx, python-telegram-bot
  Successfully installed APScheduler-3.10.4 anyio-4.0.0 certifi-2023.7.22 h11-0.14.0 h2-4.1.0 hpack-4.0.0 httpcore-0.16.3 httpx-0.23.3 hyperframe-6.0.1 idna-3.4 python-telegram-bot-20.1 pytz-2023.3.post1 rfc3986-1.5.0 six-1.16.0 sniffio-1.3.0 tzlocal-5.0.1
  WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  Collecting python-telegram-bot[callback-data]==20.1
    Using cached python_telegram_bot-20.1-py3-none-any.whl (518 kB)
  Collecting httpx[http2]~=0.23.3
    Using cached httpx-0.23.3-py3-none-any.whl (71 kB)
  Collecting cachetools~=5.3.0
    Using cached cachetools-5.3.1-py3-none-any.whl (9.3 kB)
  Collecting certifi
    Using cached certifi-2023.7.22-py3-none-any.whl (158 kB)
  Collecting httpcore<0.17.0,>=0.15.0
    Using cached httpcore-0.16.3-py3-none-any.whl (69 kB)
  Collecting rfc3986[idna2008]<2,>=1.3
    Using cached rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)
  Collecting sniffio
    Using cached sniffio-1.3.0-py3-none-any.whl (10 kB)
  Collecting h2<5,>=3
    Using cached h2-4.1.0-py3-none-any.whl (57 kB)
  Collecting hyperframe<7,>=6.0
    Using cached hyperframe-6.0.1-py3-none-any.whl (12 kB)
  Collecting hpack<5,>=4.0
    Using cached hpack-4.0.0-py3-none-any.whl (32 kB)
  Collecting h11<0.15,>=0.13
    Using cached h11-0.14.0-py3-none-any.whl (58 kB)
  Collecting anyio<5.0,>=3.0
    Using cached anyio-4.0.0-py3-none-any.whl (83 kB)
  Collecting idna
    Using cached idna-3.4-py3-none-any.whl (61 kB)
  Installing collected packages: rfc3986, sniffio, idna, hyperframe, hpack, h11, certifi, cachetools, h2, anyio, httpcore, httpx, python-telegram-bot
  Successfully installed anyio-4.0.0 cachetools-5.3.1 certifi-2023.7.22 h11-0.14.0 h2-4.1.0 hpack-4.0.0 httpcore-0.16.3 httpx-0.23.3 hyperframe-6.0.1 idna-3.4 python-telegram-bot-20.1 rfc3986-1.5.0 sniffio-1.3.0
  WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  Collecting watchdog
    Using cached watchdog-3.0.0-py3-none-manylinux2014_x86_64.whl (82 kB)
  Installing collected packages: watchdog
  Successfully installed watchdog-3.0.0
  WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  Collecting translate
    Using cached translate-3.6.1-py2.py3-none-any.whl (12 kB)
  Collecting click
    Using cached click-8.1.7-py3-none-any.whl (97 kB)
  Collecting lxml
    Using cached lxml-4.9.3-cp311-cp311-manylinux_2_28_x86_64.whl (7.9 MB)
  Collecting requests
    Using cached requests-2.31.0-py3-none-any.whl (62 kB)
  Collecting libretranslatepy==2.1.1
    Using cached libretranslatepy-2.1.1-py3-none-any.whl (3.2 kB)
  Collecting charset-normalizer<4,>=2
    Using cached charset_normalizer-3.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)
  Collecting idna<4,>=2.5
    Using cached idna-3.4-py3-none-any.whl (61 kB)
  Collecting urllib3<3,>=1.21.1
    Using cached urllib3-2.0.5-py3-none-any.whl (123 kB)
  Collecting certifi>=2017.4.17
    Using cached certifi-2023.7.22-py3-none-any.whl (158 kB)
  Installing collected packages: libretranslatepy, urllib3, lxml, idna, click, charset-normalizer, certifi, requests, translate
  Successfully installed certifi-2023.7.22 charset-normalizer-3.2.0 click-8.1.7 idna-3.4 libretranslatepy-2.1.1 lxml-4.9.3 requests-2.31.0 translate-3.6.1 urllib3-2.0.5
  WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
  Cloning into 'checkmk-telegram-plus'...
  remote: Enumerating objects: 331, done.
  remote: Counting objects: 100% (119/119), done.
  remote: Compressing objects: 100% (89/89), done.
  remote: Total 331 (delta 63), reused 68 (delta 30), pack-reused 212
  Receiving objects: 100% (331/331), 7.77 MiB | 7.85 MiB/s, done.
  Resolving deltas: 100% (138/138), done.
  THE INSTALLATION HAS BEEN COMPLETED. NOW CREATE A NOTIFICATION RULE AS EXPLAINED IN THE GIT REPOSITORY.

The telegram-plus.log then showed

2023-09-28 08:52:21,707:WARNING:log_unauthenticated_access:Virus2500 tried to execute the command 'โš™๏ธ ADMIN SETTINGS' but was not authorised to do so!

I then authenticated again
image

But now the bot is constantly crashing because this is all i get

image

โ””โ”€โ•ผ # journalctl -f -u checkmk-telegram-plus-main.service
Sep 28 09:12:35 checkmk systemd[1]: checkmk-telegram-plus-main.service: Failed with result 'exit-code'.
Sep 28 09:12:35 checkmk systemd[1]: checkmk-telegram-plus-main.service: Scheduled restart job, restart counter is at 10.
Sep 28 09:12:35 checkmk systemd[1]: Stopped checkmk-telegram-plus-main.service - CheckMK Telegram Plus Service.
Sep 28 09:12:35 checkmk systemd[1]: Starting checkmk-telegram-plus-main.service - CheckMK Telegram Plus Service...
Sep 28 09:13:35 checkmk systemd[1]: Started checkmk-telegram-plus-main.service - CheckMK Telegram Plus Service.
Sep 28 09:13:41 checkmk systemd[1]: checkmk-telegram-plus-main.service: Main process exited, code=exited, status=137/n/a
Sep 28 09:13:41 checkmk systemd[1]: checkmk-telegram-plus-main.service: Failed with result 'exit-code'.
Sep 28 09:13:41 checkmk systemd[1]: checkmk-telegram-plus-main.service: Scheduled restart job, restart counter is at 11.
Sep 28 09:13:41 checkmk systemd[1]: Stopped checkmk-telegram-plus-main.service - CheckMK Telegram Plus Service.
Sep 28 09:13:41 checkmk systemd[1]: Starting checkmk-telegram-plus-main.service - CheckMK Telegram Plus Service...

The var/log/telegram-plus.log remains silent so there are no new logs after i authenticated.

If there is another log file or a switch i can use to produce more debug output for you please let me know.

Thanks and br
Mike

/cancel not cancelling the entire conversation when using "reschedule check"

Hi again :)

Cancel seems not to cancel the entire conversation.

Steps to reproduce:

  1. hit reschedule check
  2. select a hostgroup (and missclick on a group you don't want)
  3. type /cancel
    bot replies with "Conversation cancelled X"
  4. hit reschedule again
    bot replies (without letting you select a hostgroup etc)
Failed to lookup IPv4 address of ๐Ÿ”„ RESCHEDULE CHECK via DNS: [Errno -2] Name or service not known

RESCHEDULE CHECK WAS COMPLETED SUCCESSFULLY

Response Error

Hi, after click HELP i have an error

Response Error: b')]}'\n\n38\n[["wrb.fr",null,null,null,null,[9]]]\n56\n[["di",90],["af.httprm",89,"-2829122135122531690",14]]\n25\n[["e",4,null,null,131]]\n'.
Unable to get response.
Please double-check the cookie values and verify your network environment or google account.

Issue with checkmk Plugin on GitHub After Language Change

I've been using the Telegram plugin on checkmk without any issues for months. However, after I changed the language settings to German yesterday, the checkmk server started exhibiting high resource usage, with 100% CPU and RAM utilization, leading to significant performance degradation. Stopping the Telegram plugin seems to alleviate the issue, indicating a possible link between the plugin and the server's performance problems.

I have tried uninstalling and reinstalling the plugin, but the issue persists, and I haven't found any clear error messages to diagnose the problem. I even increased the RAM allocation to 5GB and the CPU allocation to 6 cores, considering it's running on a current i7 processor, but the issue still remains.

The log doesn't provide much useful information. Here's what I see when I run the telegram_bot.py script:

root@checkmk:~# su - $omd_site_name
OMD[monitoring]:~$ cd local/share/checkmk-telegram-plus
OMD[monitoring]:~/local/share/checkmk-telegram-plus$ python3 telegram_bot.py
Run time of job "message_all_users (trigger: date[2024-02-03 09:07:46 UTC], next run at: 2024-02-03 09:07:46 UTC)" was missed by 0:00:02.938143
Killed
OMD[monitoring]:~/local/share/checkmk-telegram-plus$

I'm looking for assistance in resolving this issue. The sudden increase in resource utilization seems to be correlated with the language change in the Telegram plugin, and I need help identifying the root cause and implementing a solution.

Edit:
I have change de to en in config.ini same ...

I see in my logs 1100000000000000000 errors all same:
2024-01-31 14:07:36,629:CRITICAL:notifcation_listener:[Errno 2] No such file or directory: '/omd/sites/monitoring/tmp/telegram_plus/notifications.queue'

edit2:
i have create a folder tmp/telegram_plus/notifications.queue now its working ... also with language de .. crazy.

Please new cool Updates :)

CLOSE

AI setup not working

When trying to use the AI functions, I only get the message
"It seems that your AI is not configured. Have you configured the AI as described in the documentation?".
So it seems to not see the ai section in the config.ini, but:

AI model and API key are set and show up in the ai section of the config.ini.

I tried to add single and double quotes in the config ini, just in case ..., but it didn't help.

Since Checkmk is running on a headless server, I tried the cookie value from an X11 forwarded Epiphany browser as well as from a regular Windows host, same results.

Everything else is working (great tool!), so I would exclude permission issues with the config.ini.

Any idea?

Notification suddenly stops working

Hi Alexander, I have the problem that the notification suddenly stops working.

Under Administration / List notification Queue there are tonns of notification ids listed. I have activated the notification via email at the same time and receive all notifications there.

When I switch between activating the loud and/or silent option it seems to work again - although silent was always active - I also see this in the user list.

Version 2.1.0 is installed - CheckMk runs on a Proxmox Debian CT

Sometimes after playing with the loud/silen options many new entries come in like a wave... What else can I do so that I don't miss any notifications?

Best reagrds,
HP

Failed notification on fresh install / wrong line endings

On a fresh install of this project following the installation instructions, CheckMK cannot send notifications with the following error message:
[Errno 2] No such file or directory: '/omd/sites/<sitename>/local/share/check_mk/notifications/telegram_plus_notify_listener'

The problem is that the telegram_plus_notify_listener script uses windows-style line endings (CR LF) instead of unix ones (LF). This is not allowed for a shebang, causing this error:

-bash: /omd/sites/<sitename>/local/share/check_mk/notifications/telegram_plus_notify_listener: /bin/bash^M: bad interpreter: No such file or directory

After converting the line endings to unix, the script successfully runs.

Wouldn't start on Debian 11

Hi,

thanks for the extension. Just one minor problem occured to me during the install: The bot simply wouldn't start via systemd.

Jun 21 23:24:27 checkmk systemd[1523085]: checkmk-telegram-plus-main.service: Failed to locate executable /usr/sbin/runuser: No such file or directory
Jun 21 23:24:27 checkmk systemd[1523085]: checkmk-telegram-plus-main.service: Failed at step EXEC spawning /usr/sbin/runuser: No such file or directory

Now in Debian 11 runuser is in /sbin

โ”Œโ”€[โœ—]โ”€[root@checkmk]-[/etc/systemd/system]
โ””โ”€โ•ผ # which runuser
/sbin/runuser

I changed my unit file to this

[Unit]
Description=CheckMK Telegram Plus Service

[Service]
# Wait for the OMD Page to fully start
ExecStartPre=/bin/sleep 60
User=main
WorkingDirectory=/omd/sites/main/local/share/checkmk-telegram-plus
# The service must be started as follows, as required environment variables are not set if the service is only executed in the name of this user.
ExecStart=/omd/sites/main/bin/python3 /omd/sites/main/local/share/checkmk-telegram-plus/telegram_bot.py
Restart=always

[Install]
WantedBy=multi-user.target

I have read the message "The service must be started as follows, as required environment variables are not set if the service is only executed in the name of this user." but couldn't find (yet) anything that isn't working so... i don't know if this would impact other systems.

Maybe you could even remove the need for ExecStart=/omd/sites/main/bin/python3 with an shebang in telegram_bot.py since which as the user already points to the right python version?

OMD[main]:~$ which python3
/omd/sites/main/bin/python3

thanks again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.