def timestable(name): table = AnalysisTable.create(name, tables={}, func=compute_times) Column.create(table, 'starttime', 'Start time', datatype='time', iskey=True, issortcol=True) Column.create(table, 'endtime', 'End time', datatype='time', iskey=True) Column.create(table, 'totalsecs', 'Total secs') fields_add_business_hour_fields(table) return table
def timestable(): name = 'business_hours.timestable' try: table = Table.objects.get(name=name) except ObjectDoesNotExist: table = AnalysisTable.create(name, tables={}, func=compute_times) Column.create(table, 'starttime', 'Start time', datatype='time', iskey=True, issortcol=True) Column.create(table, 'endtime', 'End time', datatype='time', iskey=True) Column.create(table, 'totalsecs', 'Total secs') return table
def create(name, basetable, aggregate, **kwargs): table = AnalysisTable.create(name, tables={'times': timestable(name + '-times').id}, related_tables={'basetable': basetable.id}, func=report_business_hours, params={'aggregate': aggregate}, **kwargs) table.copy_columns(basetable) return table
def create(name, basetable, aggregate, other_tables=None, **kwargs): table = AnalysisTable.create(name, tables={'times': timestable().id}, func=report_business_hours, params={'table': basetable.id, 'aggregate': aggregate}, **kwargs) table.copy_columns(basetable) [table.fields.add(f) for f in basetable.fields.all()] return table
# helper libraries from rvbd_portal.apps.plugins.builtin.whois.libs.whois import whois # # Profiler report # report = Report(title="Whois", position=5) report.save() section = Section.create(report) # Define a Table that gets external hosts by avg bytes table = GroupByTable.create('5-hosts', 'host', duration='1 hour', filterexpr='not srv host 10/8 and not srv host 192.168/16') Column.create(table, 'host_ip', 'IP Addr', iskey=True) Column.create(table, 'avg_bytes', 'Avg Bytes', units='s', issortcol=True) # Create an Analysis table that calls the 'whois' function to craete a link to 'whois' whoistable = AnalysisTable.create('5-whois-hosts', tables={'t': table.id}, func=whois) Column.create(whoistable, 'host_ip', label="IP Addr", iskey=True) Column.create(whoistable, 'avg_bytes', 'Avg Bytes', datatype='bytes', issortcol=True) Column.create(whoistable, 'whois', label="Whois link", datatype='html') yui3.TableWidget.create(section, whoistable, "Link table", width=12)
from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import Column from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from rvbd_portal.apps.datasource.forms import fields_add_time_selection, fields_add_resolution from . import synthentic_functions as funcs # Report report = Report(title='Synthetic No Resampling' ) report.save() # Section section = Section(report=report, title='Section 0') section.save() # Table table = AnalysisTable.create('test-synthetic-noresampling', tables={}, func = funcs.analysis_echo_criteria) fields_add_time_selection(table) fields_add_resolution(table) Column.create(table, 'time', 'Time', iskey=True, isnumeric=True, datatype='time') Column.create(table, 'value', 'Value', isnumeric=True) raw.TableWidget.create(section, table, 'Table')
from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from . import criteria_functions as funcs report = Report(title='Criteria Section Keywords') report.save() # Section section = Section.create(report=report, title='Section 0', section_keywords=['k1']) section.save() # Table table = AnalysisTable.create('test-criteria-sectionkeywords-1', tables={}, func = funcs.analysis_echo_criteria) TableField.create(keyword='k1', label='Key 1', obj=table, initial='r1') Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table 1') # Section section = Section.create(report=report, title='Section 1', section_keywords=['k1']) section.save() # Table table = AnalysisTable.create('test-criteria-sectionkeywords-2', tables={}, func = funcs.analysis_echo_criteria) TableField.create(keyword='k1', label='Key 1', obj=table, initial='r1')
# Common methods: # sum - just add up all the data, typical for totals # avg - compute the average (using time as a weight), for anything "average" # min - minimum of all values # max - maximum of all values # bustable_pre = bizhours.create('bh-bustable-pre', basetable, aggregate={'avg_util': 'avg', 'in_avg_util': 'avg', 'out_avg_util': 'avg'}) # Device Table devtable = DevicesTable.create('devtable') Column.create(devtable, 'ipaddr', 'Device IP', iskey=True, isnumeric=False) Column.create(devtable, 'name', 'Device Name', isnumeric=False) Column.create(devtable, 'type', 'Flow Type', isnumeric=False) Column.create(devtable, 'version', 'Flow Version', isnumeric=False) bustable = AnalysisTable.create('bh-bustable', tables={'devices': devtable.id, 'traffic': bustable_pre.id}, func=protools.process_join_ip_device) Column.create(bustable, 'interface_name', 'Interface', iskey=True, isnumeric=False) bustable.copy_columns(bustable_pre, except_columns=['interface_dns']) yui3.TableWidget.create(section, bustable, "Interface", height=600) yui3.BarWidget.create(section, bustable, "Interface Utilization", height=600, keycols=['interface_name'], valuecols=['avg_util']) yui3.TableWidget.create(section, bizhours.timestable(), "Covered times", width=12, height=200)
from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import Column from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from rvbd_portal.apps.datasource.forms import fields_add_time_selection, fields_add_resolution # Report from rvbd_portal.apps.report.tests.reports import synthetic_functions as funcs report = Report(title='Synthetic No Resampling' ) report.save() # Section section = Section(report=report, title='Section 0') section.save() # Table table = AnalysisTable.create('test-synthetic-resampling', tables={}, func = funcs.analysis_generate_data, resample = True, params = {'source_resolution': 60 }) fields_add_time_selection(table) fields_add_resolution(table) Column.create(table, 'time', 'Time', iskey=True, isnumeric=True, datatype='time') Column.create(table, 'value', 'Value', isnumeric=True) raw.TableWidget.create(section, table, 'Table')
from rvbd_portal.apps.datasource.models import TableField, Table, Column from rvbd_portal.libs.fields import Function from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from . import criteria_functions as funcs report = Report(title='Criteria Changing with Sections', field_order =['first', 'second']) report.save() section = Section.create(report=report, title='Section 0', section_keywords=['first','second']) section.save() table = AnalysisTable.create('test-criteria-changingchoiceswithsections-0', tables={}, func = funcs.analysis_echo_criteria) TableField.create ('first', 'First Choice', table, field_cls = forms.ChoiceField, field_kwargs = {'choices': (('a', 'Option A'), ('b', 'Option B') ) }) TableField.create ('second', 'Second Choice', table, field_cls = forms.ChoiceField, pre_process_func = Function(funcs.preprocess_changesecond), dynamic=True) Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table 0')
# sum - just add up all the data, typical for totals # avg - compute the average (using time as a weight), for anything "average" # min - minimum of all values # max - maximum of all values # biztable = bizhours.create('bh-biztable', basetable, aggregate={'avg_util': 'avg', 'in_avg_util': 'avg', 'out_avg_util': 'avg'}) # Device Table devtable = DevicesTable.create('devtable') Column.create(devtable, 'ipaddr', 'Device IP', iskey=True, isnumeric=False) Column.create(devtable, 'name', 'Device Name', isnumeric=False) Column.create(devtable, 'type', 'Flow Type', isnumeric=False) Column.create(devtable, 'version', 'Flow Version', isnumeric=False) interfaces = AnalysisTable.create('bh-interfaces', tables={'devices': devtable.id, 'traffic': biztable.id}, func=protools.process_join_ip_device) Column.create(interfaces, 'interface_name', 'Interface', iskey=True, isnumeric=False) interfaces.copy_columns(biztable, except_columns=['interface_dns']) yui3.TableWidget.create(section, interfaces, "Interface", height=600) yui3.BarWidget.create(section, interfaces, "Interface Utilization", height=600, keycols=['interface_name'], valuecols=['avg_util']) yui3.TableWidget.create(section, bizhours.get_timestable(biztable), "Covered times", width=12, height=200)
from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from . import criteria_functions as funcs report = Report(title='Criteria Changing', field_order =['first', 'second']) report.save() section = Section(report=report, title='Section 0') section.save() TableField.create ('first', 'First Choice', section, field_cls = forms.ChoiceField, field_kwargs = {'choices': (('a', 'Option A'), ('b', 'Option B') ) }) TableField.create ('second', 'Second Choice', section, field_cls = forms.ChoiceField, pre_process_func = Function(funcs.preprocess_changesecond), dynamic=True) table = AnalysisTable.create('test-criteria-changingchoices', tables={}, func = funcs.analysis_echo_criteria) Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table')
from rvbd_portal.apps.datasource.models import TableField, Table, Column from rvbd_portal.libs.fields import Function from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from . import criteria_functions as funcs report = Report(title='Criteria Circular Dependency') report.save() # Section section = Section(report=report, title='Section 0') section.save() table = AnalysisTable.create('test-criteria-circulardependency', tables={}, func = funcs.analysis_echo_criteria) TableField.create(keyword='t1', obj=table, post_process_template='table_computed:{t2}', hidden=False) TableField.create(keyword='t2', obj=table, post_process_template='table_computed:{t3}', hidden=False) TableField.create(keyword='t3', obj=table, post_process_template='table_computed:{t1}', hidden=False) Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False)
from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from rvbd_portal.apps.report.tests.reports import criteria_functions as funcs report = Report(title='Criteria Shared Fields' ) report.save() section = Section(report=report, title='Section') section.save() x = TableField.create('x', 'X Value') for i in range(2): table = AnalysisTable.create('test-criteria-sharedfields-%d' % i, tables={}, func = funcs.analysis_echo_criteria) Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) table.fields.add(x) y = TableField.create('y', 'Y Value', table, hidden=True, parent_keywords = ['x'], post_process_func = Function(funcs.sharedfields_compute, params={'factor': 10*(i+1)})) raw.TableWidget.create(section, table, 'Table %d' % i)
from django import forms from rvbd_portal.apps.datasource.forms import fields_add_time_selection from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import TableField, Table, Column from rvbd_portal.libs.fields import Function from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from . import criteria_functions as funcs report = Report(title='Criteria Two Reports - 2') report.save() TableField.create(keyword='k2', label='Key 2', obj=report, initial='r2') # Section section = Section.create(report=report, title='Section') section.save() # Table table = AnalysisTable.create('test-criteria-tworeports-2', tables={}, func = funcs.analysis_echo_criteria) TableField.create(keyword='k1', label='Key 1', obj=table, initial='r1') Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table 2')
from rvbd_portal.apps.report.models import Report, Section import rvbd_portal.apps.report.modules.raw as raw from rvbd_portal.apps.datasource.forms import fields_add_time_selection from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import Column from rvbd_portal.apps.report.tests.reports import criteria_functions as funcs report = Report(title='Criteria Time Selection' ) report.save() section = Section(report=report, title='Section 0') section.save() table = AnalysisTable.create('test-criteria-timeselection', tables={}, func = funcs.analysis_echo_criteria) fields_add_time_selection(table, initial_duration='1 day') Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table')
from rvbd_portal.apps.report.tests.reports import criteria_functions as funcs report = Report(title='Criteria Defaults') report.save() # Report-level criteria TableField.create(keyword='report-1', label='Report 1', obj=report, initial='r1') TableField.create(keyword='report-2', label='Report 2', obj=report, required=True) # Section section = Section(report=report, title='Section 0') section.save() # Section-level criteria TableField.create(keyword='section-1', label='Section 1', obj=section, initial='s1') TableField.create(keyword='section-2', label='Section 2', obj=section, required=True, initial='s2') # Table table = AnalysisTable.create('test-criteria-postprocess', tables={}, func = funcs.analysis_echo_criteria) # Table-level criteria TableField.create(keyword='table-1', label='Table 1', obj=table, initial='t1') TableField.create(keyword='table-2', label='Table 2', obj=table, initial='t2') Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table')
from django import forms from rvbd_portal.apps.datasource.forms import fields_add_time_selection from rvbd_portal.apps.datasource.modules.analysis import AnalysisTable from rvbd_portal.apps.datasource.models import TableField, Table, Column from rvbd_portal.libs.fields import Function from rvbd_portal.apps.report.models import Report, Section from rvbd_portal.apps.report.modules import raw from . import criteria_functions as funcs report = Report(title='Criteria Two Reports - 1') report.save() # Section section = Section.create(report=report, title='Section') section.save() # Table table = AnalysisTable.create('test-criteria-tworeports-1', tables={}, func = funcs.analysis_echo_criteria) TableField.create(keyword='k1', label='Key 1', obj=table, initial='r1') Column.create(table, 'key', 'Key', iskey=True, isnumeric=False) Column.create(table, 'value', 'Value', isnumeric=False) raw.TableWidget.create(section, table, 'Table 1')