コード例 #1
0
    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)
コード例 #2
0
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)
コード例 #3
0
    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')
コード例 #4
0
 def post_process_table(self, field_options):
     self.criteria_handle_func = Function(criteria_handle)
     self.save()
     fields_add_device_selection(self,
                                 keyword='netprofiler_device',
                                 label='NetProfiler',
                                 module='netprofiler',
                                 enabled=True)
コード例 #5
0
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)
コード例 #6
0
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}'
    )
コード例 #7
0
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)
コード例 #8
0
    def fields_add_filterexprs_field(self, keyword):

        field = self.fields.get(keyword='netprofiler_filterexpr')
        field.post_process_func = Function(
            function=_post_process_combine_filterexprs)

        parent_keywords = set(field.parent_keywords or [])
        parent_keywords.add(keyword)
        field.parent_keywords = list(parent_keywords)
        field.save()

        return field
コード例 #9
0
    def process_options(cls, table_options):
        # handle direct id's, table references, or table classes
        # from tables option and transform to simple table id value
        for i in ['tables', 'related_tables']:
            for k, v in (table_options[i] or {}).iteritems():
                table_options[i][k] = Table.to_ref(v)

        tf = table_options['function']
        if tf and not isinstance(tf, Function):
            table_options['function'] = Function(tf)

        return table_options
コード例 #10
0
    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()
コード例 #11
0
    def create(cls, source, trigger_func, params=None, **kwargs):
        """Create trigger against given source table.

        :param table source: Table object reference
        :param function trigger_func: function object to run for trigger
        :param dict params: optional additional parameters to pass to
            trigger_func
        """
        tfunc = Function(trigger_func, params=params)
        t = Trigger(name=kwargs.pop('name', Source.name(source)),
                    source=Source.encode(source),
                    trigger_func=tfunc,
                    **kwargs)
        t.save()
        return t
コード例 #12
0
    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)
コード例 #13
0
    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)
コード例 #14
0
    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)
            fields_add_source_choices(self, func)

            if self.options.show_entire_pcap:
                fields_add_entire_pcap(self)

        if self.options.include_filter:
            fields_add_filterexpr(self)

        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'])
コード例 #15
0
    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'])
コード例 #16
0
 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')
コード例 #17
0
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,
            field_kwargs={'widget_attrs': {'class': 'form-control'}},
            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),
                          'widget_attrs': {'class': 'form-control'}},
            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,
        field_kwargs={'widget_attrs': {'class': 'form-control'}},
        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
    )
コード例 #18
0
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')
コード例 #19
0
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')
コード例 #20
0
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'
                      }))

a = CriteriaTable.create('test-criteria-preprocess')
コード例 #21
0
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 Shared Fields')

x = TableField.create('x', 'X Value')
for i in range(2):

    section = report.add_section(title='Section %d' % i)

    a = CriteriaTable.create('test-criteria-sharedfields-%d' % i)

    a.fields.add(x)
    y = TableField.create('y',
                          'Y Value',
                          a,
                          hidden=True,
                          parent_keywords=['x'],
                          post_process_func=Function(
                              funcs.sharedfields_compute,
                              params={'factor': 10 * (i + 1)}))

    report.add_widget(raw.TableWidget, a, 'Table %d' % i)