Browse Source

added google ping to telegram

tsi 2 years ago
parent
commit
888bad39e9
1 changed files with 9 additions and 6 deletions
  1. 9 6
      send_email.py

+ 9 - 6
send_email.py

@@ -43,7 +43,7 @@ def send_to_telegram(bot_token, chat_id, caption, *image_paths):
     if response.status_code != 200:
         raise ValueError(f"Request to Telegram API returned an error: {response.status_code}, {response.text}")
 
-def create_email(sender_email, recipient_emails, subject, boot_time_str, image_path1, image_path2):
+def create_email(sender_email, recipient_emails, subject, boot_time_str, image_path1, image_path2, image_path3):
     msg = MIMEMultipart("related")
     msg["From"] = sender_email
     msg["To"] = ",".join(recipient_emails)
@@ -93,12 +93,15 @@ def get_boot_time():
     return boot_time
 
 tmpdir = tempfile.TemporaryDirectory()
-beginning = str(1000 * (int(time.time())) - (17 * 3600000))[:-3]
+beginning = str(1000 * (int(time.time())) - (24 * 3600000))[:-3]
 end = str(1000 * int(time.time()))[:-3]
 
-urllib.request.urlretrieve("http://localhost/cacti/graph_image.php?local_graph_id=109&graph_start=" + beginning + "&graph_end=" + end + "&graph_width=700&graph_height=200", tmpdir.name + "/ping.png")
+urllib.request.urlretrieve("http://localhost/cacti/graph_image.php?local_graph_id=109&graph_start=" + beginning + "&graph_end=" + end + "&graph_width=350&graph_height=100", tmpdir.name + "/ping.png")
+
+urllib.request.urlretrieve("http://localhost/cacti/graph_image.php?local_graph_id=103&graph_start=" + beginning + "&graph_end=" + end + "&graph_width=700&graph_height=198", tmpdir.name + "/traffic.png")
+
+urllib.request.urlretrieve("http://localhost/cacti/graph_image.php?local_graph_id=120&graph_start=" + beginning + "&graph_end=" + end + "&graph_width=350&graph_height=80", tmpdir.name + "/ping_google.png")
 
-urllib.request.urlretrieve("http://localhost/cacti/graph_image.php?local_graph_id=103&graph_start=" + beginning + "&graph_end=" + end + "&graph_width=695&graph_height=198", tmpdir.name + "/traffic.png")
 
 # Bot token and chat ID for Telegram
 bot_token = "949332240:AAHNsQEmCW4it86Esa7F5o07XxwrotSM7s8"
@@ -111,12 +114,12 @@ subject = datetime.today().strftime('%Y-%m-%d') + ' Darmstadt'
 sender_email = 'pv-tannenstr@web.de'
 recipient_emails = ["tobias.siegel@outlook.com", "wsiegel@web.de"]
 
-email_msg = create_email(sender_email, recipient_emails, subject, boot_time_str, tmpdir.name + "/traffic.png", tmpdir.name + "/ping.png")
+email_msg = create_email(sender_email, recipient_emails, subject, boot_time_str, tmpdir.name + "/traffic.png", tmpdir.name + "/ping.png", tmpdir.name + "/ping_google.png")
 
 send_email(sender_email, recipient_emails, email_msg)
 
 try:
-    send_to_telegram(bot_token, chat_id, f"<b>{subject}</b>\nLetzter Start: {boot_time_str} Uhr", tmpdir.name + "/traffic.png", tmpdir.name + "/ping.png")
+    send_to_telegram(bot_token, chat_id, f"<b>{subject}</b>\nLetzter Start: {boot_time_str} Uhr", tmpdir.name + "/traffic.png", tmpdir.name + "/ping.png", tmpdir.name + "/ping_google.png")
     logging.info("Telegram message sent successfully.")
 except ValueError as e:
     logging.error(f"Failed to send images to Telegram: {e}")