From 66af23c19f72e0a209173fc8e63403285cc7f086 Mon Sep 17 00:00:00 2001 From: Federico Stagni Date: Sun, 22 Sep 2024 16:37:24 +0200 Subject: [PATCH] sweep: #7800 fix: added fromAddress for notification emails --- .../DataManagementSystem/scripts/dirac_admin_allow_se.py | 3 ++- src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py | 3 ++- src/DIRAC/Interfaces/scripts/dirac_admin_allow_site.py | 3 ++- src/DIRAC/Interfaces/scripts/dirac_admin_ban_site.py | 3 ++- src/DIRAC/ResourceStatusSystem/Agent/TokenAgent.py | 5 ++++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/DIRAC/DataManagementSystem/scripts/dirac_admin_allow_se.py b/src/DIRAC/DataManagementSystem/scripts/dirac_admin_allow_se.py index 60668b8d77b..5f7fb48258e 100755 --- a/src/DIRAC/DataManagementSystem/scripts/dirac_admin_allow_se.py +++ b/src/DIRAC/DataManagementSystem/scripts/dirac_admin_allow_se.py @@ -162,6 +162,7 @@ def main(): subject = f"{len(totalAllowedSEs)} storage elements allowed for use" addressPath = "EMail/Production" address = Operations().getValue(addressPath, "") + fromAddress = Operations().getValue("ResourceStatus/Config/FromAddress", "") body = "" if read: @@ -185,7 +186,7 @@ def main(): gLogger.notice(f"'{addressPath}' not defined in Operations, can not send Mail\n", body) DIRAC.exit(0) - res = diracAdmin.sendMail(address, subject, body) + res = diracAdmin.sendMail(address, subject, body, fromAddress=fromAddress) gLogger.notice(f"Notifying {address}") if res["OK"]: gLogger.notice(res["Value"]) diff --git a/src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py b/src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py index c1d065b6784..b0ae844875a 100755 --- a/src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py +++ b/src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py @@ -204,6 +204,7 @@ def main(): subject = f"{len(writeBanned + readBanned + checkBanned + removeBanned)} storage elements banned for use" addressPath = "EMail/Production" address = Operations().getValue(addressPath, "") + fromAddress = Operations().getValue("ResourceStatus/Config/FromAddress", "") body = "" if read: @@ -227,7 +228,7 @@ def main(): gLogger.notice(f"'{addressPath}' not defined in Operations, can not send Mail\n", body) DIRAC.exit(0) - res = diracAdmin.sendMail(address, subject, body) + res = diracAdmin.sendMail(address, subject, body, fromAddress=fromAddress) gLogger.notice(f"Notifying {address}") if res["OK"]: gLogger.notice(res["Value"]) diff --git a/src/DIRAC/Interfaces/scripts/dirac_admin_allow_site.py b/src/DIRAC/Interfaces/scripts/dirac_admin_allow_site.py index 574932999cc..09d3a8102af 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_admin_allow_site.py +++ b/src/DIRAC/Interfaces/scripts/dirac_admin_allow_site.py @@ -83,7 +83,8 @@ def getBoolean(value): if not address: gLogger.notice(f"'{addressPath}' not defined in Operations, can not send Mail\n", body) else: - result = diracAdmin.sendMail(address, subject, body) + fromAddress = Operations().getValue("ResourceStatus/Config/FromAddress", "") + result = diracAdmin.sendMail(address, subject, body, fromAddress=fromAddress) else: print("Automatic email disabled by flag.") diff --git a/src/DIRAC/Interfaces/scripts/dirac_admin_ban_site.py b/src/DIRAC/Interfaces/scripts/dirac_admin_ban_site.py index bf350b2277f..2bea4e45360 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_admin_ban_site.py +++ b/src/DIRAC/Interfaces/scripts/dirac_admin_ban_site.py @@ -85,7 +85,8 @@ def getBoolean(value): if not address: gLogger.notice(f"'{addressPath}' not defined in Operations, can not send Mail\n", body) else: - result = diracAdmin.sendMail(address, subject, body) + fromAddress = Operations().getValue("ResourceStatus/Config/FromAddress", "") + result = diracAdmin.sendMail(address, subject, body, fromAddress=fromAddress) else: print("Automatic email disabled by flag.") diff --git a/src/DIRAC/ResourceStatusSystem/Agent/TokenAgent.py b/src/DIRAC/ResourceStatusSystem/Agent/TokenAgent.py index 84a3d9208f3..0ff0f279963 100644 --- a/src/DIRAC/ResourceStatusSystem/Agent/TokenAgent.py +++ b/src/DIRAC/ResourceStatusSystem/Agent/TokenAgent.py @@ -13,10 +13,12 @@ from datetime import datetime, timedelta from DIRAC import S_OK, S_ERROR +from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations from DIRAC.Core.Base.AgentModule import AgentModule from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient + AGENT_NAME = "ResourceStatus/TokenAgent" @@ -209,7 +211,8 @@ def _notify(self, tokenOwner, expired, expiring): mail += " Or you can use the dirac-rss-set-token script\n\n" mail += "Through the same interfaces you can release the token any time\n" - resEmail = self.diracAdmin.sendMail(tokenOwner, subject, mail) + fromAddress = Operations().getValue("ResourceStatus/Config/FromAddress", "") + resEmail = self.diracAdmin.sendMail(tokenOwner, subject, mail, fromAddress=fromAddress) if not resEmail["OK"]: return S_ERROR(f'Cannot send email to user "{tokenOwner}"')