-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppg-push-empty-report
executable file
·50 lines (38 loc) · 1.39 KB
/
ppg-push-empty-report
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
if [[ -n "${PPG_DEBUG}" ]]; then
set -x
fi
pushd /etc/puppet >/dev/null || exit 1
PPG_EXEC_PATH=$( dirname $(readlink -f "${BASH_SOURCE[0]}" ) )
GIT_EXEC_PATH=$(git --exec-path)
GIT_DIR=$(git rev-parse --git-dir)
export GIT_SSH="${PPG_EXEC_PATH}/ppg-ssh"
. ${PPG_EXEC_PATH}/ppg-functions
if [ -z "$GIT_DIR" ]; then
echo >&2 "Not in a git checkout"
exit 1
fi
# puppet.conf syntax is compat with git config syntax
# (both are INI style). How lucky can we be? :-)
report_bool=$(git config -f $PUPPETCONF --bool --get agent.report)
# note: default is true
if [ "$report_bool" = 'false' ]; then
echo >&2 "ERROR: reports are disabled!"
exit 1
fi
hostname=$(xhostname)
reportsdir='/etc/puppet/.ppg/reports'
mkdir -p ${reportsdir}/${hostname}
datestamp=$(date -u --rfc-3339=seconds|sed 's/ /_/')
reportfpath=${reportsdir}/${hostname}/${datestamp}.yaml
tempreport=$(mktemp -t ppg_report_XXXXX.yaml)
# use a tempfile to prevent partially prepared reports
# from making it to the dashboard server
cp ${PPG_EXEC_PATH}/unchanged.report ${tempreport}
report_time=$(echo $(date +"%Y-%m-%d %H:%M:%S.%6N %:z"))
/bin/sed -i "s,REPLACEMEDATESTAMP,${report_time},g" ${tempreport}
/bin/sed -i "s,REPLACEMEHOSTNAME,${hostname},g" ${tempreport}
mv ${tempreport} ${reportfpath}
# cleanup in case we have failures
find ${TMPDIR:/tmp} -xdev -type f -name 'ppg_report*yaml' -delete
exec $PPG_EXEC_PATH/ppg-push-reports