#!/usr/bin/env python
"""igcollect - FreeBSD Packet Filter

Copyright (c) 2018 InnoGames GmbH
"""

from __future__ import print_function
from argparse import ArgumentParser
from socket import gethostname
from subprocess import check_output
import re
import time


def parse_args():
    parser = ArgumentParser()
    parser.add_argument('--prefix', default='network')
    return parser.parse_args()


def parse_pf_labels():
    # Get pfctl result of "show all labels"
    pfctl_result = check_output(['/sbin/pfctl', '-q', '-sl'])

    label_counters = {}

    # Read all lines
    for line in pfctl_result.splitlines():

        # Split each line by  ' ', this gives is the label name and values
        line_tab = line.split(' ')

        # Cut unnecessary things out of label
        label = line_tab[0].split(':')[0]
        label = re.sub('_pub$', '', label)
        label = re.sub('_loc$', '', label)

        if label not in label_counters:
            label_counters[label] = {}
            label_counters[label]['p_in'] = int(line_tab[4])
            label_counters[label]['b_in'] = int(line_tab[5])
            label_counters[label]['p_out'] = int(line_tab[6])
            label_counters[label]['b_out'] = int(line_tab[7])
        else:
            label_counters[label]['p_in'] += int(line_tab[4])
            label_counters[label]['b_in'] += int(line_tab[5])
            label_counters[label]['p_out'] += int(line_tab[6])
            label_counters[label]['b_out'] += int(line_tab[7])
    return label_counters


def main():
    args = parse_args()
    hostname = gethostname().replace('.', '_')
    now = str(int(time.time()))
    label_counters = parse_pf_labels()
    for label in label_counters:
        for key in (
            ('bytesIn', 'b_in'),
            ('bytesOut', 'b_out'),
            ('pktsIn', 'p_out'),
            ('pktsOut', 'p_out'),
        ):
            print('{}.{}.{}.{} {} {}'.format(
                args.prefix,
                label, hostname, key[0],
                label_counters[label][key[1]],
                now,
            ))


if __name__ == '__main__':
    main()

@@ -233,16 +233,28 @@
 _output%0A
+import json%0A
 import r
@@ -255,16 +255,16 @@
 port re%0A
-
 import t
@@ -560,16 +560,120 @@
 s = %7B%7D%0A%0A
+    known_pools = load_pools()%0A    reverse_pools = %7B v%5B'pf_name'%5D: k for k, v in known_pools.items() %7D%0A%0A
     # Re
@@ -940,33 +940,95 @@
     
-label = re.sub('_pub$', '
+if label.startswith('pool_'):%0A            label = re.sub('(pool_%5B0-9%5D+)_%5B46%5D.*', '%5Cg%3C1%3E
 ', l
@@ -1033,32 +1033,36 @@
  label)%0A        
+  
+  
 label = re.sub('
@@ -1059,31 +1059,43 @@
 = re
-.sub('_loc$', '', label
+verse_pools%5Blabel%5D.replace('.', '_'
 )%0A%0A 
@@ -1678,24 +1678,24 @@
 ine_tab%5B7%5D)%0A
-
     return l
@@ -1710,16 +1710,132 @@
 nters%0A%0A%0A
+def load_pools():%0A    with open('/etc/iglb/iglb.json') as jsonfile:%0A        return json.load(jsonfile)%5B'lbpools'%5D%0A%0A%0A
 def main

Use new LB Pool names