Pipeline
- class logstash_pipeline_parser.Pipeline(pipeline: str)[source]
- Parameters:
pipeline (str) – The pipeline definition
A class representing the Logstash pipeline.
- add_type(name: str, new_type: type[Any] | Callable[[Any], Any]) Self [source]
- Parameters:
- Return type:
Adds a new type.
For example function:
from logstash_parser import Pipeline Pipeline("").add_type("port", str)
For example class:
from logstash_parser import Pipeline class MyPortType: pass Pipeline("").add_type("port", MyPortType)
Note
Please see Types for more examples.
- classmethod from_file(path: str | Path) Self [source]
- Parameters:
path (str | pathlib.Path) – Path to the file
- Return type:
Instantiates class from a file.
For example from string:
from logstash_parser import Pipeline pipeline = Pipeline.from_file("/some/path/to/pipeline.conf")
Or from Path:
from logstash_parser import Pipeline from pathlib import Path path = Path("/some/path/to/pipeline.conf") pipeline = Pipeline.from_file(path)
- get_types() dict[str, type[Any] | Callable[[Any], Any]] [source]
- Returns:
All names as key and types as value.
- Return type:
Returns all defined types
Predefined types are:
Name
Type/Callable
aggregate_maps_path
cacert
ca_file
client_cert
client_key
database
dictionary_path
jaas_path
jdbc_driver_library
jdbc_password_filepath
json_key_file
kerberos_config
keystore
mib_paths
network_path
path
private_key
processed_db_path
public_key
schema_registry_ssl_keystore_location
schema_registry_ssl_truststore_location
send_nsca_config
ssl_cacert
ssl_cert
ssl_certificate
ssl_certificate_path
ssl_key
ssl_keystore_location
ssl_keystore_path
ssl_truststore_location
ssl_truststore_path
statement_filepath
template
template_file
truststore
- parse() list [source]
- Returns:
Parsed tree
- Return type:
Create an Abstract syntax tree from the input data. Of course, it is possible to parse all kinds of plugins, conditions and data types.
For example this input:
from logstash_pipeline_parser import Pipeline data = r""" input { beats { host => "0.0.0.0" port => 5044 client_inactivity_timeout => 3600 include_codec_tag => true enrich => [source_metadata, ssl_peer_metadata] ssl => true ssl_key => "/some/path/my.key" id => "input_beats" } } """ ast = Pipeline(data).parse()
will produce this array:
from ipaddress import IPv4Address from pathlib import Path [ ["input",[ ["beats", [ ["host", [IPv4Address("0.0.0.0")]], ["port", [5044]], ["client_inactivity_timeout", [3600]], ["include_codec_tag", [True]], ["enrich", [ ["source_metadata", "ssl_peer_metadata"] ]], ["ssl", [True]], ["ssl_key", [Path("/some/path/my.key")]], ["id", ["input_beats"]] ]] ]] ]
- remove_type(name: str) Self [source]
-
Removes a type
For example function:
from logstash_parser import Pipeline Pipeline("").remove_type("port")
- search(key: str) Generator[tuple[str, Any], None, None] [source]
- Parameters:
key (str) – Key name to search for
- Returns:
Found values in the form tuple[key, value]
- Return type:
collections.abc.Generator[tuple[str, Any], None, None]
Yield the searched keys and their values from the tree. The key can also contain the wildcard *, for example “output.*.hosts” will return (if the pipeline definition contains them):
- ("output.elasticsearch.hosts", ["127.0.0.1:9200","127.0.0.2:9200"]) - ("output.logstash.hosts", "127.0.0.1:9801")
Note
Please see Search for more examples.