forked from theforeman/foreman
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend-fixture-report
executable file
·64 lines (60 loc) · 1.22 KB
/
send-fixture-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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
BASEDIR=$(dirname $0)
URL=${URL:-http://localhost:5000}
HOST=report.example.com
TMP=/tmp/$(basename $0).tmp
usage() {
echo "Usage:"
echo " $0 -h Display this help message"
echo " $0 -u URL Foreman URL ($URL)"
echo " $0 -o HOSTNAME Hostname ($HOST)"
echo " $0 -f FILE Fixture to upload"
echo " $0 -a Upload all fixtures"
}
while getopts "haf:u:o:" opt; do
case ${opt} in
u )
URL=$OPTARG
;;
f )
FILE=$OPTARG
;;
o )
HOST=$OPTARG
;;
a )
ALL=1
;;
h )
usage
exit 0
;;
\? )
echo "Invalid option: $OPTARG" 1>&2
usage
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
do_curl() {
cat "$1" | sed "s/\"reported_at\": *\"[^\"]*\"/\"reported_at\": \"$(date -Ru)\"/" | \
sed "s/\"host\": *\"[^\"]*\"/\"host\": \"$HOST\"/" > $TMP
curl -s -H "Content-Type: application/json" \
-X POST $URL/api/v2/config_reports \
--data-binary @$TMP -w " - $1: %{http_code}\n"
}
if [[ -f "$FILE" ]]; then
do_curl "$FILE"
elif [[ $ALL -eq 1 ]]; then
for FILE in $BASEDIR/test/static_fixtures/reports/skipped.json; do
do_curl "$FILE"
done
else
usage
fi