smartinspectpython.siconnectionsparser
Module: siconnectionsparser.py
Revision History
Date | Version | Description |
---|---|---|
2023/05/30 | 3.0.0.0 | Initial Version. |
@export
class
SIConnectionsParser:
Responsible for parsing a SmartInspect connections string.
This class offers a single method only, called Parse, which is responsible for parsing a connections string. This method informs the caller about found protocols and connections by raising the ConnectionFoundEvent event.
Threadsafety:
This class is not guaranteed to be thread-safe.
def
Parse(self, connections: str) -> None:
Parses the connections part of a connections string.
Arguments:
- connections (str): The connections to parse. Not allowed to be null.
Raises:
- SIArgumentNullException: The connections argument is null.
- SmartInspectException: Invalid connections string syntax.
This method parses the supplied connections part of a connections string and informs the caller about found connections via the ConnectionFoundEvent event.
For information about the correct syntax of the connections, please refer to the documentation of the SIProtocol.connections property.
View Sample Code
# our package imports.
from smartinspectpython.siconnectionsparser import SIConnectionsParser
from smartinspectpython.siconnectionfoundeventargs import SIConnectionFoundEventArgs
print("Test Script Starting.\n")
def AddConnection(sender:object, args:SIConnectionFoundEventArgs):
print("Connection Found: {0}".format(str(args)))
# create parser class and wire up events.
parser:SIConnectionsParser = SIConnectionsParser()
parser.ConnectionFoundEvent += AddConnection
parser.Parse("tcp(host=thlucasi9.netlucas.com,port=4228,timeout=30000)") # test single protocol
print("")
parser.Parse("tcp(host=thlucasi9.netlucas.com,port=4228,timeout=30000),file(filename=c:\\log.sil,rotate=weekly)") # test multiple protocols
print("")
parser.Parse('pipe(pipename=smartinspect,reconnect=true,reconnect.interval=5s,async.enabled=true)')
print("")
parser.Parse('file(filename=\"./tests/logfiles/FileProtocol-RotateHourlyNoBuffer.sil\", rotate=hourly, maxparts=24, append=true)')
print("")
parser.Parse('file(filename=\"./tests/logfiles/FileProtocol-ENCRYPTTEST.sil\", encrypt=true, key=\"secret\", rotate=none, append=false)')
print("")
parser.Parse('mem(astext=true, indent=true)')
print("")
parser.Parse('mem(astext=true, indent=true, pattern=\"%level% [%timestamp%]: %title%\")')
print("")
parser.Parse('text(filename=\"./tests/logfiles/TextProtocol-RotateHourly.txt\", rotate=hourly, maxparts=24, indent=true, pattern=\"%level% [%timestamp%]: %title%\", append=true)')
print("")
# unwire events.
parser.ConnectionFoundEvent -= AddConnection
print("\nTest Script Ended.")