Skip to content

Commit

Permalink
fix: added fromAddress for notification emails
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Sep 20, 2024
1 parent 3fc58a8 commit 71e2b01
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"])
Expand Down
3 changes: 2 additions & 1 deletion src/DIRAC/DataManagementSystem/scripts/dirac_admin_ban_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"])
Expand Down
3 changes: 2 additions & 1 deletion src/DIRAC/Interfaces/scripts/dirac_admin_allow_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
3 changes: 2 additions & 1 deletion src/DIRAC/Interfaces/scripts/dirac_admin_ban_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
5 changes: 4 additions & 1 deletion src/DIRAC/ResourceStatusSystem/Agent/TokenAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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}"')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ def notify(self, request, params):
address = Operations().getValue("ResourceStatus/Notification/DebugGroup/Users")
msg = "Matching parameters: " + str(params)
sbj = "[NOTIFICATION] DIRAC ResourceStatusDB: " + request + " entry"
NotificationClient().sendMail(address, sbj, msg, address)
fromAddress = Operations().getValue("ResourceStatus/Config/FromAddress", "")
NotificationClient().sendMail(address, sbj, msg, address, fromAddress=fromAddress)

def _extermineStatusElement(self, element, name, keepLogs=True):
"""
Expand Down

0 comments on commit 71e2b01

Please sign in to comment.