def post_process_table(self, field_options): fields_add_device_selection(self, keyword='netprofiler_device', label='NetProfiler', module='netprofiler', enabled=True) fields_add_time_selection(self, show_end=True, show_duration=False) func = Function(netprofiler_live_templates, self.options) TableField.create('template_id', label='Template', obj=self, field_cls=IDChoiceField, parent_keywords=['netprofiler_device'], dynamic=True, pre_process_func=func) self.add_column('template_id', 'Template ID', datatype='string', iskey=True) self.add_column('widget_id', 'Widget ID', datatype='integer', iskey=True) self.add_column('title', 'Title', datatype='string') self.add_column('widget_type', 'Type', datatype='string') self.add_column('visualization', 'Visualization', datatype='string') self.add_column('datasource', 'Data Source', datatype='string')
def post_process_table(self, field_options): super(NetProfilerTrafficTimeSeriesTable, self).post_process_table( field_options) if self.options.top_n is None: # If not top-n, the criteria field 'query_columns' must # either be a string or an array of column definitions # (a string is simply parsed as json to the latter). # # This criteria field must resolve to an array of # field definitions, one per column to be queried # # An array of column defintions looks like the following: # [ {'name': <name>, 'label': <name>, 'json': <json>}, # {'name': <name>, 'label': <name>, 'json': <json>}, # ... ] # # Each element corresponds to a column requested. <name> is # used as the Column.name, <label> is for the Column.label # and json is what is passed on to NetProfiler in the POST # to create the report # TableField.create(keyword='query_columns', label='Query columns', obj=self)
def fields_add_command(obj): field = TableField(keyword='command', label='Command', field_cls=forms.CharField) field.save() obj.fields.add(field)
def fields_add_device_tag(obj, keyword='tag', label='Tag'): field = TableField(keyword=keyword, label=label, field_cls=forms.ChoiceField, pre_process_func=Function(tag_selection_preprocess, {})) field.save() obj.fields.add(field)
def fields_add_filemgr_selection(obj, keyword='filemgrfile', label='FileMgrFile'): field = TableField(keyword=keyword, label=label, field_cls=IntegerIDChoiceField, pre_process_func=Function(file_selection_preprocess)) field.save() obj.fields.add(field)
def add_netprofiler_application_field(report, section, app=None): """ Attach fields for dynamic Application dropdowns to add as filter expressions to the report. This can be added for each section in a report where the added filter expression is desired. The optional ``app`` argument can be either a single string or a list of strings for each HostGroupType. If a single string, the 'Application' field will be hidden and automatically filter Applications to the given App. If a list, the elements of the App list will be fixed to those in the list. """ # add default filter expr to extend against filterexpr = TableField.create(keyword='netprofiler_filterexpr') section.fields.add(filterexpr) if app is None: # use all available apps field = TableField.create( keyword='application', label='Application', obj=report, field_cls=forms.ChoiceField, field_kwargs={'widget_attrs': {'class': 'form-control'}}, parent_keywords=['netprofiler_device'], dynamic=True, pre_process_func=Function(netprofiler_application_choices) ) section.fields.add(field) elif type(app) in (list, tuple): # add apps field that uses given list field = TableField.create( keyword='application', label='Application', obj=report, field_cls=forms.ChoiceField, field_kwargs={'choices': zip(app, app), 'widget_attrs': {'class': 'form-control'}}, parent_keywords=['netprofiler_device'], ) section.fields.add(field) else: # no app, so no field just hardcode the filter NetProfilerTable.extend_filterexpr( section, keyword='application', template='app {}'.format(app) ) # we're done here return NetProfilerTable.extend_filterexpr( section, keyword='hg_filterexpr', template='app {application}' )
def fields_add_sample(self, keyword='resample_interval', initial='60s'): field = TableField(keyword=keyword, label='Resample Seconds', help_text='Number of seconds to sample data over.', initial=initial, required=False) field.save() self.fields.add(field)
def fields_add_filterexpr(table, keyword='netshark_filterexpr', initial=None): field = TableField(keyword=keyword, label='NetShark Filter Expression', help_text='Traffic expression using ' 'NetShark filter syntax', initial=initial, required=False) field.save() table.fields.add(field)
def fields_add_stock_symbol(self, help_text, keyword='stock_symbol', initial=None): field = TableField(keyword=keyword, label='Stock Symbol', help_text=(help_text), initial=initial, required=True) field.save() self.fields.add(field)
def fields_add_filterexpr(self, keyword='netshark_filterexpr', initial=None): field = TableField(keyword=keyword, label='NetShark Filter Expression', help_text='Traffic expression using ' 'NetShark filter syntax', initial=initial, required=False) field.save() self.fields.add(field)
def fields_add_filterexpr(self, keyword='netprofiler_filterexpr', initial=None): field = TableField(keyword=keyword, label='NetProfiler Filter Expression', help_text=('Traffic expression using NetProfiler ' 'Advanced Traffic Expression syntax'), initial=initial, required=False) field.save() self.fields.add(field)
def fields_add_device_selection(obj, keyword='device', label='Device', module=None, enabled=None): field = TableField(keyword=keyword, label=label, field_cls=IntegerIDChoiceField, pre_process_func=Function(device_selection_preprocess, {'module': module, 'enabled': enabled})) field.save() obj.fields.add(field)
def post_process_table(self, field_options): super(SCCThroughputTable, self).post_process_table(field_options) # Add device ID field field = TableField(keyword='device', label='Device Serial ID', required=True) field.save() self.fields.add(field) # Add port field field = TableField(keyword='port', label='Port', required=False) field.save() self.fields.add(field) # Add traffic_type field traffic_types = ('peak', 'p95') field = TableField(keyword='traffic_type', label='Traffic Type', field_cls=forms.ChoiceField, field_kwargs={'choices': zip(traffic_types, traffic_types)}) field.save() self.fields.add(field)
def fields_add_entire_pcap(table): TableField.create(keyword='entire_pcap', obj=table, field_cls=forms.BooleanField, label='Entire File', help_text='Ignore start/end times ' 'and run the report over the ' 'whole timeframe of the selected ' 'file.', initial=True, required=False)
def fields_add_filterexpr(table, keyword='appresponse_steelfilter', initial=None): field = TableField(keyword=keyword, label='SteelFilter Expression', help_text='Traffic expression using ' 'SteelFilter syntax, e.g. ' 'ip.addr == "10.0.0.1" or ' 'avg_traffic.total_ bytes_ps <= 10000', initial=initial, required=False) field.save() table.fields.add(field)
def fields_add_source_choices(table, func, keyword='appresponse_source', label='Source', initial=None): TableField.create( keyword=keyword, label=label, obj=table, field_cls=IDChoiceField, field_kwargs={'widget_attrs': {'class': 'form-control'}}, parent_keywords=['appresponse_device'], initial=initial, dynamic=True, pre_process_func=func )
def post_process_table(self, field_options): super(AppResponseTimeSeriesTable, self).\ post_process_table(field_options) TableField.create(keyword='pivot_column_names', required=not self.options.hide_pivot_field, hidden=self.options.hide_pivot_field, label=self.options.pivot_column_label, obj=self, help_text='Name of Interested Columns ' '(separated by ",")') self.add_column('time', 'time', datatype='time', iskey=True)
def fields_add_time_selection(obj, show_duration=True, initial_duration=None, durations=None, show_start=False, initial_start_time='now-1h', initial_start_date='now-1h', show_end=True, initial_end_time='now-0', initial_end_date='now-0', round_initial=0, # seconds to round initial time special_values=None): if show_start: field = TableField(keyword='starttime', label='Start Time', field_cls=DateTimeField, field_kwargs={ 'widget': ReportSplitDateTimeWidget, 'widget_attrs': { 'initial_time': initial_start_time, 'initial_date': initial_start_date, 'round_initial': round_initial } }, required=False) field.save() obj.fields.add(field) if show_end: field = TableField(keyword='endtime', label='End Time', field_cls=DateTimeField, field_kwargs={ 'widget': ReportSplitDateTimeWidget, 'widget_attrs': { 'initial_time': initial_end_time, 'initial_date': initial_end_date, 'round_initial': round_initial } }, required=False) field.save() obj.fields.add(field) if show_duration: if durations is None: durations = DURATIONS field = TableField(keyword='duration', label='Duration', initial=initial_duration, field_cls=DurationField, field_kwargs={'choices': durations, 'special_values': special_values}, required=False) field.save() obj.fields.add(field)
def fields_add_end_date(self, initial_end_date='now-0'): # Add a date field # the front javascript code will determine the default date # according to initial_end_date, so if initial_end_date is # 'now-0', today will be the default end date field = TableField(keyword='end_date', label='End Date', field_cls=DateTimeField, field_kwargs={'widget': ReportSplitDateWidget, 'widget_attrs': {'initial_date': initial_end_date}}, required=False) field.save() self.fields.add(field)
def post_process_table(self, field_options): super(BandwidthTable, self).post_process_table(field_options) durations = [('1min', '1 minute'), ('5min', '5 minutes'), ('hour', '1 hour'), ('day', '1 day'), ('week', '1 week'), ('month', '1 month')] field = TableField(keyword='duration', label='Bandwidth Stats Duration', field_cls=forms.ChoiceField, field_kwargs={'choices': durations}, initial='5min') field.save() self.fields.add(field)
def post_process_table(self, field_options): fields_add_device_selection(self, keyword='netshark_device_src', label='NetShark Source', module='netshark', enabled=True) fields_add_device_selection(self, keyword='netshark_device_dst', label='NetShark Dest', module='netshark', enabled=True) fields_add_device_selection(self, keyword='netshark_device_upload', label='NetShark MSA', module='netshark', enabled=True) TableField.create( keyword='netshark_source_name_src', label='Source Capture Job', obj=self, field_cls=forms.ChoiceField, field_kwargs={'widget_attrs': { 'class': 'form-control' }}, parent_keywords=['netshark_device_src'], dynamic=True, pre_process_func=Function(netshark_source_choices, {'field': 'netshark_device_src'})) TableField.create( keyword='netshark_source_name_dst', label='Dest Capture Job', obj=self, field_cls=forms.ChoiceField, field_kwargs={'widget_attrs': { 'class': 'form-control' }}, parent_keywords=['netshark_device_dst'], dynamic=True, pre_process_func=Function(netshark_source_choices, {'field': 'netshark_device_dst'})) fields_add_time_selection(self, show_start=True, initial_start_time='now-1m', show_end=True, show_duration=False) fields_add_filterexpr(obj=self)
def extend_filterexpr(cls, obj, keyword, template): field = obj.fields.get(keyword='netprofiler_filterexpr') field.post_process_func = Function( function=_post_process_combine_filterexprs ) TableField.create( keyword=keyword, obj=obj, hidden=True, post_process_template=template) parent_keywords = set(field.parent_keywords or []) parent_keywords.add(keyword) field.parent_keywords = list(parent_keywords) field.save()
def fields_add_granularity(obj, initial=None, source=None): if source == 'packets': granularities = ('0.001', '0.01', '0.1', '1', '10', '60', '600', '3600', '86400') else: granularities = ('60', '600', '3600', '86400') field = TableField(keyword='granularity', label='Granularity', field_cls=DurationField, field_kwargs={'choices': granularities}, initial=initial) field.save() obj.fields.add(field)
def fields_add_resolution(obj, initial=None, resolutions=None, special_values=None): if resolutions is None: resolutions = ('1m', '15m', '1h', '6h') field = TableField(keyword='resolution', label='Data Resolution', field_cls=DurationField, field_kwargs={'choices': resolutions, 'special_values': special_values}, initial=initial) field.save() obj.fields.add(field)
def fields_add_resolution(obj, initial=None, resolutions=None, special_values=None): if resolutions is None: resolutions = ('1m', '15m', '1h', '6h') field = TableField(keyword='resolution', label='Data Resolution', field_cls=DurationField, field_kwargs={ 'choices': resolutions, 'special_values': special_values }, initial=initial) field.save() obj.fields.add(field)
def __init__(self, *args, **kwargs): fields = {} res = TableField.objects.filter(keyword='batch_file') if not res: file_upload = TableField(keyword='batch_file', label='Batch File', field_cls=FileSelectField, field_kwargs=dict(widget=FileInput), required=True) file_upload.save() else: file_upload = res[0] fields['batch_file'] = file_upload super(DeviceBatchForm, self).__init__(fields, *args, **kwargs)
def post_process_table(self, field_options): # # Add criteria fields that are required by this table # TableField.create(keyword='entire_pcap', obj=self, field_cls=forms.BooleanField, label='Entire PCAP', initial=True, required=False) fields_add_time_selection(self, show_start=True, show_end=True, show_duration=False) fields_add_resolution(obj=self, initial=field_options['resolution'], resolutions=field_options['resolutions']) fields_add_pcapfile( obj=self, astextfield=field_options['pcapfile_astextfield']) fields_add_filterexpr(obj=self)
def post_process_table(self, field_options): duration = field_options['duration'] if isinstance(duration, int): duration = "{}m".format(duration) fields_add_device_selection(self, keyword='netshark_device', label='NetShark', module='netshark', enabled=True) func = Function(netshark_msa_file_choices, self.options) TableField.create( keyword='netshark_source_name', label='Source', obj=self, field_cls=IDChoiceField, field_kwargs={'widget_attrs': { 'class': 'form-control' }}, parent_keywords=['netshark_device'], dynamic=True, pre_process_func=func) fields_add_time_selection(self, initial_duration=duration, durations=field_options['durations']) fields_add_resolution(self, initial=field_options['resolution'], resolutions=field_options['resolutions']) if self.options.include_filter: fields_add_filterexpr(self) if self.options.include_bpf_filter: fields_add_bpf_filterexpr(self) if self.options.show_entire_msa: TableField.create(keyword='entire_msa', obj=self, field_cls=forms.BooleanField, label='Entire MSA (ignore start/end times)', initial=True, required=False)
def fields_add_filterexpr(obj, keyword='wireshark_filterexpr', initial=None): field = (TableField( keyword=keyword, label='WireShark Filter Expression', help_text=('Traffic expression using WireShark Display ' 'Filter syntax'), initial=initial, required=False)) field.save() obj.fields.add(field)
def post_process_table(self, field_options): duration = field_options['duration'] if isinstance(duration, int): duration = "%dm" % duration fields_add_device_selection(self, keyword='netshark_device', label='NetShark', module='netshark', enabled=True) func = Function(netshark_source_name_choices, self.options) TableField.create( keyword='netshark_source_name', label='Source', obj=self, field_cls=IDChoiceField, field_kwargs={'widget_attrs': { 'class': 'form-control' }}, parent_keywords=['netshark_device'], dynamic=True, pre_process_func=func) if self.options.include_persistent: TableField.create(keyword='netshark_persistent', label='Persistent View', obj=self, field_cls=forms.BooleanField, initial=False) fields_add_time_selection(self, initial_duration=duration, durations=field_options['durations']) fields_add_resolution(self, initial=field_options['resolution'], resolutions=field_options['resolutions']) if self.options.include_filter: fields_add_filterexpr(self) if self.options.include_bpf_filter: fields_add_bpf_filterexpr(self)
def post_process_table(self, field_options): fields_add_device_selection(self, keyword='netshark_device', label='NetShark', module='netshark', enabled=True) fields_add_time_selection(self, show_start=True, initial_start_time='now-1m', show_end=True, show_duration=False) fields_add_resolution(self, initial=field_options['resolution'], resolutions=field_options['resolutions']) func = Function(netshark_source_name_choices, self.options) TableField.create(keyword='netshark_source_name', label='Source', obj=self, field_cls=forms.ChoiceField, parent_keywords=['netshark_device'], dynamic=True, pre_process_func=func) fields_add_filterexpr(obj=self) self.add_column('filename', datatype='string')
def fields_add_pcapfile(obj, keyword='pcapfilename', label='PCAP File', initial=None, astextfield=False): """Add a PCAP file selection field. :param bool astextfield: If True, use a text field instead of a file selection field. The text value is interpreted as a file on the server. """ kwargs = {} if not astextfield: kwargs['field_cls'] = FileSelectField kwargs['field_kwargs'] = {'widget': FileInput} field = TableField(keyword=keyword, label=label, **kwargs) field.save() obj.fields.add(field)
def post_process_table(self, field_options): duration = field_options['duration'] if isinstance(duration, int): duration = "{}m".format(duration) fields_add_device_selection(self, keyword='netshark_device', label='NetShark', module='netshark', enabled=True) func = Function(netshark_msa_file_choices, self.options) TableField.create(keyword='netshark_source_name', label='Source', obj=self, field_cls=IDChoiceField, field_kwargs={ 'widget_attrs': {'class': 'form-control'} }, parent_keywords=['netshark_device'], dynamic=True, pre_process_func=func) fields_add_time_selection(self, initial_duration=duration, durations=field_options['durations']) fields_add_resolution(self, initial=field_options['resolution'], resolutions=field_options['resolutions']) if self.options.include_filter: fields_add_filterexpr(self) if self.options.include_bpf_filter: fields_add_bpf_filterexpr(self) if self.options.show_entire_msa: TableField.create(keyword='entire_msa', obj=self, field_cls=forms.BooleanField, label='Entire MSA (ignore start/end times)', initial=True, required=False)
def post_process_table(self, field_options): fields_add_device_selection(self, keyword='netshark_device_src', label='NetShark Source', module='netshark', enabled=True) fields_add_device_selection(self, keyword='netshark_device_dst', label='NetShark Dest', module='netshark', enabled=True) fields_add_device_selection(self, keyword='netshark_device_upload', label='NetShark MSA', module='netshark', enabled=True) TableField.create( keyword='netshark_source_name_src', label='Source Capture Job', obj=self, field_cls=forms.ChoiceField, field_kwargs={'widget_attrs': {'class': 'form-control'}}, parent_keywords=['netshark_device_src'], dynamic=True, pre_process_func=Function(netshark_source_choices, {'field': 'netshark_device_src'}) ) TableField.create( keyword='netshark_source_name_dst', label='Dest Capture Job', obj=self, field_cls=forms.ChoiceField, field_kwargs={'widget_attrs': {'class': 'form-control'}}, parent_keywords=['netshark_device_dst'], dynamic=True, pre_process_func=Function(netshark_source_choices, {'field': 'netshark_device_dst'}) ) fields_add_time_selection(self, show_start=True, initial_start_time='now-1m', show_end=True, show_duration=False) fields_add_filterexpr(obj=self)
def post_process_table(self, field_options): duration = field_options['duration'] if isinstance(duration, int): duration = "%dm" % duration fields_add_device_selection(self, keyword='netshark_device', label='NetShark', module='netshark', enabled=True) func = Function(netshark_source_name_choices, self.options) TableField.create( keyword='netshark_source_name', label='Source', obj=self, field_cls=IDChoiceField, field_kwargs={'widget_attrs': {'class': 'form-control'}}, parent_keywords=['netshark_device'], dynamic=True, pre_process_func=func ) if self.options.include_persistent: TableField.create(keyword='netshark_persistent', label='Persistent View', obj=self, field_cls=forms.BooleanField, initial=False) fields_add_time_selection(self, initial_duration=duration, durations=field_options['durations']) fields_add_resolution(self, initial=field_options['resolution'], resolutions=field_options['resolutions']) if self.options.include_filter: fields_add_filterexpr(self) if self.options.include_bpf_filter: fields_add_bpf_filterexpr(self)
def post_process_table(self, field_options): # Add a time selection field fields_add_device_selection(self, keyword='appresponse_device', label='AppResponse', module='appresponse', enabled=True) if self.options.source == 'packets': func = Function(appresponse_source_choices, self.options) TableField.create( keyword='appresponse_source', label='Source', obj=self, field_cls=IDChoiceField, field_kwargs={'widget_attrs': { 'class': 'form-control' }}, parent_keywords=['appresponse_device'], dynamic=True, pre_process_func=func) if self.options.show_entire_pcap: TableField.create(keyword='entire_pcap', obj=self, field_cls=forms.BooleanField, label='Entire PCAP', initial=True, required=False) fields_add_granularity(self, initial=field_options['granularity'], source=self.options.source) fields_add_time_selection(self, show_end=True, initial_duration=field_options['duration'])
def post_process_table(self, field_options): duration = field_options['duration'] if isinstance(duration, int): duration = "%dm" % duration fields_add_device_selection(self, keyword='netshark_device', label='NetShark', module='netshark', enabled=True) TableField.create(keyword='netshark_source_name', label='Source', obj=self, field_cls=forms.ChoiceField, parent_keywords=['netshark_device'], dynamic=True, pre_process_func=Function(netshark_source_name_choices)) fields_add_time_selection(self, initial_duration=duration, durations=field_options['durations']) fields_add_resolution(self, initial=field_options['resolution'], resolutions=field_options['resolutions']) self.fields_add_filterexpr()
def post_process_table(self, field_options): # # Add criteria fields that are required by this table # if self.options.show_entire_pcap: TableField.create(keyword='entire_pcap', obj=self, field_cls=forms.BooleanField, label='Entire PCAP', initial=True, required=False) fields_add_time_selection(self, show_start=True, show_end=True, show_duration=False) fields_add_resolution(obj=self, initial=field_options['resolution'], resolutions=field_options['resolutions']) if self.options.show_pcap_mgr: fields_add_pcapmgr_selection(obj=self) fields_add_filterexpr(obj=self)
from django import forms from steelscript.appfwk.apps.datasource.modules.analysis import CriteriaTable from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.apps.report.models import Report from steelscript.appfwk.apps.report.modules import raw report = Report.create(title='Criteria Bool') # Section section = report.add_section(title='Section 0') # Table a = CriteriaTable.create('test-criteria-bool') # Table-level criteria TableField.create('b1', 'Bool True', obj=a, field_cls=forms.BooleanField, initial=True) TableField.create('b2', 'Bool False', obj=a, field_cls=forms.BooleanField, initial=False) report.add_widget(raw.TableWidget, a, 'Table')
from steelscript.appfwk.apps.datasource.modules.analysis import CriteriaTable from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.libs.fields import Function from steelscript.appfwk.apps.report.models import Report from steelscript.appfwk.apps.report.modules import raw from steelscript.appfwk.apps.report.tests.reports \ import criteria_functions as funcs report = Report.create(title='Criteria Post Process Errors') section = report.add_section(title='Section 0') a = CriteriaTable.create('test-criteria-postprocess-errors') TableField.create('error', 'Error type', a) TableField.create('x', 'X Value', a, hidden=True, post_process_func=Function(funcs.postprocesserrors_compute)) report.add_widget(raw.TableWidget, a, 'Table')
from steelscript.appfwk.apps.datasource.modules.analysis import CriteriaTable from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.apps.report.models import Report from steelscript.appfwk.apps.report.modules import raw from steelscript.appfwk.apps.report.tests.reports import criteria_functions as funcs report = Report.create( title='Criteria Parents', hidden_fields=['report_computed', 'section_computed', 'table_computed']) # Report-level independent TableField.create('report_independent', 'Report Independent', obj=report) # Report-level computed TableField.create('report_computed', 'Reprot computed', obj=report, post_process_template='report_computed:{report_independent}', hidden=False) # Section section = report.add_section(title='Section 0') # Section-level computed TableField.create(keyword='section_computed', obj=section, post_process_template='section_computed:{report_computed}', hidden=False)
def post_process_table(self, field_options): super(CriteriaFieldMapTable, self).post_process_table(field_options) TableField.create('k1', 'Key 1', obj=self, initial='K1') TableField.create('k2', 'Key 2', obj=self, required=True)
from steelscript.appfwk.apps.datasource.modules.analysis import CriteriaTable from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.apps.report.models import Report from steelscript.appfwk.apps.report.modules import raw from steelscript.appfwk.apps.report.tests.reports import criteria_functions as funcs report = Report.create(title='Criteria Parents', hidden_fields=['report_computed', 'section_computed', 'table_computed']) # Report-level independent TableField.create('report_independent', 'Report Independent', obj=report) # Report-level computed TableField.create('report_computed', 'Reprot computed', obj=report, post_process_template='report_computed:{report_independent}', hidden=False) # Section section = report.add_section(title='Section 0') # Section-level computed TableField.create(keyword='section_computed', obj=section, post_process_template='section_computed:{report_computed}', hidden=False) # Table a = CriteriaTable.create('test-criteria-parents')
# This software is licensed under the terms and conditions of the MIT License # accompanying the software ("License"). This software is distributed "AS IS" # as set forth in the License. from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.apps.report.models import Report import steelscript.appfwk.apps.report.modules.yui3 as yui3 from steelscript.netprofiler.appfwk.datasources.netprofiler import \ NetProfilerTimeSeriesTable, NetProfilerGroupbyTable, NetProfilerTable report = Report.create("DSCP Report", position=10, hidden_fields=['netprofiler_filterexpr']) netprofiler_filterexpr = TableField.create( keyword='netprofiler_filterexpr') interface_field = TableField.create( keyword='interface', label='Interface', required=True) # # Overall section # - netprofiler_filterexpr = "interface {interface}" # section = report.add_section("Overall", section_keywords=['netprofiler_filterexpr', 'interface_expr']) section.fields.add(netprofiler_filterexpr) section.fields.add(interface_field)
from steelscript.appfwk.apps.datasource.modules.analysis import CriteriaTable from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.libs.fields import Function from steelscript.appfwk.apps.report.models import Report from steelscript.appfwk.apps.report.modules import raw from . import criteria_functions as funcs report = Report.create(title='Criteria Post Process') section = report.add_section(title='Section 0') a = CriteriaTable.create('test-criteria-postprocess') TableField.create('w', 'W Value', a) TableField.create('x', 'X Value', a) TableField.create('y', 'Y Value', a) for (f1, f2) in [('w', 'x'), ('w', 'y'), ('x', 'y')]: (TableField.create ('%s%s' % (f1, f2), '%s+%s Value' % (f1, f2), a, hidden=True, parent_keywords=[f1, f2], post_process_func=Function(funcs.postprocess_field_compute, params={'fields': [f1, f2]}))) report.add_widget(raw.TableWidget, a, 'Table')
def fields_add_time_selection( obj, show_duration=True, initial_duration=None, durations=None, show_start=False, initial_start_time='now-1h', initial_start_date='now-1h', show_end=True, initial_end_time='now-0', initial_end_date='now-0', round_initial=0, # seconds to round initial time special_values=None): if show_start: field = TableField(keyword='starttime', label='Start Time', field_cls=DateTimeField, field_kwargs={ 'widget': ReportSplitDateTimeWidget, 'widget_attrs': { 'initial_time': initial_start_time, 'initial_date': initial_start_date, 'round_initial': round_initial } }, required=False) field.save() obj.fields.add(field) if show_end: field = TableField(keyword='endtime', label='End Time', field_cls=DateTimeField, field_kwargs={ 'widget': ReportSplitDateTimeWidget, 'widget_attrs': { 'initial_time': initial_end_time, 'initial_date': initial_end_date, 'round_initial': round_initial } }, required=False) field.save() obj.fields.add(field) if show_duration: if durations is None: durations = DURATIONS field = TableField(keyword='duration', label='Duration', initial=initial_duration, field_cls=DurationField, field_kwargs={ 'choices': durations, 'special_values': special_values }, required=False) field.save() obj.fields.add(field)
from steelscript.appfwk.apps.datasource.modules.analysis import CriteriaTable from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.libs.fields import Function from steelscript.appfwk.apps.report.models import Report from steelscript.appfwk.apps.report.modules import raw from steelscript.appfwk.apps.report.tests.reports \ import criteria_functions as funcs report = Report.create(title='Criteria Pre Process') section = report.add_section(title='Section 0') TableField.create('choices', 'Choices', section, field_cls=forms.ChoiceField, pre_process_func=Function(funcs.preprocess_field_choices)) TableField.create('choices_with_params', 'Choices with params', section, field_cls=forms.ChoiceField, pre_process_func=Function( funcs.preprocess_field_choices_with_params, params={ 'start': 1, 'end': 3, 'prefix': 'pre' }))
def fields_add_business_hour_fields(obj, initial_biz_hours_start='8:00am', initial_biz_hours_end='5:00pm', initial_biz_hours_tzname='US/Eastern', initial_biz_hours_weekends=False, **kwargs): kwargs['initial_duration'] = kwargs.get('initial_duration', '1w') fields_add_time_selection(obj, show_start=True, **kwargs) time_choices = {'choices': zip(TIMES, TIMES)} business_hours_start = TableField(keyword='business_hours_start', label='Start Business', initial=initial_biz_hours_start, field_cls=forms.ChoiceField, field_kwargs=time_choices, required=True) business_hours_start.save() obj.fields.add(business_hours_start) business_hours_end = TableField(keyword='business_hours_end', label='End Business', initial=initial_biz_hours_end, field_cls=forms.ChoiceField, field_kwargs=time_choices, required=True) business_hours_end.save() obj.fields.add(business_hours_end) tz_choices = {'choices': zip(pytz.common_timezones, pytz.common_timezones)} business_hours_tzname = TableField(keyword='business_hours_tzname', label='Business Timezone', initial=initial_biz_hours_tzname, field_cls=forms.ChoiceField, field_kwargs=tz_choices, required=True) business_hours_tzname.save() obj.fields.add(business_hours_tzname) business_hours_weekends = TableField(keyword='business_hours_weekends', field_cls=forms.BooleanField, label='Business includes weekends', initial=initial_biz_hours_weekends, required=False) business_hours_weekends.save() obj.fields.add(business_hours_weekends)
def add_netprofiler_hostgroup_field(report, section, hg_type=None): """ Attach fields for dynamic HostGroup dropdowns to add as filter expressions to the report. This can be added for each section in a report where the added filter expression is desired. The optional ``hg_type`` argument can be either a single string or a list of strings for each HostGroupType. If a single string, the 'HostGroupType' field will be hidden and automatically filter HostGroups to the given HostGroupType. If a list, the elements of the HostGroupType list will be fixed to those in the list; this can be helpful if certain HostGroupTypes may be sensitive or not applicable to the report. """ # add default filter expr to extend against filterexpr = TableField.create(keyword='netprofiler_filterexpr') section.fields.add(filterexpr) # defaults if we are using hostgroup type field hg_template = '{hostgroup_type}' hg_parent = ['hostgroup_type'] hg_params = None if hg_type is None: # add hostgroup types field that queries netprofiler field = TableField.create( keyword='hostgroup_type', label='HostGroup Type', obj=report, field_cls=forms.ChoiceField, parent_keywords=['netprofiler_device'], dynamic=True, pre_process_func=Function(netprofiler_hostgroup_types) ) section.fields.add(field) elif type(hg_type) in (list, tuple): # add hostgroup types field that uses given list field = TableField.create( keyword='hostgroup_type', label='HostGroup Type', obj=report, field_cls=forms.ChoiceField, field_kwargs={'choices': zip(hg_type, hg_type)}, parent_keywords=['netprofiler_device'], ) section.fields.add(field) else: # no field, hardcode the given value hg_template = hg_type hg_parent = None hg_params = {'hostgroup_type': hg_type} # add hostgroup field field = TableField.create( keyword='hostgroup', label='HostGroup', obj=report, field_cls=forms.ChoiceField, parent_keywords=hg_parent, dynamic=True, pre_process_func=Function(netprofiler_hostgroups, params=hg_params) ) section.fields.add(field) NetProfilerTable.extend_filterexpr( section, keyword='hg_filterexpr', template='hostgroup %s:{hostgroup}' % hg_template )
# accompanying the software ("License"). This software is distributed "AS IS" # as set forth in the License. from steelscript.appfwk.apps.datasource.models import TableField from steelscript.appfwk.apps.report.models import Report import steelscript.appfwk.apps.report.modules.c3 as c3 import steelscript.appfwk.apps.report.modules.tables as tables from steelscript.netprofiler.appfwk.datasources.netprofiler import \ NetProfilerTimeSeriesTable, NetProfilerGroupbyTable, NetProfilerTable report = Report.create("DSCP Report", position=10, hidden_fields=['netprofiler_filterexpr']) netprofiler_filterexpr = TableField.create( keyword='netprofiler_filterexpr') interface_field = TableField.create( keyword='interface', label='Interface', required=True) # # Overall section # - netprofiler_filterexpr = "interface {interface}" # section = report.add_section("Overall", section_keywords=['netprofiler_filterexpr', 'interface_expr']) section.fields.add(netprofiler_filterexpr) section.fields.add(interface_field)