From 9d04be773f576760e1b3c50e57c66833966e2717 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 11 Aug 2020 15:45:54 -0400 Subject: [PATCH] updat scrip --- .../webhooks/ChrisProElite-Bacula-Webhook.py | 3 ++- Dir Config/scripts/webhooks/ChrisProEliteMail.md | 3 +-- .../scripts/webhooks/Robotics-Bacula-Webhook.py | 4 ++-- Dir Config/scripts/webhooks/RoboticsMail.md | 2 +- .../webhooks/__pycache__/mextract.cpython-38.pyc | Bin 0 -> 386 bytes Dir Config/scripts/webhooks/mextract.py | 9 +++++++++ 6 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 Dir Config/scripts/webhooks/__pycache__/mextract.cpython-38.pyc create mode 100644 Dir Config/scripts/webhooks/mextract.py diff --git a/Dir Config/scripts/webhooks/ChrisProElite-Bacula-Webhook.py b/Dir Config/scripts/webhooks/ChrisProElite-Bacula-Webhook.py index b51c0a9..e3a94a3 100644 --- a/Dir Config/scripts/webhooks/ChrisProElite-Bacula-Webhook.py +++ b/Dir Config/scripts/webhooks/ChrisProElite-Bacula-Webhook.py @@ -1,4 +1,5 @@ from discord_webhook import DiscordWebhook, DiscordEmbed +from mextract import mextract webhookURL = "https://discordapp.com/api/webhooks/742784012640190565/NBhtbWpDdgMZPx7uCXO8Ofw-o8Lez0V17EBGIvYv7FTIeTENK24GHNL3krUbYnOOIJ63" maxCharPerMessage = 1994 @@ -7,7 +8,7 @@ with open ("/etc/bacula/scripts/webhooks/ChrisProEliteMail.md", "r") as myfile: cleaned_stdout=myfile.read() if "Termination: Backup OK" in cleaned_stdout: - truncated_stdout = ["Job Backup-Chris completed with status Backup OK, omitting full report.\nAll data from nextcloud was successfully written to tape on " + datetime.now().strftime("%d/%m/%Y %H:%M:%S") + "."] + truncated_stdout = ["Job Backup-Chris completed with status Backup OK, omitting full report.\nAll data from nextcloud was successfully written to tape on " + mextract(cleaned_stdout, "End time:") + ".\nBackup took " + mextract(cleaned_stdout, "Elapsed time:") + " And used " + mextract(cleaned_stdout, "SD Bytes Written:") + " bytes."] else: # Discord limits each message to 2000 chars, if the message is longer than that, truncate it truncated_stdout = [cleaned_stdout[i:i+maxCharPerMessage] for i in range(0, len(cleaned_stdout), maxCharPerMessage)] diff --git a/Dir Config/scripts/webhooks/ChrisProEliteMail.md b/Dir Config/scripts/webhooks/ChrisProEliteMail.md index 982d684..cf1bc2b 100644 --- a/Dir Config/scripts/webhooks/ChrisProEliteMail.md +++ b/Dir Config/scripts/webhooks/ChrisProEliteMail.md @@ -48,5 +48,4 @@ 11-Aug 12:43 bacula-dir JobId 310: No Jobs found to prune. 11-Aug 12:43 bacula-dir JobId 310: Begin pruning Files. 11-Aug 12:43 bacula-dir JobId 310: No Files found to prune. -11-Aug 12:43 bacula-dir JobId 310: End auto prune. - +11-Aug 12:43 bacula-dir JobId 310: End auto prune. \ No newline at end of file diff --git a/Dir Config/scripts/webhooks/Robotics-Bacula-Webhook.py b/Dir Config/scripts/webhooks/Robotics-Bacula-Webhook.py index ddf3cb3..2309bbe 100644 --- a/Dir Config/scripts/webhooks/Robotics-Bacula-Webhook.py +++ b/Dir Config/scripts/webhooks/Robotics-Bacula-Webhook.py @@ -1,5 +1,5 @@ from discord_webhook import DiscordWebhook, DiscordEmbed -from datetime import datetime +from mextract import mextract webhookURL = "https://discordapp.com/api/webhooks/740630755259973713/CNhxPBJ4C6UZ-m1DVXUQ54KeJQD3I9Di0sAwldmyjw-s7dMPUWplq7rhGXegpWGtKSve" maxCharPerMessage = 1994 @@ -8,7 +8,7 @@ with open ("/etc/bacula/scripts/webhooks/RoboticsMail.md", "r") as myfile: cleaned_stdout=myfile.read() if "Termination: Backup OK" in cleaned_stdout: - truncated_stdout = ["Job Backup-Robotics completed with status Backup OK, omitting full report.\nAll data from google drive was successfully written to tape on " + datetime.now().strftime("%d/%m/%Y %H:%M:%S") + "."] + truncated_stdout = ["Job Backup-Robotics completed with status Backup OK, omitting full report.\nAll data from 1721's google drive was successfully written to tape on " + mextract(cleaned_stdout, "End time:") + ".\nBackup took " + mextract(cleaned_stdout, "Elapsed time:") + " And used " + mextract(cleaned_stdout, "SD Bytes Written:") + " bytes."] else: # Discord limits each message to 2000 chars, if the message is longer than that, truncate it truncated_stdout = [cleaned_stdout[i:i+maxCharPerMessage] for i in range(0, len(cleaned_stdout), maxCharPerMessage)] diff --git a/Dir Config/scripts/webhooks/RoboticsMail.md b/Dir Config/scripts/webhooks/RoboticsMail.md index 39c711a..81d4706 100644 --- a/Dir Config/scripts/webhooks/RoboticsMail.md +++ b/Dir Config/scripts/webhooks/RoboticsMail.md @@ -44,4 +44,4 @@ 11-Aug 02:56 bacula-dir JobId 308: No Jobs found to prune. 11-Aug 02:56 bacula-dir JobId 308: Begin pruning Files. 11-Aug 02:56 bacula-dir JobId 308: No Files found to prune. -11-Aug 02:56 bacula-dir JobId 308: End auto prune. +11-Aug 02:56 bacula-dir JobId 308: End auto prune. \ No newline at end of file diff --git a/Dir Config/scripts/webhooks/__pycache__/mextract.cpython-38.pyc b/Dir Config/scripts/webhooks/__pycache__/mextract.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..96e867ccfa88adcbfa5f1d146aaec6ce6e6eb01c GIT binary patch literal 386 zcmYjNJ5R$f5I#F;6pAV_RASB8FfL%m%K7{ zgprAJM5W&8&iCEpv+mAEqamQY{~X?Z5V~uu zKwQ|)jW`&1XlH2Z2;DN!(2@ox_Mw4}u4qGB%4kPgr-MsKfb@C|%t_!1f3nQ+axj@5 zgu^wl6yuwVOwO~sJhn%xsXb`cpvxVTh6u{|9Bx-UGfvVkFp2zoj;)tRtEq8 literal 0 HcmV?d00001 diff --git a/Dir Config/scripts/webhooks/mextract.py b/Dir Config/scripts/webhooks/mextract.py new file mode 100644 index 0000000..796912c --- /dev/null +++ b/Dir Config/scripts/webhooks/mextract.py @@ -0,0 +1,9 @@ +import re + + +def mextract(report, variable): + try: + result = re.search(variable + '(.*)\n', report) + return(result.group(1).lstrip()) # lstrip removes leading spaces. + except: + return("[Variable Not found]") \ No newline at end of file