<%! from splunk.appserver.mrsparkle.lib import times %> <% # # generate a JSON literal of all of the time ranges that have been specified # in time.conf # timeRanges = times.getTimeRanges(namespace=APP['id']) menuItems = [] ''' Although times.conf has a submenu hierarchy, the values come out as a flat list. The hierarchy is then built here. In that list among the regular top-level items, there will be a) stubs for the submenus themselves, within the regular items, marked with is_sub_menu = True and label=foo. b) the children of those submenus , marked with sub_menu = foo. We will not append those children into the main menuItems array, but rather keep them in a dict by sub_menu name. Then in a second pass we will attach the children appropriately. ''' subMenuContents = {} for t in timeRanges: if 'is_sub_menu' in t: item = { "is_sub_menu" : True, "label" : _(t['label']), "rawLabel" : t['label'], "order": t['order'] } menuItems.append(item) continue item = { "label" : _(t['label']), "rawLabel": t['label'], "attrs" : {}, "style": "timeRangePreset", "order": t['order'] } # if defined, add in earliest/latest identifiers # the resurrection logic depends on the absence/presence of start and end keys # TODO: convert start/end to earliest/latest for k in ('earliest_time', 'latest_time'): if t[k]: item['attrs'][k] = t[k] subMenuName = t.get('sub_menu', False) if (subMenuName) : #subMenuName = _(subMenuName) if (subMenuName not in subMenuContents) : subMenuContents[subMenuName] = [] subMenuContents[subMenuName].append(item) else : menuItems.append(item) ''' Now we go through and attach the children for each of the sub_menus, which we've been keeping off to the side in the subMenuContents dict until now. ''' for i in range(len(menuItems)): if "is_sub_menu" in menuItems[i]: subMenuLabel = menuItems[i]["rawLabel"] # If this isnt true it'll have been caught by the runtime check in times.py # we check here only to prevent the exception. if subMenuLabel in subMenuContents: menuItems[i]["items"] = subMenuContents[subMenuLabel] # This was just a marker for us to do this rearranging. # Now that we're done we delete the marker. del menuItems[i]["is_sub_menu"] jsonOutput = jsonify(menuItems) %> <%page args="module"/> <%namespace name="lib" file="//lib.html" import="*"/> <%call expr="lib.add_script_block()"> Splunk.Module.loadParams.${module['id']}.timeRangeJson = ${jsonOutput}; % if module.get('label'): % endif

${_('Select Date Range')}

${_('Start:')}
${_('End:')}