Commit 519d7643 authored by Dainius Simelevicius's avatar Dainius Simelevicius
Browse files

references #185: added hotspotmailer.py script to sentinel/utils package

parent ce4fba0b
......@@ -2,12 +2,12 @@
#########################################################################
# XDAQ Components for Distributed Data Acquisition #
# Copyright (C) 2000-2009, CERN. #
# Copyright (C) 2000-2020, CERN. #
# All rights reserved. #
# Authors: J. Gutleber and L. Orsini #
# Authors: J. Gutleber, L. Orsini and D. Simelevicius #
# #
# For the licensing terms see LICENSE. #
# For the list of contributors see CREDITS. #
# For the licensing terms see LICENSE. #
# For the list of contributors see CREDITS. #
#########################################################################
##
......
......@@ -2,12 +2,12 @@
/*************************************************************************
* XDAQ Components for Distributed Data Acquisition *
* Copyright (C) 2000-2009, CERN. *
* Copyright (C) 2000-2020, CERN. *
* All rights reserved. *
* Authors: J. Gutleber and L. Orsini *
* Authors: J. Gutleber, L. Orsini and D. Simelevicius *
* *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
* For the licensing terms see LICENSE. *
* For the list of contributors see CREDITS. *
*************************************************************************/
#ifndef _sentinelutils_version_h_
......@@ -17,10 +17,11 @@
// !!! Edit this line to reflect the latest package version !!!
#define WORKSUITE_SENTINELUTILS_VERSION_MAJOR 2
#define WORKSUITE_SENTINELUTILS_VERSION_MINOR 2
#define WORKSUITE_SENTINELUTILS_VERSION_MINOR 3
#define WORKSUITE_SENTINELUTILS_VERSION_PATCH 0
// If any previous versions available E.g. #define WORKSUITE_SENTINELUTILS_PREVIOUS_VERSIONS "3.8.0,3.8.1"
#undef WORKSUITE_SENTINELUTILS_PREVIOUS_VERSIONS
#define WORKSUITE_SENTINELUTILS_PREVIOUS_VERSIONS "2.2.0"
//
......
import sys
import http.client
import json
import datetime
from smtplib import SMTP
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import urllib.parse
import time
def exception_history(input):
originatedby = ""
if 'children' in input:
originatedby = "originated by " + exception_history(input["children"][0])
output = "<b>" + input["label"] + "</b>"
output += "<br><table>"
for property in input["properties"]:
output += "<tr>"
output += "<td>" + property["name"] + "</td>"
value = property["value"]
if property["name"] == "message":
value = urllib.parse.unquote(value)
output += "<td>" + value + "</td>"
output += "</tr>"
output += "</table><br>"
output += originatedby
return output
def display_exception_to_html(input):
return "<html>" + exception_history(input) + "</html>"
if sys.version_info[0] != 3:
raise Exception("Python 3 is required!")
parameterCount = len(sys.argv)
if parameterCount != 3:
print("Usage python3 hotspotmailer.py <spotlight url> <zone>")
exit()
spotlightUrl = sys.argv[1]
zone = sys.argv[2]
print("spotlightUrl = " + sys.argv[1])
print
connection = http.client.HTTPConnection(spotlightUrl)
#connection.set_debuglevel(1)
connection.request('GET', '/urn:xdaq-application:service=sentinelspotlight2g/lastStoredEvents')
response = connection.getresponse()
result = response.read().decode()
if (response.status != 200):
print("response.status = " + response.status, "response.reason = " + response.reason)
exit()
connection.close()
events = json.loads(result)
lastStoreTime = events["lastStoreTime"]
print("lastStoreTime = '" + lastStoreTime + "'")
local_address = zone + "@hotspot.cern.ch"
egroup_address = "cms-os-forward-" + zone + "@cern.ch"
severity_icons = {"fatal": "🟥", "error": "🟧", "warning": "🟨"}
while 1:
connection.request('GET', '/urn:xdaq-application:service=sentinelspotlight2g/lastStoredEvents?start=' + lastStoreTime)
response = connection.getresponse()
result = response.read().decode()
if (response.status != 200):
print("response.status = " + response.status, "response.reason = " + response.reason)
exit()
connection.close()
events = json.loads(result)
lastStoreTime = events["lastStoreTime"]
print("lastStoreTime = '" + lastStoreTime + "'")
for row in events["table"]["rows"]:
connection.request('GET', '/urn:xdaq-application:service=sentinelspotlight2g/view?uniqueid=' + row["exception"])
response = connection.getresponse()
result = response.read().decode()
if (response.status != 200):
print("response.status = " + response.status, "response.reason = " + response.reason)
exit()
connection.close()
exception = json.loads(result)
severity = row["severity"]
severity_icon = ""
if severity in severity_icons:
severity_icon = severity_icons[severity] + " "
message_text = urllib.parse.unquote(row["message"])
message = MIMEMultipart("alternative")
message["Subject"] = severity_icon + severity + ": " + message_text
message["From"] = local_address
message["To"] = egroup_address
body = MIMEText(display_exception_to_html(exception), "html")
message.attach(body)
email_server = SMTP("cernmx.cern.ch", 25)
email_server.starttls()
email_server.sendmail(local_address, egroup_address, message.as_string())
email_server.quit()
time.sleep(10)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment