114 Commits

Author SHA1 Message Date
Rainer Gerhards
15ad71074a
template: add omitIfZero option to property()
Why:
Ensures high-performance JSON emission can comply with ECS (Elastic Common
Schema) requirements where numerical zero values should often be omitted
rather than emitted as '0'.

Impact:
Adds a new property() parameter 'omitIfZero' that affects templates using
format='jsonf' and dataType='number'. No change to existing templates.

Before/After:
Previously, numerical properties in jsonf mode always emitted their value
(e.g., '"field":0'); with this change, they can be completely omitted.

Technical Overview:
- Extended templateEntry options in template.h with bOmitIfZero bitfield.
- Updated template.c to parse the 'omitifzero' binary parameter.
- Implemented omission logic in tplJsonRenderValue (template.c) and
  jsonField (runtime/msg.c).
- Standardized memory safety by using the project-standard CHKmalloc()
  macro for all es_str2cstr() allocations and other memory checks.
- Standardized error handling by replacing explicit gotos with the
  FINALIZE; macro across affected areas.
- Formatted modified files using devtools/format-code.sh for full
  compliance with project style rules.
- Registered tests/json-omitifzero.sh following the "Define at Top,
  Distribute Unconditionally, Register Conditionally" pattern.

Issue: https://github.com/rsyslog/rsyslog/issues/6176

With the help of AI-Agents: Antigravity
2026-01-25 15:02:32 +01:00
Rainer Gerhards
e9d485757f
template: add jsonftree option for nested jsonf output
We want easy nested JSON to match common schemas (e.g., Elastic ECS)
without external processors. This introduces an opt-in mode so existing
jsonf users keep exact behavior while enabling structured output when
requested.

Impact: No change unless option.jsonftree is enabled. With jsonftree,
dotted outnames render as nested objects; empty containers are skipped.
On name collisions (object vs value), we fall back to flat rendering.

Before: jsonf always emitted flat name/value pairs, even for dotted
outnames. After: jsonf remains flat by default; enabling jsonftree makes
"host.hostname" and "host.ip" render as {"host":{"hostname":...,"ip":...}}.

Technically, we add option.jsonftree to templates. When set, we lazily
build a per-template JSON tree (tplJsonNode) from dotted segments and
render it in one pass, reusing existing jsonf formatting for leaves.
The tree state is tracked on the template and freed on template delete.
Config parsing enforces mutual exclusivity among sql, stdsql, json,
jsonf, and jsonftree. Constants record bJSONf to reuse serialized
fragments. Tests cover nested output and pure-json cases using
option.jsonftree.
2025-09-24 18:12:00 +02:00
Rainer Gerhards
b326c76f45 style: normalize C source formatting via clang-format (PoC)
This commit applies the new canonical formatting style using `clang-format` with custom settings (notably 4-space indentation), as part of our shift toward automated formatting normalization.

⚠️ No functional changes are included — only whitespace and layout modifications as produced by `clang-format`.

This change is part of the formatting modernization strategy discussed in:
https://github.com/rsyslog/rsyslog/issues/5747

Key context:
- Formatting is now treated as a disposable view, normalized via tooling.
- The `.clang-format` file defines the canonical style.
- A fixup script (`devtools/format-code.sh`) handles remaining edge cases.
- Formatting commits are added to `.git-blame-ignore-revs` to reduce noise.
- Developers remain free to format code however they prefer locally.
2025-07-16 13:56:21 +02:00
Rainer Gerhards
6c16d84237
Merge pull request #4758 from mbarbon/mbarbon/format-iso-week
add property options to support ISO week/year number
2022-04-01 12:57:31 +02:00
Michael Biebl
6569133c75
Typo fixes (#4801)
* typo fix: ambigious -> ambiguous

* typo fix: aquire -> acquire

* typo fix: assgined -> assigned

* typo fix: cancelation -> cancellation

* typo fix: childs -> children

* typo fix: configuraton -> configuration

* typo fix: delemiter -> delimiter

* typo fix: forwardig -> forwarding

* typo fix: initializiation -> initialization

* typo fix: intializing -> initializing

* typo fix: lengh -> length

* typo fix: mesage -> message

* typo fix: occured -> occurred

* typo fix: occurence -> occurrence

* typo fix: paramter -> parameter

* typo fix: remaing -> remaining

* typo fix: resetted -> reset

* typo fix: suppored -> supported

* typo fix: Sytem -> System

* typo fix: uncommited -> uncommitted

* typo fix: depricated -> deprecated

* typo fix: stoping -> stopping

* type fix: allow to -> allow one to
2022-02-17 10:54:12 +01:00
Mattia Barbon
a11ad1a451 add property options to support ISO week/year number 2021-12-28 10:35:59 +01:00
Rainer Gerhards
602d6b1a9f
template: add datatype template option for JSON generation
The new "datatype" and "onEmpty"  template options permits to
generate non-string data rather easily. It works together with
jsonf formatting, which is what people should use nowadays.

closes https://github.com/rsyslog/rsyslog/issues/2827
2019-05-16 15:49:45 +02:00
Rainer Gerhards
223c03e536
cleanup: remove commented-out code
thanks to lgtm.com for the ability to detect commented out code!
2018-10-27 19:04:30 +02:00
Rainer Gerhards
26db406974
cleanup: remove no longer needed code
array mode templates are no longer supported

If they are needed again, check v7 for importing code
2018-09-26 18:55:31 +02:00
PascalWithopf
c83e3ed216 correct codestyle in rsyslog part 2 2018-08-01 16:11:33 +02:00
PascalWithopf
19133327cc correct codestyle in rsyslog 2018-07-31 09:44:27 +02:00
Rainer Gerhards
93bebb1f1f template: add option to generate json "container"
This enables easy JSON generation via template.

This commit also corrects an issue with the constant "jsonf"
format. That was recently added, and the implementation problem
only became visible when used inside a larger json object. No
officially released code is affected, thought - so it rellay
is just a side-note.

closes https://github.com/rsyslog/rsyslog/issues/2347
2018-02-16 08:22:49 +01:00
PascalWithopf
29c9fb1f9a codestyle: reduce line length to 120
lines are still checked for a length of 125 because
these are just some of the lines
2017-12-21 17:09:32 +01:00
PascalWithopf
e485c5c5bc codestyle: shorten lines to max 130 chars 2017-11-15 09:04:42 +01:00
Rainer Gerhards
8d67c03d45 solaris: fix coding issues 2017-04-11 10:18:42 +02:00
purnima
d45daa2af0 Rebase,redefine msgDestruct() as smsg_t is used 2016-11-22 14:24:25 +05:30
Rainer Gerhards
5e3b075d53 fix compiler warnings 2016-06-02 12:08:55 +02:00
Rainer Gerhards
17553f5195 cleanup: compiler warnings 2016-06-01 09:49:46 +02:00
Rainer Gerhards
43fad84a45 templates: add new option "compressspace"
closes https://github.com/rsyslog/rsyslog/issues/861
2016-03-23 17:05:34 +01:00
Rainer Gerhards
0ab2ba2ff2 add template option "date-utc" to emit time in UTC
closes https://github.com/rsyslog/rsyslog/issues/730
2016-03-22 12:27:39 +01:00
Peter Portante
84f5608157 Fix upper and mixed case variable references
We could not reference mixed or upper case variables properly prior to
this change, as they were always lowercased before references were
pulled.

The new "option.casesensitive" for templates allows folks to turn on
variable name reference case sensitivity on a template by template
basis.
2015-12-19 16:17:11 +00:00
Jonny Törnbom
f3bd7a2f5e Add fixed-width option
Pads a string with spaces up to toChar field if string is shorter, if
string is equal then nothing is done and if string is longer then it
gets truncated.
2015-09-07 15:13:00 +02:00
RJ Bergeron
32de3f6741 Now that we have the ordinal day, we can easily get the week of the year. Expose that. 2014-08-05 11:37:50 -04:00
RJ Bergeron
6d90af8739 Add support for day-of-year (ordinal day) time formatting 2014-08-05 11:37:20 -04:00
Rainer Gerhards
e3bcf3f0e8 add date-wday template option to complete date-related set
Was not requested, but makes sense to support it.
See also: https://github.com/rsyslog/rsyslog/issues/65
2014-04-30 11:47:47 +02:00
Rainer Gerhards
0ac1ce59dd add remaining template options for date extraction
see also: https://github.com/rsyslog/rsyslog/issues/65
2014-04-30 11:20:07 +02:00
Rainer Gerhards
25e8881d95 add date-wdayname property modifier
see also: https://github.com/rsyslog/rsyslog/issues/65
2014-04-29 13:13:51 +02:00
Nate Brown
1cd1ace0ff Adding two new format types to import raw json strings as is 2014-01-24 16:39:29 -08:00
Rainer Gerhards
94729cd9f9 refactor ExtendBuf() interface for iparams 2013-12-06 10:03:32 +01:00
Rainer Gerhards
01de5afe83 refactor strgen interface once again
as this provides more flexibility and potentially better performance. We
try to squeueze all interface changes into as early an release as
possible.
2013-12-06 09:52:03 +01:00
Rainer Gerhards
4695ab7c3e refactor output system string handling 2013-12-04 16:49:22 +01:00
Rainer Gerhards
69752635d2 refactor strgen interface 2013-12-04 11:55:36 +01:00
Rainer Gerhards
fb6dd02afc refactor milestone: create first PoC of commitTransaction() entry point 2013-12-04 11:38:07 +01:00
Rainer Gerhards
c0f4474389 refactor get.*PropVal() series of functions 2013-10-23 15:12:30 +02:00
Rainer Gerhards
7d39740b3d refactor: use common code for message property description processing
in all cases except script var access -- this comes next...
2013-10-22 17:55:35 +02:00
Rainer Gerhards
f4f2a493b0 work a bit toward string handling unification 2013-10-21 17:12:07 +02:00
hwoarang
1c71b9628b make rsyslog use the new json-c pkgconfig file if available 2013-09-03 11:38:01 +02:00
Rainer Gerhards
7b45d0b4d2 Merge branch 'v7-stable-info'
Conflicts:
	ChangeLog
	template.c
2013-03-29 16:09:19 +01:00
Rainer Gerhards
474877b9d7 permit substring extraction relative to end-of-string in templates 2013-03-29 16:04:21 +01:00
Rainer Gerhards
3421209cd5 optimize property replacer: reduce runtime for simple processing 2012-10-11 11:33:16 +02:00
Rainer Gerhards
f85690620b do "template date call" only when actually needed 2012-10-11 09:12:20 +02:00
Rainer Gerhards
dc724fcd2e optimize: do "template time() call" only once per batch
This still needs more optimizing as the call is very often
NOT needed - but we need to know about the templates in that
case.
2012-10-10 19:34:08 +02:00
Rainer Gerhards
037eaa0d69 new ruleengine: implement template type "subtree" 2012-09-18 11:32:45 +02:00
Rainer Gerhards
4bb35f1e94 Add missing prototype for tplToJSON() 2012-09-10 18:40:42 +02:00
Rainer Gerhards
0426ad7dd2 switch field default to "mandatory" and implement that mode 2012-08-30 18:56:23 +02:00
Miloslav Trmač
a73058031f Add support for optional fields 2012-08-29 16:07:23 +02:00
Rainer Gerhards
d18a93e943 default outname for $!<property> is now without $! prefix
also some type cleanup and simplification
2012-08-29 16:00:20 +02:00
Rainer Gerhards
3d56820f13 add capability to configure outname for constant (inside template)
also some cleanup
2012-08-25 19:21:12 +02:00
Rainer Gerhards
00c4f69c55 milestone: LIST-type templates support full option set 2012-08-25 19:08:07 +02:00
Rainer Gerhards
27a0078958 Merge branch 'master' into master-newtemplate 2012-08-25 12:27:06 +02:00