This module contains functionality for reading the connection log from the PacketLogic system.
Do NOT import this module directly. The PLConnection object should be used, e.g:
>>> import packetlogic2 >>> pl = packetlogic2.connect("192.168.1.25", "admin", "password") >>> cl = pl.ConnLog()
This resource will allow you to search the connectionlog (if enabled in the system).
Methods: | ||
---|---|---|
Ungrouped | list_services(self, day) List all services seen on specified day |
|
list of dict
|
search(self, timefr, timeto, server=None, serverport=None, client=None, clientport=None, service=None, serverhostname=None, protocol=None, endtimefr=None, endtimeto=None, netobject=None, natclient=None, natclientport=None, natserver=None, natserverport=None, max_hits=50, offset=0, callback=None) Search the connection log with parameters |
|
Inherited from Resource | close(self) Immediately disconnects the resource |
|
commit(self, message='PythonAPI commit') Store the current transaction to the database |
||
ping(self, string='') Send a command to server to test if it is up |
||
tuple of (str , int )
|
protocol(self, protocol, strict=False) Translate protocol name OR number to tuple with name AND number |
|
dict of str :int and
int :str
|
protocols_dict(self) Returns a dictionary with name:nr and nr:name items for IP protocols |
|
rollback(self) Abort the current transaction and discard the data |
||
services_cmd(self, services=[], props=[]) Send services to pldbd |
||
list of str
|
services_list(self) List all services |
|
list of str
|
services_prop_list(self) List all properties |
|
wait_for_commit(self, pinginterval=60) Wait for new data to be committed on resource |
||
list of str
|
xfb_flags_list(self) List all XFB (Transfer Behaviour) flags, that can be used in FlagObjects |
Properties: | |
---|---|
commitid | The CommitID associated with this session |
Immediately disconnects the resource.
After this method has been called this object becomes useless.
It may be used to force a disconnect when the garbage collector can't be trusted to do a timely disconnect.
Store the current transaction to the database.
When you do this PacketLogic will reload the ruleset. This will take a lot of CPU resources from the system, try to do this in batches.
Observe that if you don't commit the changes you've made, no other resource (including the client) will see your changes.
str
) - Message recorded in the commit log. Ignored in v12.1 and earlier.
List all services seen on specified day.
>>> cl.list_services("2009-12-24") ['Diablo 2', 'HTTP', 'Microsoft Online Crash Analysis', 'World of Warcraft login', 'Flash audio over HTTP', 'OCSP over HTTP', 'Internet Key Exchange', 'HTTP media stream', 'IMAP4']
Send a command to server to test if it is up.
Translate protocol name OR number to tuple with name AND number. Can be used to e.g translate numerical protocol in connlog.search() result to protocol name.
An unknown protocol will be translated to e.g '#7' or -1, unless strict is set to True, in which case ValueError is raised for unknown protocols.
tuple
of (str
, int
)
int
, str
or a ProtocolObject
Item) - Name or number of an IP protocol
bool
) - If True
, ValueError is raised for an unknown protocol, if
False
(default), an unknown protocol translates to number -1
or name '#7' (where 7 is the supplied unknown protocol number).
Returns a dictionary with name:nr and nr:name items for IP protocols. Can be used to e.g translate numerical protocol in connlog.search() result to protocol name.
dict
of str
:int
and
int
:str
Abort the current transaction and discard the data.
This will also automatically happen if your connection drops or that you exit the program without commit.
Search the connection log with parameters. All parameters except timefr and timeto can be omitted, which will evaluate to "any". You must specify at least one other search criteria though.
Time is specified as the local time on the PacketLogic system. The 'time' item in the returned dictionary is a unix timestamp adjusted for the timezone on the PacketLogic system, to get a python timetuple representing the PacketLogic systems local time convert it (despite the misleading function name) with: pl_local_time_tuple = time.gmtime(connlog_data['time'])
>>> cl.search("2005-12-19 10:00", "2005-12-20 12:04", service="http", max_hits=3) [{'client': '10.2.20.75', 'client_port': 3429, 'protocol': 6, 'server': '194.14.70.50', 'server_port': 80, 'serverhostname': 'www.svt.se', 'service': 'http', 'time': 1135033194}, {'client': '10.2.95.71', 'client_port': 1958, 'protocol': 6, 'server': '70.85.224.194', 'server_port': 80, 'serverhostname': 'www.dumpalink.com', 'service': 'http', 'time': 1135033194}, {'client': '10.2.20.75', 'client_port': 3430, 'protocol': 6, 'server': '194.14.70.50', 'server_port': 80, 'serverhostname': 'www.svt.se', 'service': 'http', 'time': 1135033194}]
list
of dict
str
or datetime.date or datetime.datetime) - Search for connections beginning at specified date or later. The date has
to be in YYYY-MM-DD HH:MM or YYYY-MM-DD format, time default
to 00:00.
str
or datetime.date or datetime.datetime) - Search for connections beginning at specified date or earlier. The date
has to be in YYYY-MM-DD HH:MM or YYYY-MM-DD format, time
default to 00:00.
str
or datetime.date or datetime.datetime) - Search for connections ending at specified date or later. The date has to
be in YYYY-MM-DD HH:MM or YYYY-MM-DD format, time default to
00:00. Requires firmware v12.2 or newer.
str
or datetime.date or datetime.datetime) - Search for connections ending at specified date or earlier. The date has
to be in YYYY-MM-DD HH:MM or YYYY-MM-DD format, time default
to 00:00. Requires firmware v12.2 or newer.
str
) - The servers ip address.
int
) - The server port.
str
) - The clients ip address
int
) - client port.
str
) - a string with the name of the service (e.g. FTP or FTP
transfer)
str
) - the hostname of the server, this only works on protocols where the
serverhostname is extractedlike HTTP.
int
) - The IP protocol used. (6=TCP)
str
) - Visible netobject that the local host of the connection appeared in.
Requires firmware v12.2 or newer.
str
) - The servers post NAT ip address. Requires firmware v15.0 or newer.
int
) - The servers post NAT port. Requires firmware v15.0 or newer.
str
) - The clients post NAT ip address Requires firmware v15.0 or newer.
int
) - The clients post NAT port. Requires firmware v15.0 or newer.
int
) - Number of answers you want.
int
) - Start on this number of answers .. (i.e. if you set max_hits to 50 and
offset to 50 you will get answers between 50 and 100)
callable
) - Optional function to be called for each chunk of data received instead of
returning a list.
Send services to pldbd
Sets stringtable for services and properties. Do NOT use this unless you know exactly what you are doing.
list
of str
) - List of services
list
of str
) - List of service properties
Wait for new data to be committed on resource.
This method returns as soon as the server signals that another client has committed new data to the resource. It also periodically tests the connection to the server. If connection is broken (or any other error happens) an exception is raised.
List all XFB (Transfer Behaviour) flags, that can be used in FlagObjects.
list
of str
The CommitID associated with this session. (14.0 or newer only)