Commit b023d728 authored by Tristan Cavelier's avatar Tristan Cavelier

Alarm check skin cache added to erp5_administration

This alarm will check if a cache is assigned to some files in portal_skins.
If a file has no cache manager, it triggers a Problem.
When solving the alarm, `http_cache` will be assigned to uncached files.
parent 00b10b5a
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_checkSkinCache</string> </value>
</item>
<item>
<key> <string>alarm_notification_mode</string> </key>
<value>
<tuple>
<string>problem</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>check_skin_cache</string> </value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1230768000.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>sense_method_id</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>check_skin_cache</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>ap = context.newActiveProcess()\n
\n
context.activate(\n
active_process=ap.getRelativeUrl(),\n
tag=tag,\n
).Alarm_checkSkinCacheActive(fixit=fixit)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_checkSkinCache</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\\\n
Browse portal skins to seek for non cached files.\n
\n
This Alarm returns one ActiveResult severity 100 if the file listed in this\n
script from portal_skins are not affected to a cache manager. If all files are\n
correct, it returns one ActiveResult severity 0.\n
\n
If the `fixit` parameter is considered as true, the incorrect parsed files will\n
be affected to the chosen cache manager.\n
"""\n
\n
# Cache manager to use\n
# examples: "http_cache" "anonymous_http_cache" "user_ram_cache"\n
cache_manager_id = "http_cache"\n
\n
# check all files in..\n
meta_type_checklist = "Image", "File", "Filesystem Image", "Filesystem File"\n
\n
# check all files which name endswith..\n
file_extension_checklist = ".css", ".js"\n
\n
################################################################################\n
from Products.CMFActivity.ActiveResult import ActiveResult\n
\n
incorrect_file_absolute_url_list = []\n
\n
def some(iterable, function):\n
for v in iterable:\n
if function(v): return True\n
return False\n
\n
# Browse files and folders recursively\n
def execute(skin):\n
for o in skin.objectValues():\n
# browsing files\n
oid = o.id\n
# force oid to be a string\n
if callable(oid): oid = oid()\n
if o.meta_type in meta_type_checklist or \\\n
some(file_extension_checklist, oid.endswith):\n
# this file matches the cheklists requirements\n
current_cache_manager_id = o.ZCacheable_getManagerId()\n
if current_cache_manager_id is None:\n
# the current file is not cached\n
if fixit: o.ZCacheable_setManagerId(cache_manager_id)\n
else: incorrect_file_absolute_url_list.append(o.absolute_url(relative=1))\n
elif o.meta_type == \'Folder\':\n
execute(o)\n
\n
for skin in context.portal_skins.objectValues():\n
try: execute(skin)\n
except Exception as e: incorrect_file_absolute_url_list.append(str(e))\n
\n
\n
if incorrect_file_absolute_url_list != []:\n
return ActiveResult(severity=100, detail="There is no cache set for:\\n" + "\\n".join(incorrect_file_absolute_url_list))\n
\n
return ActiveResult(severity=0, detail="OK")\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>fixit=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_checkSkinCacheActive</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
161
\ No newline at end of file
164
\ No newline at end of file
......@@ -4,4 +4,5 @@ portal_alarms/check_conversion_tool_availability
portal_alarms/check_folder_handler
portal_alarms/check_item_tracking
portal_alarms/check_localizer
portal_alarms/check_skin_cache
portal_alarms/check_stock
\ 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