You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.3 KiB
124 lines
4.3 KiB
# Copyright (C) 2005-2024 Splunk Inc. All Rights Reserved.
|
|
|
|
from .utils import get_nested
|
|
from itsi_py3 import _
|
|
|
|
GLOBAL_TRP_TOKEN_NAME = 'global_time'
|
|
GLOBAL_REFRESH_TOKEN_NAME = 'global_refresh_rate'
|
|
|
|
|
|
class UDFDefinitionBuilder(object):
|
|
"""
|
|
Helper object for managing different UDF json sections
|
|
"""
|
|
def __init__(self):
|
|
self.definition = {
|
|
'title': '',
|
|
'description': '',
|
|
'defaults': {
|
|
'dataSources': {
|
|
'global': {
|
|
'options': {
|
|
'queryParameters': {
|
|
'earliest': '$%s.earliest$' % GLOBAL_TRP_TOKEN_NAME,
|
|
'latest': '$%s.latest$' % GLOBAL_TRP_TOKEN_NAME
|
|
},
|
|
'refreshType': 'delay',
|
|
'refresh': '$%s$' % GLOBAL_REFRESH_TOKEN_NAME
|
|
}
|
|
}
|
|
}
|
|
},
|
|
'layout': {
|
|
'type': 'absolute',
|
|
'structure': [],
|
|
'globalInputs': [
|
|
'input_global_trp',
|
|
'input_global_refresh_rate'
|
|
],
|
|
'options': {
|
|
'showTitleAndDescription': True
|
|
}
|
|
},
|
|
'inputs': {
|
|
'input_global_trp': {
|
|
'options': {
|
|
'defaultValue': '-60m@m, now',
|
|
'token': GLOBAL_TRP_TOKEN_NAME
|
|
},
|
|
'type': 'input.timerange',
|
|
'title': _('Global Time Range')
|
|
},
|
|
'input_global_refresh_rate': {
|
|
'options': {
|
|
'items': [
|
|
{
|
|
'label': _('1 Minute'),
|
|
'value': '60s'
|
|
},
|
|
{
|
|
'label': _('5 Minutes'),
|
|
'value': '300s'
|
|
},
|
|
{
|
|
'label': _('30 Minutes'),
|
|
'value': '1800s'
|
|
},
|
|
{
|
|
'label': _('1 Hour'),
|
|
'value': '3600s'
|
|
},
|
|
{
|
|
'label': _('24 Hours'),
|
|
'value': '86400s'
|
|
}
|
|
],
|
|
'defaultValue': '60s',
|
|
'token': GLOBAL_REFRESH_TOKEN_NAME
|
|
},
|
|
'title': _('Global Refresh Rate'),
|
|
'type': 'input.dropdown'
|
|
}
|
|
},
|
|
'visualizations': {},
|
|
'dataSources': {}
|
|
}
|
|
|
|
def update_meta(self, title, description):
|
|
if title:
|
|
self.definition['title'] = title
|
|
if description:
|
|
self.definition['description'] = description
|
|
|
|
def update_layout_options(self, layout_options):
|
|
curr_options = get_nested(self.definition, ['layout', 'options'])
|
|
if curr_options:
|
|
curr_options.update(layout_options)
|
|
else:
|
|
curr_options = layout_options
|
|
self.definition['layout']['options'] = curr_options
|
|
|
|
def add_layout_item(self, layout_item):
|
|
curr_layout = get_nested(self.definition, ['layout', 'structure'])
|
|
if layout_item.get('item') in [obj.get('item') for obj in curr_layout]:
|
|
# prevent duplicates
|
|
return
|
|
curr_layout.append(layout_item)
|
|
|
|
def add_visualization(self, viz):
|
|
visualizations = get_nested(self.definition, ['visualizations'])
|
|
visualizations.update(viz)
|
|
|
|
def update_visualization(self, id, viz):
|
|
visualizations = get_nested(self.definition, ['visualizations'])
|
|
viz_id = id if id.startswith('viz_') else 'viz_%s' % id
|
|
del visualizations[viz_id]
|
|
visualizations.update(viz)
|
|
|
|
def add_data_source(self, data_source):
|
|
data_sources = get_nested(self.definition, ['dataSources'])
|
|
data_sources.update(data_source)
|
|
|
|
def get_definition(self):
|
|
return self.definition
|