def main(self):
        netprof = self.netprofiler

        timefilter = TimeFilter.parse_range(self.options.timefilter)

        # Create and run a traffic summary report of all server ports in use
        report = TrafficSummaryReport(netprof)

        # Run the report
        report.run(
            groupby=netprof.groupbys.port,
            columns=[netprof.columns.key.protoport,
                     netprof.columns.key.protocol,
                     netprof.columns.key.port,
                     netprof.columns.value.avg_bytes],
            sort_col=netprof.columns.value.avg_bytes,
            timefilter=timefilter)

        # Retrieve and print data
        ports_data = report.get_data()[:int(self.options.N)]
        report.delete()

        # Now create a new report using the ports_data
        report = TrafficTimeSeriesReport(netprof)

        # The format the query_columns for 'ports' is:
        #    'ports' = [{'name': 'tcp/80'},
        #               {'name': 'tcp/443'},
        #               {'name': 'icmp/0'}]
        # For most protocols, this works just fine from the report data,
        # but for icmp the result from data is 'icmp/0/0' -- where the two
        # zeros are type and code.  This doesn't work for input to
        # netprofiler, it expects type and code to be smushed into a single
        # 16-bit number (type << 8 | code).
        query_columns = []
        for (protoport, protocol, port, avgbytes) in ports_data:
            if protoport.startswith('icmp'):
                protoport = 'icmp/%s' % (port)

            query_columns.append({'name': protoport})

        # Run the report
        report.run(columns=[netprof.columns.key.time,
                            netprof.columns.value.avg_bytes],
                   resolution='1 min',
                   query_columns_groupby='ports',
                   query_columns=query_columns,
                   timefilter=timefilter)

        # Get the data!
        data = report.get_data()
        Formatter.print_table(
            data, padding=1,
            headers=(['time'] + [q['name'] for q in query_columns]))
