set
2 minute read
This function is used to explicitly set a telemetry field to a specified value, providing flexibility in updating or assigning values within the telemetry data structure.
Syntax: set(target, value)
- Target: A path expression indicating the telemetry field where the value will be set.
- Value: The value to be assigned to the target. This can be of any data type. If the value resolves to
nil(for example, if it references an unset map value), no action will occur.
Input
{
"_type": "log",
"attributes": {
"decoded_body": "User's IP address: 192.168.1.xxx; Action: Login attempt.",
"ip_addresses": "192.168.1.xxx, 10.10.10.10, 172.16.0.1"
},
"body": "User's IP address: 192.168.1.45; Action: Login attempt.",
"resource": {
"ed.conf.id": "123456789",
"ed.domain": "pipeline",
"ed.org.id": "987654321",
"ed.source.name": "Kubernetes Source",
"ed.source.type": "memory_input",
"ed.tag": "loggen",
"host.ip": "10.0.0.1",
"host.name": "ED_TEST",
"service.name": "ed-tester",
"src_type": null
},
"timestamp": 1733439280081
}
Statement
set(attributes["host"], resource["host.ip"])
set(attributes["notes"], "comment")
Output
{
"_type": "log",
"attributes": {
"decoded_body": "User's IP address: 192.168.1.xxx; Action: Login attempt.",
"host": "10.0.0.1",
"ip_addresses": "192.168.1.xxx, 10.10.10.10, 172.16.0.1",
"notes": "comment"
},
"body": "User's IP address: 192.168.1.45; Action: Login attempt.",
"resource": {
"ed.conf.id": "123456789",
"ed.domain": "pipeline",
"ed.org.id": "987654321",
"ed.source.name": "Kubernetes Source",
"ed.source.type": "memory_input",
"ed.tag": "loggen",
"host.ip": "10.0.0.1",
"host.name": "ED_TEST",
"service.name": "ed-tester",
"src_type": null
},
"timestamp": 1733439335943
}
In this example, the host field within the attributes object is set to the value from host.ip in resource. In addition, a second statement adds a static string value to notes in attributes.