Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
case $facts['kernel'] {
'Linux': {
$puppet_bin = '/opt/puppetlabs/bin/puppet'
$fact_upload_params = "facts upload --environment ${environment}"
$fact_upload_params = "facts upload"
$fact_upload_cmd = "${puppet_bin} ${fact_upload_params}"
$cache_dir = '/opt/puppetlabs/log4jscanner'
$scan_script = 'scan_data_generation.sh'
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/log4jscanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
context "on #{os}" do
case os_facts[:kernel]
when 'Linux'
let(:fact_upload_cmd) { '/opt/puppetlabs/bin/puppet facts upload --environment production' }
let(:fact_upload_cmd) { '/opt/puppetlabs/bin/puppet facts upload' }
let(:cache_dir) { '/opt/puppetlabs/log4jscanner' }
let(:scan_script) { 'scan_data_generation.sh' }
let(:scan_script_mode) { '0700' }
Expand Down
14 changes: 13 additions & 1 deletion templates/scan_data_generation.sh.epp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ diff=$(diff -y --suppress-common "${UPDATEFILE}" "${UPDATEFILE}.previous" | wc -
rm -f "${UPDATEFILE}.previous"
if [ "${diff}" != "0" ]; then
logger -p info -t scan_data_generation.sh "Uploading fact"
<%= $puppet_bin %> <%= $fact_upload_params %> 2>/dev/null 1>/dev/null
# Find environment puppet runs in. As it is entirely possible to have puppet agent run by external
# tools calling it - and them always telling puppet in which environment, a simple config print
# for environment can be wrong.
# So we parse the report of the last run and use that.
# In case that fails to parse or does not exist yet, we fall back to asking puppet.
# The awk BEGIN/END part is magic to make awk exit with an error, if match wasn't found (say, empty file).
lastreport=$(puppet config print lastrunreport)
if [ -f "${lastreport}" ]; then
environment=$(awk -F ': ' 'BEGIN { rc=1 } /^environment: / { print $2; rc=0; exit } END { exit rc }' ${lastreport} || puppet config print environment )
else
environment=$(puppet config print environment)
fi
<%= $puppet_bin %> <%= $fact_upload_params %> --environment ${environment} 2>/dev/null 1>/dev/null
fi
logger -p info -t scan_data_generation.sh "Log4jscanner scan data refreshed"

Expand Down