Esempio n. 1
0
def _parse_traffic_stats(data_array):
    data_array = data_array[:4]
    if len(data_array) != 4:
        raise RouterParseError('Unexpected stats size: %d' % len(data_array))

    data_array = map(int, list(data_array))
    return TrafficStats(*data_array)
Esempio n. 2
0
def parse_traffic_stats(html):
    regex = re.compile('slist\[0\]\+"</B>","([0-9]+)","([0-9]+)",')
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot parse traffic stats')
    packets_recv, packets_sent = map(int, match_object.groups())
    return TrafficStats(0, 0, packets_recv, packets_sent)
Esempio n. 3
0
def _parse_traffic_stats(html):
    regex = re.compile('Ethernet WAN(?:.+?)<td>([0-9]+)</td>'
                       '(?:.+?)<td>([0-9]+)</td>', re.DOTALL)
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot determine WAN stats!')
    packets_sent, packets_recv = map(int, match_object.groups())
    return TrafficStats(0, 0, packets_recv, packets_sent)
Esempio n. 4
0
def _parse_traffic_stats(html):
    regex = "showText\(EthernetWAN\)(?:.+?)table2(?:.+?)&nbsp;([0-9]+)(?:.+?)table2(?:.+?)&nbsp;([0-9]+)"
    match_object = re.compile(regex, re.DOTALL).search(html)
    if match_object is None:
        raise RouterParseError('Cannot _parse traffic stats')

    packets_sent, packets_recv = map(int, match_object.groups())
    # sadly, we've got only packets and no size information..
    return TrafficStats(0, 0, packets_recv, packets_sent)
Esempio n. 5
0
def _parse_traffic_stats(html):
    # The monthly_history array contains one or more other arrays.
    # Each of those arrays contains 3 items (like a 3-tuple), which are:
    #   1. time data, for which 2. and 3. are
    #   2. traffic received in KB
    #   3. traffic sent in KB
    regex = 'monthly_history = \[\n(.+?)\];'
    match_object = re.compile(regex).search(html)
    if match_object is not None:
        try:
            array = ast.literal_eval('[%s]' % match_object.group(1))
            kb_recv, kb_sent = 0, 0
            for time_data, recv, sent in array:
                kb_recv += recv
                kb_sent += sent
            return TrafficStats(kb_recv * 1024, kb_sent * 1024, 0, 0)
        except (KeyError, ValueError):
            raise RouterParseError('Cannot parse traffic stats!')
    return TrafficStats(0, 0, 0, 0)
Esempio n. 6
0
def _parse_traffic_stats(html):
    # Sadly, we can only get packets count information.. no size stats available

    regex = re.compile('WAN</span>(?:.+?)([0-9]+)</span>(?:.+?)([0-9]+)</span>', re.DOTALL)
    match_object = regex.search(html)
    if match_object is None:
        raise RouterParseError('Cannot find traffic stats information')

    packets_sent, packets_recv = map(int, match_object.groups())

    return TrafficStats(0, 0, packets_recv, packets_sent)
Esempio n. 7
0
def _parse_traffic_stats(contents):
    regex = "Ethernet WAN(?:.+?)Sent Packets(?:.+?)<font size=2>([0-9]+)</td>(?:.+?)Received Packets(?:.+?)<font size=2>([0-9]+)</td>"
    regex_traffic_stats = re.compile(regex, re.DOTALL)

    match_object = regex_traffic_stats.search(contents)
    if match_object is None:
        raise RouterParseError("Cannot _parse traffic stats")

    packets_recv, packets_sent = map(int, match_object.groups())
    # sadly, we've got only packets and no size information..
    return TrafficStats(0, 0, packets_recv, packets_sent)
Esempio n. 8
0
 def get_traffic_stats(self):
     # This router doesn't report traffic statistics
     return TrafficStats(0, 0, 0, 0)