smartinspectpython.sioptionsparser
Module: sioptionsparser.py
Revision History
Date | Version | Description |
---|---|---|
2023/09/27 | 3.0.21.0 | Updated documentation sample code and examples. |
2023/05/30 | 3.0.0.0 | Initial Version. |
Responsible for parsing the options part of a SmartInspect connections string.
This class offers a single method only, called Parse, which is responsible for parsing the options part of a connections string. This method informs the caller about found options by raising the OptionFound event.
Threadsafety:
This class is not guaranteed to be thread-safe.
Event raised when an option key=value pair has been found.
Parses the options part of a connections string.
Arguments:
- protocol (str): The related protocol. Not allowed to be null.
- options (str): The options to parse. Not allowed to be null.
Raises:
- SIArgumentNullException: The protocol or options argument is null.
- SmartInspectException: Invalid options string syntax.
This method parses the supplied options part of a connections string and informs the caller about found options via the OptionFound event.
For information about the correct syntax of the options, please refer to the documentation of the SIProtocol.Options property.
Sample Code
# package imports.
from smartinspectpython.sioptionsparser import SIOptionsParser
from smartinspectpython.sioptionfoundeventargs import SIOptionFoundEventArgs
print("Test Script Starting.\n")
def AddOption(sender:object, args:SIOptionFoundEventArgs):
print("Protocol Option Found: {0}".format(str(args)))
# create parser class and wire up events.
parser:SIOptionsParser = SIOptionsParser()
parser.OptionFoundEvent += AddOption
parser.Parse("tcp", 'host=localhost, port=4228, timeout=30000, reconnect=true, reconnect.interval=10s, async.enabled=false')
print("")
parser.Parse("tcp", "host=thlucasi9.netlucas.com,port=4228,timeout=30000")
print("")
parser.Parse("pipe", "pipename=smartinspect,reconnect=true,reconnect.interval=5s,async.enabled=true")
print("")
parser.Parse("file", "filename=\"./tests/logfiles/FileProtocol-RotateHourly.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.OptionFoundEvent -= AddOption
print("/nTest Script Ended.")