Skip to content

Commit

Permalink
output/file: Fix datasource argument handling in output specification…
Browse files Browse the repository at this point in the history
… (GH #270)
  • Loading branch information
bostjan committed Sep 5, 2024
1 parent 5f4133f commit a546bb6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ int snoopy_configfile_parseValue_output (
outputArg = "";
} else {
// Separate output name from its arguments
// (arguments may contain further ':' characters, like "file:/var/log/snoopy-%{datetime:%Y-%m-%d}")
outputName = strtok_r(confVal, ":", &saveptr1);
outputArg = strtok_r(NULL , ":", &saveptr1);
outputArg = outputName + strlen(outputName) + 1;
outputArgFound = SNOOPY_TRUE;

}

// Determine output name
Expand Down
3 changes: 3 additions & 0 deletions tests/output/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ if OUTPUT_ENABLED_file
if DATASOURCE_ENABLED_username
TESTS += output_file-dynamic.sh
endif
if DATASOURCE_ENABLED_snoopy_literal
TESTS += output_file-dynamic-arg.sh
endif
endif

TESTS += output_noop.sh
Expand Down
33 changes: 33 additions & 0 deletions tests/output/output_file-dynamic-arg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash



### Configure shell and bootstrap
#
set -e
set -u
. `dirname $BASH_SOURCE`/_bootstrap.sh



### Output data
#
VAL_REAL=`date +%s`
MY_PID=$$
MY_USERNAME=`whoami`
FILE_EXPECTED="output_file-dynamic-arg.sh.$MY_PID-asdf.tmp.out"
FILE_FORMAT="output_file-dynamic-arg.sh.$MY_PID-%{snoopy_literal:asdf}.tmp.out"

# Write
rm -f $FILE_EXPECTED
$SNOOPY_TEST_CLI run output "$VAL_REAL" "file" "$FILE_FORMAT" > /dev/null

# Read
VAL_SNOOPY=`cat $FILE_EXPECTED`
rm -f $FILE_EXPECTED



### Evaluate
#
snoopy_test_compareValues "$VAL_SNOOPY" "$VAL_REAL"

0 comments on commit a546bb6

Please sign in to comment.