diff options
author | Miloslav Trmač <mitr@redhat.com> | 2012-08-11 09:52:53 +0200 |
---|---|---|
committer | Miloslav Trmač <mitr@redhat.com> | 2012-08-28 10:26:42 +0200 |
commit | 02ea1d97657ed81797e02ef80c7f89195cf82a27 (patch) | |
tree | ec8743360626300e365e8c120e2bdfb7048ad695 | |
parent | f2068e080718f28b98034233ea08b50f3d2ab220 (diff) | |
download | rsyslog-ommongodb.tar.gz rsyslog-ommongodb.tar.xz rsyslog-ommongodb.zip |
These fields are only relevant in field templates (i.e. mongodb): a
field for a non-existent CEE property is not created (instead of being
set to an empty string).
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-rw-r--r-- | doc/property_replacer.html | 4 | ||||
-rw-r--r-- | runtime/msg.c | 8 | ||||
-rw-r--r-- | template.c | 5 | ||||
-rw-r--r-- | template.h | 1 |
4 files changed, 18 insertions, 0 deletions
diff --git a/doc/property_replacer.html b/doc/property_replacer.html index 86a07474..367603b7 100644 --- a/doc/property_replacer.html +++ b/doc/property_replacer.html @@ -486,6 +486,10 @@ Useful for secure pathname generation (with dynafiles). Useful for secure pathname generation (with dynafiles). </td> </tr> +<tr> +<td><b>optional-field</b></td> +<td>In templates that are used for building field lists (in particular, ommongodb), completely remove this field if the corresponding property is not present. Currently implemented only for the <b>$!<name></b> properties.</td> +</tr> </tbody> </table> <p>To use multiple options, simply place them one after each other with a comma delmimiting diff --git a/runtime/msg.c b/runtime/msg.c index 0d01f5e1..0ee78ae0 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -3500,6 +3500,14 @@ rsRetVal MsgAppendFields(msg_t *pMsg, struct templateEntry *pTpe, } } } else { + /* FIXME: this performs a duplicate lookup, which wastes + time. */ + if(pTpe->data.field.options.bOptionalField + && (pMsg->event == NULL + || ee_getEventField(pMsg->event, + pTpe->data.field.propName) == NULL)) + FINALIZE; /* Nothing to do */ + CHKiRet(FBSensureSpace(state)); dst = state->fields + state->nextField; @@ -669,6 +669,8 @@ static void doOptions(unsigned char **pp, struct templateEntry *pTpe) } else { pTpe->data.field.options.bJSONf = 1; } + } else if(!strcmp((char*)Buf, "optional-field")) { + pTpe->data.field.options.bOptionalField = 1; } else { dbgprintf("Invalid field option '%s' specified - ignored.\n", Buf); } @@ -1984,6 +1986,9 @@ void tplPrintList(rsconf_t *conf) if(pTpe->data.field.options.bJSONf) { dbgprintf("[format as JSON field] "); } + if(pTpe->data.field.options.bOptionalField) { + dbgprintf("[optional field - skip in field template if not present] "); + } if(pTpe->data.field.options.bDropLastLF) { dbgprintf("[drop last LF in msg] "); } @@ -114,6 +114,7 @@ struct templateEntry { unsigned bCSV: 1; /* format field in CSV (RFC 4180) format */ unsigned bJSON: 1; /* format field JSON escaped */ unsigned bJSONf: 1; /* format field JSON *field* (n/v pair) */ + unsigned bOptionalField: 1; /* optional field - skip in field template if not present */ } options; /* options as bit fields */ } field; } data; |