void test_format_welf(void) { assert_template_format("$(format-welf MSG=$MSG)", "MSG=árvíztűrőtükörfúrógép"); assert_template_format("$(format-welf MSG=$escaping)", "MSG=\"binary stuff follows \\\"\\xad árvíztűrőtükörfúrógép\""); assert_template_format_with_context("$(format-welf MSG=$MSG)", "MSG=árvíztűrőtükörfúrógép MSG=árvíztűrőtükörfúrógép"); }
void test_format_json_with_type_hints(void) { assert_template_format("$(format-json i32=int32(1234))", "{\"i32\":1234}"); assert_template_format("$(format-json \"i=ifoo(\")", "{\"i\":\"ifoo(\"}"); assert_template_format("$(format-json b=boolean(TRUE))", "{\"b\":true}"); }
void test_numeric_funcs(void) { assert_template_format("$(+ $FACILITY_NUM 1)", "20"); assert_template_format("$(+ -1 -1)", "-2"); assert_template_format("$(- $FACILITY_NUM 1)", "18"); assert_template_format("$(- $FACILITY_NUM 20)", "-1"); assert_template_format("$(* $FACILITY_NUM 2)", "38"); assert_template_format("$(/ $FACILITY_NUM 2)", "9"); assert_template_format("$(% $FACILITY_NUM 3)", "1"); assert_template_format("$(/ $FACILITY_NUM 0)", "NaN"); assert_template_format("$(% $FACILITY_NUM 0)", "NaN"); assert_template_format("$(+ foo bar)", "NaN"); }
void test_format_json_key(void) { assert_template_format("$(format-json --key PID)", "{\"PID\":\"23323\"}"); assert_template_format("$(format-json --key HOST)", "{\"HOST\":\"bzorp\"}"); assert_template_format("$(format-json --key MESSAGE)", "{\"MESSAGE\":\"árvíztűrőtükörfúrógép\"}"); assert_template_format("$(format-json --key HOST --key MESSAGE)", "{\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\"}"); assert_template_format("$(format-json --scope selected-macros --key MSG)", "{\"TAGS\":\"alma,korte,citrom\",\"SOURCEIP\":\"10.11.12.13\",\"SEQNUM\":\"999\",\"PROGRAM\":\"syslog-ng\",\"PRIORITY\":\"err\",\"PID\":\"23323\",\"MSG\":\"árvíztűrőtükörfúrógép\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\",\"FACILITY\":\"local3\",\"DATE\":\"Feb 11 10:34:56\"}"); assert_template_format("$(format-json --key MSG)", "{\"MSG\":\"árvíztűrőtükörfúrógép\"}"); assert_template_format("$(format-json --key DATE)", "{\"DATE\":\"Feb 11 10:34:56\"}"); assert_template_format("$(format-json --key PRI)", "{\"PRI\":\"155\"}"); }
void test_hash(void) { assert_template_format("$(sha1 foo)", "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"); assert_template_format("$(sha1 bar)", "62cdb7020ff920e5aa642c3d4066950dd1f01f4d"); assert_template_format("$(md5 foo)", "acbd18db4cc2f85cedef654fccc4a4d8"); assert_template_format("$(hash foo)", "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"); assert_template_format("$(md4 foo)", "0ac6700c491d70fb8650940b1ca1e4b2"); assert_template_format("$(sha256 foo)", "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"); assert_template_format("$(sha512 foo)", "f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7"); assert_template_failure("$(sha1)", "$(hash) parsing failed, invalid number of arguments"); assert_template_format("$(sha1 --length 5 foo)", "0beec"); assert_template_format("$(sha1 -l 5 foo)", "0beec"); assert_template_failure("$(sha1 --length 5)", "$(hash) parsing failed, invalid number of arguments"); assert_template_failure("$(sha1 --length invalid_length_specification foo)", "Cannot parse integer value 'invalid_length_specification' for --length"); assert_template_format("$(sha1 --length 99999 foo)", "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"); assert_template_format("$(sha1 foo bar)", "8843d7f92416211de9ebb963ff4ce28125932878"); assert_template_format("$(sha1 \"foo bar\")", "3773dea65156909838fa6c22825cafe090ff8030"); assert_template_format("$(md5 $(sha1 foo) bar)", "196894290a831b2d2755c8de22619a97"); }
void test_str_funcs(void) { assert_template_format("$(ipv4-to-int $SOURCEIP)", "168496141"); assert_template_format("$(length $HOST $PID)", "5 5"); assert_template_format("$(length $HOST)", "5"); assert_template_format("$(length)", ""); assert_template_format("$(substr $HOST 1 3)", "zor"); assert_template_format("$(substr $HOST 1)", "zorp"); assert_template_format("$(substr $HOST -1)", "p"); assert_template_format("$(substr $HOST -2 1)", "r"); assert_template_format("$(strip ${APP.STRIP1})", "value"); assert_template_format("$(strip ${APP.STRIP2})", "value"); assert_template_format("$(strip ${APP.STRIP3})", "value"); assert_template_format("$(strip ${APP.STRIP4})", "value"); assert_template_format("$(strip ${APP.STRIP5})", ""); assert_template_format("$(strip ${APP.STRIP1} ${APP.STRIP2} ${APP.STRIP3} ${APP.STRIP4} ${APP.STRIP5})", "value value value value "); assert_template_format("$(sanitize alma/bela)", "alma_bela"); assert_template_format("$(sanitize -r @ alma/bela)", "alma@bela"); assert_template_format("$(sanitize -i @ alma@bela)", "alma_bela"); assert_template_format("$(sanitize -i '@/l ' alma@/bela)", "a_ma__be_a"); assert_template_format("$(sanitize alma\x1b_bela)", "alma__bela"); assert_template_format("$(sanitize -C alma\x1b_bela)", "alma\x1b_bela"); assert_template_format("$(sanitize $HOST $PROGRAM)", "bzorp/syslog-ng"); assert_template_format("$(indent-multi-line 'foo\nbar')", "foo\n\tbar"); }
void test_format_json_on_error(void) { configuration->template_options.on_error = ON_ERROR_DROP_MESSAGE | ON_ERROR_SILENT; assert_template_format("$(format-json x=y bad=boolean(blah) foo=bar)", ""); assert_template_format("$(format-json x=y bad=int32(blah) foo=bar)", ""); assert_template_format("$(format-json x=y bad=int64(blah) foo=bar)", ""); configuration->template_options.on_error = ON_ERROR_DROP_PROPERTY | ON_ERROR_SILENT; assert_template_format("$(format-json x=y bad=boolean(blah) foo=bar)", "{\"x\":\"y\",\"foo\":\"bar\"}"); assert_template_format("$(format-json x=y bad=boolean(blah))", "{\"x\":\"y\"}"); assert_template_format("$(format-json x=y bad=int32(blah))", "{\"x\":\"y\"}"); assert_template_format("$(format-json x=y bad=int64(blah))", "{\"x\":\"y\"}"); configuration->template_options.on_error = ON_ERROR_FALLBACK_TO_STRING | ON_ERROR_SILENT; assert_template_format("$(format-json x=y bad=boolean(blah) foo=bar)", "{\"x\":\"y\",\"foo\":\"bar\",\"bad\":\"blah\"}"); assert_template_format("$(format-json x=y bad=boolean(blah))", "{\"x\":\"y\",\"bad\":\"blah\"}"); assert_template_format("$(format-json x=y bad=int32(blah))", "{\"x\":\"y\",\"bad\":\"blah\"}"); assert_template_format("$(format-json x=y bad=int64(blah))", "{\"x\":\"y\",\"bad\":\"blah\"}"); }
void test_format_json_rekey(void) { assert_template_format("$(format-json .msg.text=dotted --rekey .* --shift 1 --add-prefix _)", "{\"_msg\":{\"text\":\"dotted\"}}"); }
void test_format_json(void) { assert_template_format("$(format-json MSG=$MSG)", "{\"MSG\":\"árvíztűrőtükörfúrógép\"}"); assert_template_format("$(format-json MSG=$escaping)", "{\"MSG\":\"binary stuff follows \\\"\\\\xad árvíztűrőtükörfúrógép\"}"); assert_template_format_with_context("$(format-json MSG=$MSG)", "{\"MSG\":\"árvíztűrőtükörfúrógép\"}{\"MSG\":\"árvíztűrőtükörfúrógép\"}"); assert_template_format("$(format-json --scope rfc3164)", "{\"PROGRAM\":\"syslog-ng\",\"PRIORITY\":\"err\",\"PID\":\"23323\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\",\"FACILITY\":\"local3\",\"DATE\":\"Feb 11 10:34:56\"}"); assert_template_format("$(format-json msg.text=$MSG msg.id=42 host=bzorp)", "{\"msg\":{\"text\":\"árvíztűrőtükörfúrógép\",\"id\":\"42\"},\"host\":\"bzorp\"}"); assert_template_format("$(format-json msg.text.str=$MSG msg.text.len=42 msg.id=42 host=bzorp)", "{\"msg\":{\"text\":{\"str\":\"árvíztűrőtükörfúrógép\",\"len\":\"42\"},\"id\":\"42\"},\"host\":\"bzorp\"}"); assert_template_format("$(format-json kernel.SUBSYSTEM=pci kernel.DEVICE.type=pci kernel.DEVICE.name=0000:02:00.0 MSGID=801 MESSAGE=test)", "{\"kernel\":{\"SUBSYSTEM\":\"pci\",\"DEVICE\":{\"type\":\"pci\",\"name\":\"0000:02:00.0\"}},\"MSGID\":\"801\",\"MESSAGE\":\"test\"}"); assert_template_format("$(format-json .foo=bar)", "{\"_foo\":\"bar\"}"); assert_template_format("$(format-json --scope rfc3164,rfc3164)", "{\"PROGRAM\":\"syslog-ng\",\"PRIORITY\":\"err\",\"PID\":\"23323\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\",\"FACILITY\":\"local3\",\"DATE\":\"Feb 11 10:34:56\"}"); assert_template_format("$(format-json [email protected]=\"pear\" [email protected]=\"good\")", "{\"sdata\":{\"[email protected]\":{\"taste\":\"good\",\"fruit\":\"pear\"}}}"); assert_template_format("$(format-json --scope selected_macros)", "{\"TAGS\":\"alma,korte,citrom\",\"SOURCEIP\":\"10.11.12.13\",\"SEQNUM\":\"999\",\"PROGRAM\":\"syslog-ng\",\"PRIORITY\":\"err\",\"PID\":\"23323\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\",\"FACILITY\":\"local3\",\"DATE\":\"Feb 11 10:34:56\"}"); assert_template_format("$(format-json --scope rfc3164 --key *.*)", "{\"_unix\":{\"uid\":\"1000\",\"gid\":\"1000\",\"cmd\":\"command\"},\"_json\":{\"sub\":{\"value2\":\"subvalue2\",\"value1\":\"subvalue1\"},\"foo\":\"bar\"},\"PROGRAM\":\"syslog-ng\",\"PRIORITY\":\"err\",\"PID\":\"23323\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\",\"FACILITY\":\"local3\",\"DATE\":\"Feb 11 10:34:56\",\"APP\":{\"VALUE\":\"value\",\"STRIP4\":\"value\",\"STRIP3\":\" value \",\"STRIP2\":\"value \",\"STRIP1\":\" value\",\"QVALUE\":\"\\\"value\\\"\"}}"); assert_template_format("$(format-json --scope syslog-proto)", "{\"PROGRAM\":\"syslog-ng\",\"PRIORITY\":\"err\",\"PID\":\"23323\",\"MESSAGE\":\"árvíztűrőtükörfúrógép\",\"HOST\":\"bzorp\",\"FACILITY\":\"local3\",\"DATE\":\"Feb 11 10:34:56\"}"); }