Commit d02bac34 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Move check for hasReportedError

   Moving logic to SoftwareInstallation_hasReportedError allow us reuse the logic on SupportRequest_recheckMonitoring script.
parent 30e3c4d7
from DateTime import DateTime from DateTime import DateTime
portal = context.getPortalObject() portal = context.getPortalObject()
if (context.getMonitorScope() == "disabled"): if context.getMonitorScope() == "disabled":
return return
project = context.getFollowUpValue() project = context.getFollowUpValue()
...@@ -16,48 +16,16 @@ software_installation_list = portal.portal_catalog( ...@@ -16,48 +16,16 @@ software_installation_list = portal.portal_catalog(
) )
support_request_list = [] support_request_list = []
compute_node_reference = context.getReference()
compute_node_title = context.getTitle()
should_notify = True should_notify = True
tolerance = DateTime()-0.5 tolerance = DateTime() - 0.5
for software_installation in software_installation_list: for software_installation in software_installation_list:
should_notify = False should_notify = False
if software_installation.getCreationDate() > tolerance: should_notify, ticket_title, description, last_contact = \
# Give it 12 hours to deploy. software_installation.SoftwareInstallation_hasReportedError(
continue tolerance=tolerance)
if software_installation.getSlapState() != 'start_requested':
continue
reference = software_installation.getReference()
d = software_installation.getAccessStatus()
if d.get("no_data", None) == 1:
#should_notify = True
# We do not create if there is no information for the compilation
# it should be reported by more global alarm related to the compute node itself
last_contact = "No Contact Information"
ticket_title = "[MONITORING] No information for %s on %s" % (reference, compute_node_reference)
description = "The software release %s did not started to build on %s since %s" % \
(software_installation.getUrlString(), compute_node_title, software_installation.getCreationDate())
else:
last_contact = DateTime(d.get('created_at'))
if d.get("text").startswith("#building"):
should_notify = True
ticket_title = "[MONITORING] %s is building for too long on %s" % (reference, compute_node_reference)
description = "The software release %s is building for mode them 12 hours on %s, started on %s" % \
(software_installation.getUrlString(), compute_node_title, software_installation.getCreationDate())
elif d.get("text").startswith("#access"):
# Nothing to do.
pass
elif d.get("text").startswith("#error"):
should_notify = True
ticket_title = "[MONITORING] %s is failing to build on %s" % (reference, compute_node_reference)
description = "The software release %s is failing to build for too long on %s, started on %s" % \
(software_installation.getUrlString(), compute_node_title, software_installation.getCreationDate())
if should_notify: if should_notify:
project = context.getFollowUpValue() project = context.getFollowUpValue()
support_request = project.Project_createSupportRequestWithCausality( support_request = project.Project_createSupportRequestWithCausality(
ticket_title, ticket_title,
...@@ -79,8 +47,9 @@ for software_installation in software_installation_list: ...@@ -79,8 +47,9 @@ for software_installation in software_installation_list:
#language=XXX, #language=XXX,
substitution_method_parameter_dict={ substitution_method_parameter_dict={
'compute_node_title':context.getTitle(), 'compute_node_title':context.getTitle(),
'compute_node_id':reference, # Maybe a mistake on compute_node_id
'last_contact':last_contact 'compute_node_id': software_installation.getReference(),
'last_contact': last_contact
} }
) )
......
from DateTime import DateTime from DateTime import DateTime
d = context.getAccessStatus() if tolerance is None:
# Ignore if data isn't present. tolerance = DateTime() - 0.5
software_installation = context
reference = software_installation.getReference()
d = software_installation.getAccessStatus()
def return_ok(batch_mode):
if batch_mode:
return None
return None, None, None, None
if software_installation.getCreationDate() > tolerance:
return return_ok(batch_mode)
if software_installation.getSlapState() != 'start_requested':
return return_ok(batch_mode)
if d.get("no_data", None) == 1: if d.get("no_data", None) == 1:
return return return_ok(batch_mode)
if d.get("text").startswith("#access"):
return return_ok(batch_mode)
last_contact = DateTime(d.get('created_at'))
if d.get("text").startswith("#building"):
if batch_mode:
# is it a problem...?
return last_contact
should_notify = True
ticket_title = "[MONITORING] %s is building for too long on %s" % (reference, software_installation.getAggregateReference())
description = "The software release %s is building for mode them 12 hours on %s, started on %s" % \
(software_installation.getUrlString(), software_installation.getAggregateTitle(), software_installation.getCreationDate())
return should_notify, ticket_title, description, last_contact
if d.get("text").startswith("#error"):
if batch_mode:
return DateTime(d.get('created_at'))
if d['text'].startswith('#error '): should_notify = True
return DateTime(d.get('created_at')) ticket_title = "[MONITORING] %s is failing to build on %s" % (reference, software_installation.getAggregateReference())
description = "The software release %s is failing to build for too long on %s, started on %s" % \
(software_installation.getUrlString(), software_installation.getAggregateTitle(), software_installation.getCreationDate())
return should_notify, ticket_title, description, last_contact
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>tolerance=None, batch_mode=False</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
Markdown is supported
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