예제 #2
0
    def main(self):
        self.tfilter1 = TrafficFilter(self.options.expr1)
        self.report1 = TrafficSummaryReport(self.netprofiler)
        self.columns_report1 = self.netprofiler.get_columns([self.options.column1])
        self.trigger1 = safe_lambda(self.options.trigger1)

        if self.options.trigger2 and self.options.column2 and self.options.expr2:
            self.tfilter2 = TrafficFilter(self.options.expr2)
            self.report2 = TrafficSummaryReport(self.netprofiler)
            self.columns_report2 = self.netprofiler.get_columns([self.options.column2])
            self.trigger2 = safe_lambda(self.options.trigger2)
        else:
            self.trigger2 = None

        try:
            while 1:
                print('Running report 1 ...')
                alert_flag = False
                result = None
                result2 = None

                result = self.run_query(self.report1,
                                        self.columns_report1,
                                        self.tfilter1,
                                        self.trigger1)
                if result:
                    if self.trigger2:
                        print('Trigger 1 passed, running report 2 ...')
                        result2 = self.run_query(self.report2,
                                                 self.columns_report2,
                                                 self.tfilter2,
                                                 self.trigger2)
                        if result2:
                            print('Trigger 2 passed ...')
                            alert_flag = True
                    else:
                        print('Trigger 1 passed ...')
                        alert_flag = True
                if alert_flag:
                    print('ALERT ALERT!')
                    self.update_description(result, result2)
                    self.send_trap()

                time.sleep(self.options.refresh)

        except KeyboardInterrupt:
            print('Exiting ...')
            sys.exit(0)
 def test_resolution(self):
     groupby = self.profiler.groupbys.host
     columns = [self.profiler.columns.key.host_ip,
                self.profiler.columns.value.avg_bytes,
                self.profiler.columns.value.avg_pkts]
     sort_col = self.profiler.columns.value.avg_bytes
     trafficexpr = TrafficFilter("host 10/8")
     resolutions = [["1min", "last 5 min"],
                    ["15min", "last 1 hour"],
                    ["hour", "last 4 hours"],
                    ["6hour", "last 1 day"],
                    ["day", "last 1 week"],
                    ["3600", "last 4 hours"],  # hour resolution
                    ["60", "last 5 min"],      # minute resolution
                    #["week", "last 4 weeks"],
                    #["month", "last 12 months"],
                    #Commented values blow up with a
                    #E       RvbdHTTPException: 400 Unknown time resolution.
                    ]
     for (resolution, duration) in resolutions:
         timerange = TimeFilter.parse_range(duration)
         with TrafficSummaryReport(self.profiler) as rep:
             rep.run(groupby, columns,
                     sort_col, timerange,
                     trafficexpr, resolution=resolution)
    def test_traffic_summary_report(self):
        groupby = self.profiler.groupbys.host
        columns = [self.profiler.columns.key.host_ip,
                   self.profiler.columns.value.avg_bytes,
                   self.profiler.columns.value.avg_pkts]
        sort_col = self.profiler.columns.value.avg_bytes
        timerange = self.yesterday
        trafficexpr = TrafficFilter("host 10/8")

        with TrafficSummaryReport(self.profiler) as rep:
            rep.run(groupby, columns,
                    sort_col, timerange,
                    trafficexpr)
            legend = rep.get_legend()
            self.assertEqual(len(legend), 3)
            legend = rep.get_legend(columns=[self.profiler.columns.key.host_ip,
                                             self.profiler.columns.value.avg_bytes])
            self.assertEqual(len(legend), 2)
            self.assertEqual(legend[0].key, 'host_ip')
            self.assertEqual(legend[1].key, 'avg_bytes')

            data = rep.get_data()
            if data:
                self.assertEqual(len(data[0]), 3)

            #check that data is refetched from cache
            data = rep.get_data()

            data = rep.get_data(columns=[self.profiler.columns.key.host_ip,
                                         self.profiler.columns.value.avg_bytes])
            if data:
                self.assertEqual(len(data[0]), 2)
    def main(self):
        # groupby validation should be part of validate_args, but there
        # is no NetProfiler initialized at that part of the initialization
        try:
            self.groupby = self.netprofiler.groupbys[self.options.groupby]
        except KeyError:
            if self.options.groupby not in self.netprofiler.groupbys.values():
                self.parser.error('Invalid groupby chosen.')
            else:
                self.groupby = self.options.groupby

        self.timefilter = TimeFilter.parse_range(self.options.timefilter)
        if self.options.trafficexpr:
            self.trafficexpr = TrafficFilter(self.options.trafficexpr)
        else:
            self.trafficexpr = None

        with TrafficSummaryReport(self.netprofiler) as report:
            report.run(columns=self.options.columns.split(','),
                       groupby=self.groupby,
                       sort_col=self.options.sortby,
                       timefilter=self.timefilter,
                       trafficexpr=self.trafficexpr,
                       centricity=self.centricity,
                       resolution='auto')
            data = report.get_data()
            legend = [c.label for c in report.get_legend()]

        self.print_data(data, legend)
 def test_report_with_area(self):
     groupby = self.profiler.groupbys.host
     columns = [self.profiler.columns.key.host_ip,
                self.profiler.columns.value.avg_bytes,
                self.profiler.columns.value.avg_pkts]
     sort_col = self.profiler.columns.value.avg_bytes
     timerange = self.yesterday
     trafficexpr = TrafficFilter("host 10/8")
     area = self.profiler.areas.vxlan_tenant
     with TrafficSummaryReport(self.profiler) as rep:
         rep.run(groupby, columns,
                 sort_col, timerange,
                 trafficexpr, area=area)
