Created
February 1, 2023 19:12
-
-
Save arsalanses/7fec37d0324b29325380df0dff582e4f to your computer and use it in GitHub Desktop.
telegram bot for checking docker health
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import telegram | |
| import subprocess | |
| bot = telegram.Bot(token='YOUR_BOT_TOKEN') | |
| chat_id = 'YOUR_CHAT_ID' | |
| def check_docker_health(container_name): | |
| try: | |
| output = subprocess.check_output(["docker", "inspect", "-f", "{{json .State.Health.Status}}", container_name]) | |
| if "healthy" in output: | |
| return "Container is healthy" | |
| else: | |
| return "Container is not healthy" | |
| except subprocess.CalledProcessError as e: | |
| return f"Error: {e.output}" | |
| container_name = "my-telegram-bot" | |
| status = check_docker_health(container_name) | |
| bot.send_message(chat_id=chat_id, text=status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment