Commit e527f54c authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Rafael Monnerat

Improve "Unavailable Computer" Support Request

parent 91d68b8c
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
</item> </item>
<item> <item>
<key> <string>periodicity_hour_frequency</string> </key> <key> <string>periodicity_hour_frequency</string> </key>
<value> <int>1</int> </value> <value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>periodicity_minute</string> </key> <key> <string>periodicity_minute</string> </key>
...@@ -42,9 +44,7 @@ ...@@ -42,9 +44,7 @@
</item> </item>
<item> <item>
<key> <string>periodicity_minute_frequency</string> </key> <key> <string>periodicity_minute_frequency</string> </key>
<value> <value> <int>30</int> </value>
<none/>
</value>
</item> </item>
<item> <item>
<key> <string>periodicity_month</string> </key> <key> <string>periodicity_month</string> </key>
......
...@@ -80,7 +80,7 @@ if not is_service_provider:\n ...@@ -80,7 +80,7 @@ if not is_service_provider:\n
\n \n
# Create a ticket (or re-open it) for this issue!\n # Create a ticket (or re-open it) for this issue!\n
support_request = None\n support_request = None\n
request_title = \'Allocation scope has been changed for %s\' % computer_reference\n request_title = \'[MONITORING] Allocation scope has been changed for %s\' % computer_reference\n
request_description = \'Allocation scope has been changed back to \' \\\n request_description = \'Allocation scope has been changed back to \' \\\n
\'open/personal for %s\' % computer_reference\n \'open/personal for %s\' % computer_reference\n
message_title = \'We have changed allocation scope for %s\' % computer_reference\n message_title = \'We have changed allocation scope for %s\' % computer_reference\n
......
...@@ -62,29 +62,72 @@ if portal.ERP5Site_isSupportRequestCreationClosed():\n ...@@ -62,29 +62,72 @@ if portal.ERP5Site_isSupportRequestCreationClosed():\n
return\n return\n
\n \n
reference = context.getReference()\n reference = context.getReference()\n
computer_title = context.getTitle()\n
ticket_title = "[MONITORING] Lost contact with computer %s" % reference\n
description = ""\n
should_notify = True\n
last_contact = "No Contact Information"\n
\n
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n plugin_path=\'portal_memcached/default_memcached_plugin\')\n
\n \n
try:\n try:\n
d = memcached_dict[reference]\n d = memcached_dict[reference]\n
d = json.loads(d)\n
last_contact = DateTime(d.get(\'created_at\'))\n
if (DateTime() - last_contact) > 1:\n
description = "The Computer %s (%s) has not contacted the server for more than 24 hours" \\\n
"(last contact date: %s)" % (computer_title, reference, last_contact)\n
else:\n
should_notify = False\n
except KeyError:\n except KeyError:\n
return context.Base_generateSupportRequestForSlapOS(\n ticket_title = "[MONITORING] No information about %s" % reference\n
"No information about %s" % reference,\n description = "The Computer %s (%s) has not contacted the server (No Contact Information)" % (\n
"%s has not contacted the server (No Contact Information)" % reference,\n computer_title, reference)\n
context.getRelativeUrl()\n
)\n
\n \n
\n \n
d = json.loads(d)\n if should_notify:\n
last_contact = DateTime(d.get(\'created_at\'))\n support_request_url = context.Base_generateSupportRequestForSlapOS(\n
\n ticket_title,\n
if (DateTime() - last_contact) > 1:\n description,\n
return context.Base_generateSupportRequestForSlapOS(\n
"Lost contact with %s" % reference,\n
"%s has not contacted the server for more than 24 hours (last contact date: %s)" % (reference, last_contact),\n
context.getRelativeUrl()\n context.getRelativeUrl()\n
)\n )\n
\n
support_request = None\n
person = context.getSourceAdministrationValue(portal_type="Person")\n
if not person:\n
return support_request_url\n
\n
if support_request_url:\n
support_request = portal.restrictedTraverse(support_request_url, None)\n
else:\n
# XXX - the support request might already exists\n
support_request = portal.portal_catalog.getResultValue(\n
portal_type = \'Support Request\',\n
title = ticket_title,\n
simulation_state = \'validated\',\n
source_project_uid = context.getUid()\n
)\n
if support_request is None:\n
# Existing ticket not found, can not create event for the moment\n
return support_request_url\n
\n
# Send Notification message\n
notification_reference = \'slapos-crm-computer_check_state.notification\'\n
notification_message = portal.portal_notifications.getDocumentValue(\n
reference=notification_reference)\n
mapping_dict = {\'computer_title\':context.getTitle(),\n
\'computer_id\':reference,\n
\'last_contact\':last_contact}\n
message = notification_message.asText(\n
substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
\n
support_request.SupportRequest_trySendNotificationMessage(\n
ticket_title.replace(\'[MONITORING] \', \'\'),\n
message, person.getRelativeUrl(), 5)\n
\n
return support_request_url\n
]]></string> </value> ]]></string> </value>
......
...@@ -62,7 +62,7 @@ last_event = context.portal_catalog.getResultValue(\n ...@@ -62,7 +62,7 @@ last_event = context.portal_catalog.getResultValue(\n
sort_on=[(\'delivery.start_date\', \'DESC\')],\n sort_on=[(\'delivery.start_date\', \'DESC\')],\n
)\n )\n
if last_event and \\\n if last_event and \\\n
(DateTime() - last_event.getStartDate() < 1):\n (DateTime() - last_event.getStartDate() < interval_of_day):\n
# User has already been notified this last 24h.\n # User has already been notified this last 24h.\n
return\n return\n
event = portal.event_module.slapos_crm_web_message_template.\\\n event = portal.event_module.slapos_crm_web_message_template.\\\n
...@@ -77,13 +77,15 @@ event.edit(\n ...@@ -77,13 +77,15 @@ event.edit(\n
)\n )\n
event.stop()\n event.stop()\n
event.deliver()\n event.deliver()\n
\n
return event\n
]]></string> </value> ]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>message_title, message, source_relative_url</string> </value> <value> <string>message_title, message, source_relative_url, interval_of_day=1</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -326,6 +326,47 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin): ...@@ -326,6 +326,47 @@ class TestSlapOSCloudSupportRequestGeneration(testSlapOSMixin):
self.assertEqual('Visited Base_generateSupportRequestForSlapOS', self.assertEqual('Visited Base_generateSupportRequestForSlapOS',
result) result)
def test_SupportRequest_trySendNotificationMessage(self):
title = "Test Support Request %s" % self.new_id
text_content='Test NM content<br/>%s<br/>' % self.new_id
computer = self._makeComputer(self.new_id)
support_request_url = computer.Base_generateSupportRequestForSlapOS(
title, title, computer.getRelativeUrl()
)
support_request = self.portal.restrictedTraverse(support_request_url)
person = computer.getSourceAdministrationValue()
time_before_next = 2
self.tic()
first_event = support_request.SupportRequest_trySendNotificationMessage(
message_title=title, message=text_content,
source_relative_url=person.getRelativeUrl(),
interval_of_day=time_before_next
)
self.assertNotEqual(first_event, None)
first_event.edit(start_date=(DateTime() - 1.8))
self.tic()
event = support_request.SupportRequest_trySendNotificationMessage(
message_title=title, message=text_content,
source_relative_url=person.getRelativeUrl(),
interval_of_day=time_before_next
)
self.assertEqual(event, None)
time_before_next = 1
event = support_request.SupportRequest_trySendNotificationMessage(
message_title=title, message=text_content,
source_relative_url=person.getRelativeUrl(),
interval_of_day=time_before_next
)
self.assertEqual(event.getTitle(), title)
def test_Computer_checkState_empty_cache(self): def test_Computer_checkState_empty_cache(self):
computer = self._makeComputer(self.new_id) computer = self._makeComputer(self.new_id)
......
42 43
\ No newline at end of file \ No newline at end of file
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