updat scrip
This commit is contained in:
parent
1444b9401c
commit
9d04be773f
|
@ -1,4 +1,5 @@
|
||||||
from discord_webhook import DiscordWebhook, DiscordEmbed
|
from discord_webhook import DiscordWebhook, DiscordEmbed
|
||||||
|
from mextract import mextract
|
||||||
|
|
||||||
webhookURL = "https://discordapp.com/api/webhooks/742784012640190565/NBhtbWpDdgMZPx7uCXO8Ofw-o8Lez0V17EBGIvYv7FTIeTENK24GHNL3krUbYnOOIJ63"
|
webhookURL = "https://discordapp.com/api/webhooks/742784012640190565/NBhtbWpDdgMZPx7uCXO8Ofw-o8Lez0V17EBGIvYv7FTIeTENK24GHNL3krUbYnOOIJ63"
|
||||||
maxCharPerMessage = 1994
|
maxCharPerMessage = 1994
|
||||||
|
@ -7,7 +8,7 @@ with open ("/etc/bacula/scripts/webhooks/ChrisProEliteMail.md", "r") as myfile:
|
||||||
cleaned_stdout=myfile.read()
|
cleaned_stdout=myfile.read()
|
||||||
|
|
||||||
if "Termination: Backup OK" in cleaned_stdout:
|
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:
|
else:
|
||||||
# Discord limits each message to 2000 chars, if the message is longer than that, truncate it
|
# 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)]
|
truncated_stdout = [cleaned_stdout[i:i+maxCharPerMessage] for i in range(0, len(cleaned_stdout), maxCharPerMessage)]
|
||||||
|
|
|
@ -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: No Jobs found to prune.
|
||||||
11-Aug 12:43 bacula-dir JobId 310: Begin pruning Files.
|
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: 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.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from discord_webhook import DiscordWebhook, DiscordEmbed
|
from discord_webhook import DiscordWebhook, DiscordEmbed
|
||||||
from datetime import datetime
|
from mextract import mextract
|
||||||
|
|
||||||
webhookURL = "https://discordapp.com/api/webhooks/740630755259973713/CNhxPBJ4C6UZ-m1DVXUQ54KeJQD3I9Di0sAwldmyjw-s7dMPUWplq7rhGXegpWGtKSve"
|
webhookURL = "https://discordapp.com/api/webhooks/740630755259973713/CNhxPBJ4C6UZ-m1DVXUQ54KeJQD3I9Di0sAwldmyjw-s7dMPUWplq7rhGXegpWGtKSve"
|
||||||
maxCharPerMessage = 1994
|
maxCharPerMessage = 1994
|
||||||
|
@ -8,7 +8,7 @@ with open ("/etc/bacula/scripts/webhooks/RoboticsMail.md", "r") as myfile:
|
||||||
cleaned_stdout=myfile.read()
|
cleaned_stdout=myfile.read()
|
||||||
|
|
||||||
if "Termination: Backup OK" in cleaned_stdout:
|
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:
|
else:
|
||||||
# Discord limits each message to 2000 chars, if the message is longer than that, truncate it
|
# 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)]
|
truncated_stdout = [cleaned_stdout[i:i+maxCharPerMessage] for i in range(0, len(cleaned_stdout), maxCharPerMessage)]
|
||||||
|
|
|
@ -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: No Jobs found to prune.
|
||||||
11-Aug 02:56 bacula-dir JobId 308: Begin pruning Files.
|
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: 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.
|
Binary file not shown.
|
@ -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]")
|
Loading…
Reference in New Issue