evtctxsetvar()
Sets a user variable in an event context. Returns true if the variable is set successfully, or false if it fails.
Syntax
evtctxsetvar(TOPIC, KEY, VAR_NAME, VALUE[, HOST])
Parameters
TOPIC- The topic name of the event context. String.
KEY- The key value of the event context. String.
VAR_NAME- The name of the variable to set. String.
VALUE- The value to store in the variable.
HOST- (Optional) The hostname to which the event context belongs. If omitted, the default host is searched.
Description
The function identifies the event context using TOPIC and KEY, then stores VALUE under the name VAR_NAME. Returns true (boolean) on success.
If TOPIC or KEY is null, false is returned. If VAR_NAME is null, false is returned. If VALUE is null, the variable is set with a null value.
Variables set with this function can be retrieved using the evtctxgetvar() function.
Error codes
| Error code | Description |
|---|---|
invalid-evtctxsetvar-arguments | The number of arguments is not 4 or 5. |
Usage examples
-
Set the
last_ipvariable in the event context for each user in thelogin_failtopicevtctx topic=login_fail key=src_user | eval ok = evtctxsetvar("login_fail", src_user, "last_ip", src_ip) -
Set a variable and then retrieve it with
evtctxgetvar()evtctx topic=login_fail key=src_user | eval ok = evtctxsetvar("login_fail", src_user, "score", risk_score) | eval stored = evtctxgetvar("login_fail", src_user, "score") -
TOPICisnullevtctx topic=login_fail key=src_user | eval ok = evtctxsetvar(null, src_user, "last_ip", src_ip) | # ok: false
Compatibility
evtctxsetvar() has been available since before Sonar 4.0.