-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlms.sh
141 lines (127 loc) · 3.14 KB
/
dlms.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
jsondoc="{"
while [[ $# > 1 ]]
do
key="$1"
case $key in
-p|--project_name)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"project_name\":\"$2\""
shift # past argument
;;
-r|--runtime_name)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"runtime_name\":\"$2\""
shift # past argument
;;
-m|--module_name)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"module_name\":\"$2\""
shift # past argument
;;
-b|--build_number)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"build_number\":\"$2\""
shift # past argument
;;
-e|--environment_name)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"environment_name\":\"$2\""
shift # past argument
;;
-l|--lifecycle_stage)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"lifecycle_stage\":\"$2\""
shift # past argument
;;
-u|--url)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"url\":[\"$2\"]"
shift # past argument
;;
-t|--tool_name)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"tool_name\":\"$2\""
shift # past argument
;;
-d|--description)
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
jsondoc=$jsondoc"\"description\":\"$2\""
shift # past argument
;;
-cm|--custom_metadata)
if [ -e "$2" ]; then
if [ -f "$2" ]; then
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
cont=`cat "$2"`
jsondoc=$jsondoc"\"custom_metadata\":$cont"
fi
fi
shift # past argument
;;
-c|--contents)
if [ -e "$2" ]; then
if [ -f "$2" ]; then
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
cont=`cat "$2" | base64 -w 0`
#jsondoc=$jsondoc"\"contents\":{\"fcontents\":\"$cont\"}"
jsondoc=$jsondoc"\"contents\":\"$cont\""
fi
fi
shift # past argument
;;
-h|--html_contents)
if [ -e "$2" ]; then
if [ -f "$2" ]; then
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
cont=`cat "$2" | base64 -w 0`
jsondoc=$jsondoc"\"html_contents\":\"$cont\""
fi
fi
shift # past argument
;;
--default)
DEFAULT=YES
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
if [ "$jsondoc" != "{" ]; then
jsondoc=$jsondoc","
fi
#atime=`date +"%c"`
atime=`date --utc +%FT%TZ`
jsondoc=$jsondoc"\"timestamp\":\"$atime\"}"
echo jsondoc = "${jsondoc}"
if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:"
tail -1 $1
fi
curl -X POST --header "Content-Type: application/json" --header "Accept: text/plain" -d "${jsondoc}" "http://devops-datastore.stage1.mybluemix.net/v1/pub_message"