示例#1
0
    def test_process_port_data_one_row(self):
        example_results = [{'peerAddress': '127.0.0.1', 'user_input': 'hello',
                            'session': 'f6cae8f0-5c61-4319-b357-1dcc20ab6fe4',
                            'localAddress': '127.0.0.1', 'input_type': 'username', 'ID': 1,
                            'eventDateTime': '2016-04-23T16:12:20.497293'}]

        json_expected = {
            'begin_time': '2016-04-23T16:12:20.497293',
            'end_time': '2016-04-23T16:12:20.497293',
            'local_address': '127.0.0.1',
            'peer_address': '127.0.0.1',
            'session': 'f6cae8f0-5c61-4319-b357-1dcc20ab6fe4',
            'duration': '0:00:00',
            'session_items': [{
                'peerAddress': '127.0.0.1',
                'user_input': 'hello',
                'session': 'f6cae8f0-5c61-4319-b357-1dcc20ab6fe4',
                'localAddress': '127.0.0.1',
                'input_type': 'username',
                'ID': 1,
                'eventDateTime': '2016-04-23T16:12:20.497293'
            }]
        }

        json_received = utilities.process_data(example_results)

        print("expected:" + str(json_expected))
        print("received:" + str(json_received))

        # self.assertListEqual(json_received['session_items'], json_expected['session_items'])
        self.assertEqual(len(json_received), 1)
        self.assertEqual(json_received[0]['begin_time'], json_expected['begin_time'])
        self.assertEqual(json_received[0]['end_time'], json_expected['end_time'])
        self.assertEqual(len(json_received[0]['session_items']), 1)
        self.assertDictEqual(json_received[0]['session_items'][0], json_expected['session_items'][0])
示例#2
0
    def get_data(self, ipaddress, uom, unit):
        self.log.info("Retrieving ipaddress data: " + str(ipaddress) + "  uom:  " + uom + " size: " + str(unit))

        port_data = []

        for port in self.valid_port_numbers:
            results = self.get_json_by_ip(port, ipaddress, uom, unit)
            items = utilities.process_data(results)
            port_data.append({port:items})

        port_json = {
            'ipaddress': str(ipaddress),
            'timespan': uom + "=" + str(unit),
            'ports':port_data
        }
        return port_json
示例#3
0
    def getPort(self, port_number, uom, unit):
        self.log.info("Retrieving port:" + str(port_number) + "uom:" + uom + " size: " + str(unit))

        items = []

        if self.isPortValid(port_number):
            results = DatabaseHandler().get_json_by_time(port_number, uom, unit)
            items = utilities.process_data(results)

        port_json = {
            'port': str(port_number),
            'timespan': uom + "=" + str(unit),
            'items':items
        }

        return port_json