Exclude specific IP Address during Python Script Import

Is there a way to specifically exclude an IP address when using the python import script? For example we want to exclude all entries from our monitoring system.

In the Piwik frontend just go Settings - Websites --> Global list of Excluded IPs

You can also specify “Excluded IPs” per site.

These values are taken into account during import as well real-time tracking.

We did it like this.

Constants.

BANNED_IPS = (
‘X.X.X.X’,
‘Y.Y.Y.Y’,
)

In class (at the beginning, first thing to drop):

class Parser(object):
""“
The Parser parses the lines in a specified file and inserts them into
a Queue.
”""

## All check_* methods are called for each hit and must return True if the
## hit can be imported, False otherwise.

def check_ip(self, hit):
    for x in BANNED_IPS:
            if hit.ip.find(x) != -1:
                return False
    return True

You can use it to drop more than one ip - whole class (simplified version)

example
192.168.0. -> this gives you all ip’s from 192.168.0.0 to 192.168.0.255 :slight_smile: