summaryrefslogtreecommitdiffstats
path: root/source/rainerscript/functions/rs-get_property.rst
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:27:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:27:18 +0000
commitf7f20c3f5e0be02585741f5f54d198689ccd7866 (patch)
tree190d5e080f6cbcc40560b0ceaccfd883cb3faa01 /source/rainerscript/functions/rs-get_property.rst
parentInitial commit. (diff)
downloadrsyslog-doc-f7f20c3f5e0be02585741f5f54d198689ccd7866.tar.xz
rsyslog-doc-f7f20c3f5e0be02585741f5f54d198689ccd7866.zip
Adding upstream version 8.2402.0+dfsg.upstream/8.2402.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'source/rainerscript/functions/rs-get_property.rst')
-rw-r--r--source/rainerscript/functions/rs-get_property.rst58
1 files changed, 58 insertions, 0 deletions
diff --git a/source/rainerscript/functions/rs-get_property.rst b/source/rainerscript/functions/rs-get_property.rst
new file mode 100644
index 0000000..a1536fa
--- /dev/null
+++ b/source/rainerscript/functions/rs-get_property.rst
@@ -0,0 +1,58 @@
+**************
+get_property()
+**************
+
+Purpose
+========
+
+get_property(rsyslog_variable, key_str)
+
+Provides ability to get a rsyslog variable or property using dynamically evaluated parameters.
+The first parameter is a valid rsyslog variable or property, the second parameter is a key string, or index value.
+
+
+Example
+========
+
+In the following example, a json string is parsed using parse_json(), and placed into the variable ``$!parsed``.
+The get_property function is then used to get property fields from ``$!parsed``.
+
+.. code-block:: none
+
+ set $.ret = parse_json("{\"offsets\": [ { \"a\": 9, \"b\": 0 },\
+ { \"a\": 9, \"b\": 3 } ],\
+ \"boolval\": true,\
+ \"int64val\": 1234567890,\
+ \"nullval\": null,\
+ \"doubleval\": 12345.67890 }", "\$!parsed");
+
+ # get different fields from $!parsed here
+ if $.ret == 0 then {
+ # dynamically evaluate different fields in $!parsed
+
+ # do dynamic indexing into array
+ $.index = 1;
+ # set $.ret = { "a": 9, "b": 3}
+ set $.ret = get_property($!parsed!offsets, $.index);
+
+ # set $.ret = true;
+ set $.key = "boolval";
+ set $.ret = get_property($!parsed, $.key);
+
+ # null values are evaluated to empty string
+ # thus below statement will set $.ret to empty string
+ set $.ret = get_property($!parsed, "nullval");
+
+ # evaluates to 1234567890
+ set $.key = "int64val";
+ set $.ret = get_property($!parsed, $.key);
+
+ # using a key variable, evaluates to 12345.67890
+ set $key = "doubleval";
+ set $.ret = get_property($!parsed, $key);
+ }
+
+ # example of dynamically building key value
+ set $.foo!barval = 3;
+ # set $.bar = 3;
+ set $.bar = get_property($.foo, "bar" & "val");