예제 #7
0
    def traffic_report(self, host, timefilter, report_type):
        """ Generate average statistics for host given `timefilter` time period

            `report_type` is one of ('timeseries', 'summary')
        """
        print 'Running %s report for %s over %s/%s' % (
            report_type, host, timefilter.start, timefilter.end)

        texpr = TrafficFilter('host %s' % host)

        if report_type == 'timeseries':
            columns = [c[0] for c in TCOLUMNS]
            report = TrafficOverallTimeSeriesReport(self.netprofiler)
            report.run(columns,
                       timefilter=timefilter,
                       trafficexpr=texpr,
                       resolution=self.options.resolution)
        elif report_type == 'summary':
            columns = [c[0] for c in SCOLUMNS]
            report = TrafficSummaryReport(self.netprofiler)

            if self.options.groupby_application:
                columns.insert(0, 'app_name')
                groupby = 'app'
            elif self.options.groupby_interface:
                columns.insert(0, 'interface_alias')
                columns.insert(0, 'interface')
                groupby = 'ifc'
            else:
                groupby = 'hos'

            report.run(groupby,
                       columns,
                       timefilter=timefilter,
                       trafficexpr=texpr,
                       resolution=self.options.resolution)
        else:
            raise RuntimeError('unknown report type: %s' % report_type)

        print 'Report complete, gathering data ...'
        data = report.get_data()
        if not data:
            print "Empty data results."
        elif len(data) == 10000:
            print 'WARNING: data size exceeds max length of 10000 rows'
        legend = report.get_legend()
        report.delete()

        return legend, data
    def test_unsupported_column(self):
        groupby = self.profiler.groupbys.port

        # host_ip shouldn't be included as part of 'port' groupby
        columns = [self.profiler.columns.key.host_ip,
                   self.profiler.columns.value.avg_bytes,
                   self.profiler.columns.value.avg_pkts]
        sort_col = self.profiler.columns.value.avg_bytes

        timerange = self.yesterday
        trafficexpr = TrafficFilter("host 10/8")

        report = TrafficSummaryReport(self.profiler)
        kwds = dict(groupby=groupby,
                    columns=columns,
                    sort_col=sort_col,
                    timefilter=timerange,
                    trafficexpr=trafficexpr)
        self.assertRaises(RvbdException, report.run, None, kwds)
    def main(self):
        netprof = self.netprofiler

        timefilter = TimeFilter.parse_range(self.options.timefilter)

        # Create and run a traffic summary report of all server ports in use
        report = TrafficSummaryReport(netprof)

        # Run the report
        report.run(groupby=netprof.groupbys.port,
                   columns=[
                       netprof.columns.key.protoport,
                       netprof.columns.key.protocol, netprof.columns.key.port,
                       netprof.columns.value.avg_bytes
                   ],
                   sort_col=netprof.columns.value.avg_bytes,
                   timefilter=timefilter)

        # Retrieve and print data
        ports_data = report.get_data()[:int(self.options.N)]
        report.delete()

        # Now create a new report using the ports_data
        report = TrafficTimeSeriesReport(netprof)

        # The format the query_columns for 'ports' is:
        #    'ports' = [{'name': 'tcp/80'},
        #               {'name': 'tcp/443'},
        #               {'name': 'icmp/0'}]
        # For most protocols, this works just fine from the report data,
        # but for icmp the result from data is 'icmp/0/0' -- where the two
        # zeros are type and code.  This doesn't work for input to
        # netprofiler, it expects type and code to be smushed into a single
        # 16-bit number (type << 8 | code).
        query_columns = []
        for (protoport, protocol, port, avgbytes) in ports_data:
            if protoport.startswith('icmp'):
                protoport = 'icmp/%s' % (port)

            query_columns.append({'name': protoport})

        # Run the report
        report.run(columns=[
            netprof.columns.key.time, netprof.columns.value.avg_bytes
        ],
                   resolution='1 min',
                   query_columns_groupby='ports',
                   query_columns=query_columns,
                   timefilter=timefilter)

        # Get the data!
        data = report.get_data()
        Formatter.print_table(data,
                              padding=1,
                              headers=(['time'] +
                                       [q['name'] for q in query_columns]))
예제 #10
0
# connection information
username = '******'
password = '******'
host = '<netprofiler.ip.address>'

if (username == '<username>' or password == '<password>'
        or host == '<netprofiler.ip.address>'):
    print("Update the username, password, and netprofiler host values "
          "before running this script.")
    sys.exit(0)

auth = UserAuth(username, password)

p = NetProfiler(host, auth=auth)
report = TrafficSummaryReport(p)

columns = [
    p.columns.key.host_ip, p.columns.value.avg_bytes,
    p.columns.value.network_rtt
]
sort_column = p.columns.value.avg_bytes
timefilter = TimeFilter.parse_range("last 15 m")

report.run('hos', columns, timefilter=timefilter, sort_col=sort_column)
data = report.get_data()
legend = report.get_legend()
report.delete()

pprint.pprint(data[:10])
# connection information
username = '******'
password = '******'
host = '<netprofiler.ip.address>'

if (username == '<username>' or
        password == '<password>' or
        host == '<netprofiler.ip.address>'):
    print ("Update the username, password, and netprofiler host values "
           "before running this script.")
    sys.exit(0)

auth = UserAuth(username, password)

p = NetProfiler(host, auth=auth)
report = TrafficSummaryReport(p)

columns = [p.columns.key.host_ip,
           p.columns.value.avg_bytes,
           p.columns.value.network_rtt]
sort_column = p.columns.value.avg_bytes
timefilter = TimeFilter.parse_range("last 15 m")

report.run('hos', columns, timefilter=timefilter, sort_col=sort_column)
data = report.get_data()
legend = report.get_legend()
report.delete()

pprint.pprint(data[:10])