Skip to content

Instantly share code, notes, and snippets.

@arsalanses
Created February 1, 2023 19:12
Show Gist options
  • Select an option

  • Save arsalanses/7fec37d0324b29325380df0dff582e4f to your computer and use it in GitHub Desktop.

Select an option

Save arsalanses/7fec37d0324b29325380df0dff582e4f to your computer and use it in GitHub Desktop.
telegram bot for checking docker health
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