cloudmunch_sdk 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62f77e9360bb900fb478f2f53f126f0ec8415370
|
4
|
+
data.tar.gz: 64405240eb61c16234e7f5aa043c79f7cd6e235a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda6786a698876f0742d58857c4b9e0c6a4d5ae4ffbced16dd74ac0cc740f7bf0cac41c3a642822e56bcc89b6d968e1d7872b19d5407367721a32535ffaa73c7
|
7
|
+
data.tar.gz: a7817398062304b3a6f246107eb34c7dbd1da81a926c2a0a6b115acc7c3add3dad4d4ebe257c721de46c3354532fbdc8a2f1f399ecdb4de410e15e89a03f491a
|
@@ -62,7 +62,8 @@ class AppAbstract
|
|
62
62
|
|
63
63
|
def getCloudmunchService()
|
64
64
|
# @cloudmunchservice = @cloudmunchservice ? @cloudmunchservice : CloudmunchService.new(@var_input)
|
65
|
-
@cloudmunchservice = @cloudmunchservice ? @cloudmunchservice : CloudmunchService.initialize(@appContext)
|
65
|
+
# @cloudmunchservice = @cloudmunchservice ? @cloudmunchservice : CloudmunchService.initialize(@appContext)
|
66
|
+
@cloudmunchservice = self.extend(CloudmunchService)
|
66
67
|
return @cloudmunchservice
|
67
68
|
end
|
68
69
|
def openJSONFile(fileNameWithPath)
|
@@ -80,8 +81,7 @@ class AppAbstract
|
|
80
81
|
return serviceProvider
|
81
82
|
end
|
82
83
|
|
83
|
-
def getAppContext(
|
84
|
-
|
84
|
+
def getAppContext()
|
85
85
|
return @appContext
|
86
86
|
end
|
87
87
|
|
@@ -8,96 +8,700 @@ require_relative "Util"
|
|
8
8
|
|
9
9
|
module CloudmunchService
|
10
10
|
include Util
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
# def self.initialize(appcontext)
|
13
|
+
# @appContext=appcontext
|
14
|
+
# end
|
15
|
+
|
16
|
+
def getDataStoreID(insightID, dataStoreName)
|
17
|
+
if insightID.nil? || dataStoreName.nil?
|
18
|
+
log("DEBUG", "insight id and datastore name is needed to get datastore id")
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
|
22
|
+
paramHash = Hash.new
|
23
|
+
paramHash["insightID"] = insightID
|
24
|
+
paramHash["filter"] = {"name" => dataStoreName}
|
25
|
+
paramHash["count"] = 1
|
26
|
+
paramHash["fields"] = "id"
|
27
|
+
|
28
|
+
dataStore = getInsightDataStores(paramHash)
|
29
|
+
if dataStore.nil? || !dataStore.any?
|
30
|
+
log("DEBUG", "Data store with name "+dataStoreName+" does not exist")
|
31
|
+
return nil
|
32
|
+
else
|
33
|
+
return dataStore[0]["id"]
|
34
|
+
end
|
13
35
|
end
|
14
36
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
37
|
+
def getReportID(insightID, reportName)
|
38
|
+
if insightID.nil? || reportName.nil?
|
39
|
+
log("DEBUG", "insight id and report name is needed to get report id")
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
|
43
|
+
paramHash = Hash.new
|
44
|
+
paramHash["insightID"] = insightID
|
45
|
+
paramHash["filter"] = {"name" => reportName}
|
46
|
+
paramHash["count"] = 1
|
47
|
+
paramHash["fields"] = "id"
|
48
|
+
|
49
|
+
report = getInsightReports(paramHash)
|
50
|
+
if report.nil? || !report.any?
|
51
|
+
log("DEBUG", "Report with name "+reportName+" does not exist")
|
52
|
+
return nil
|
53
|
+
else
|
54
|
+
return report[0]["id"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def getExtractID(insightID, dataStoreID, extractName)
|
59
|
+
if insightID.nil? || dataStoreID.nil? || extractName.nil?
|
60
|
+
log("DEBUG", "insight id, datastore id and extract name is needed to get extract id")
|
61
|
+
return nil
|
62
|
+
end
|
25
63
|
|
64
|
+
extract = nil
|
65
|
+
paramHash = Hash.new
|
66
|
+
paramHash["insightID"] = insightID
|
67
|
+
paramHash["dataStoreID"] = dataStoreID
|
68
|
+
paramHash["filter"] = {"name" => extractName}
|
69
|
+
paramHash["count"] = 1
|
70
|
+
paramHash["fields"] = "id"
|
26
71
|
|
72
|
+
extract = getInsightDataStoreExtracts(paramHash)
|
73
|
+
if extract.nil? || !extract.any?
|
74
|
+
log("DEBUG", "Data store with name "+extractName+" does not exist")
|
75
|
+
return nil
|
76
|
+
else
|
77
|
+
return extract[0]["id"]
|
78
|
+
end
|
79
|
+
end
|
27
80
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
81
|
+
def getReportCardID(insightID, reportID, cardName)
|
82
|
+
if insightID.nil? || reportID.nil? || cardName.nil?
|
83
|
+
log("DEBUG", "insight id, report id and card name is needed to get report card id")
|
84
|
+
return nil
|
85
|
+
end
|
86
|
+
|
87
|
+
card = nil
|
88
|
+
paramHash = Hash.new
|
89
|
+
paramHash["insightID"] = insightID
|
90
|
+
paramHash["reportID"] = reportID
|
91
|
+
paramHash["filter"] = {"name" => cardName}
|
92
|
+
paramHash["count"] = 1
|
93
|
+
paramHash["fields"] = "id"
|
94
|
+
|
95
|
+
card = getInsightReportCards(paramHash)
|
96
|
+
if card.nil? || !card.any?
|
97
|
+
log("DEBUG", "Report with name "+cardName+" does not exist")
|
98
|
+
return nil
|
99
|
+
else
|
100
|
+
return card[0]["id"]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def getKeyMetricID(insightID, reportID, keyMetricName)
|
105
|
+
extract = nil
|
106
|
+
paramHash = Hash.new
|
107
|
+
paramHash["insightID"] = insightID
|
108
|
+
paramHash["reportID"] = reportID
|
109
|
+
paramHash["filter"] = {"name" => keyMetricName}
|
110
|
+
paramHash["count"] = 1
|
111
|
+
paramHash["fields"] = "id"
|
112
|
+
|
113
|
+
keyMetric = getInsightReportCards(paramHash)
|
114
|
+
if keyMetric.nil? || !keyMetric.any?
|
115
|
+
log("DEBUG", "Report key metric with name "+keyMetricName+" does not exist")
|
116
|
+
return nil
|
117
|
+
else
|
118
|
+
return keyMetric[0]["id"]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def createInsight(insightName)
|
123
|
+
if !insightName.nil?
|
124
|
+
insightID = nil
|
125
|
+
insightID = getInsightID(insightName)
|
126
|
+
|
127
|
+
if !insightID.nil?
|
128
|
+
log("DEBUG", "Insight with name "+insightName+" already exists!")
|
129
|
+
return insightID
|
130
|
+
else
|
131
|
+
paramHash = {}
|
132
|
+
paramHash["context"] = "insights"
|
133
|
+
paramHash["data"] = {"name" => insightName}
|
134
|
+
insight = updateCloudmunchData(paramHash)
|
135
|
+
|
136
|
+
if insight["id"].nil?
|
137
|
+
log("DEBUG", "Unable to create insight : "+insightName+"! refer log for more details")
|
138
|
+
return nil
|
139
|
+
else
|
140
|
+
return insight["id"]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
else
|
144
|
+
log("DEBUG", "Insights name is needed for creating an insight")
|
145
|
+
return nil
|
33
146
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
147
|
+
end
|
148
|
+
|
149
|
+
def createInsightDataStore(insightID, dataStoreName)
|
150
|
+
if !dataStoreName.nil? && !dataStoreName.empty? && !insightID.nil?
|
151
|
+
dataStoreID = nil
|
152
|
+
dataStoreID = getDataStoreID(insightID, dataStoreName)
|
153
|
+
|
154
|
+
if !dataStoreID.nil?
|
155
|
+
log("DEBUG", "Data store with name "+dataStoreName+" already exists!")
|
156
|
+
return dataStoreID
|
157
|
+
else
|
158
|
+
paramHash = {}
|
159
|
+
paramHash["context"] = "insights"
|
160
|
+
paramHash["contextID"] = insightID
|
161
|
+
paramHash["subContext"] = "datastores"
|
162
|
+
paramHash["data"] = {"name" => dataStoreName}
|
163
|
+
dataStore = updateCloudmunchData(paramHash)
|
164
|
+
|
165
|
+
if dataStore["id"].nil?
|
166
|
+
return nil
|
167
|
+
else
|
168
|
+
return dataStore["id"]
|
169
|
+
end
|
170
|
+
end
|
37
171
|
else
|
38
|
-
|
39
|
-
|
40
|
-
|
172
|
+
log("DEBUG", "Datastore name and insights id is needed for creating a data store")
|
173
|
+
return nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def createInsightDataStoreExtract(insightID, dataStoreID, extractName)
|
178
|
+
if !extractName.nil? && !extractName.empty? && !insightID.nil? && !dataStoreID.nil?
|
179
|
+
|
180
|
+
extractID = nil
|
181
|
+
extractID = getExtractID(insightID, dataStoreID, extractName)
|
182
|
+
|
183
|
+
if !extractID.nil?
|
184
|
+
return extractID
|
185
|
+
else
|
186
|
+
paramHash = Hash.new
|
187
|
+
paramHash["context"] = "insights"
|
188
|
+
paramHash["contextID"] = insightID
|
189
|
+
paramHash["subContext"] = "datastores"
|
190
|
+
paramHash["subContextID"] = dataStoreID
|
191
|
+
paramHash["leafContext"] = "extracts"
|
192
|
+
paramHash["data"] = {"name" => extractName}
|
193
|
+
|
194
|
+
log("DEBUG", "Attempting creation of extract with name " + extractName + "...")
|
195
|
+
extract = updateCloudmunchData(paramHash)
|
196
|
+
|
197
|
+
if extract["id"].nil? then return nil else extract["id"] end
|
198
|
+
end
|
199
|
+
else
|
200
|
+
log("DEBUG", "Extract name, insights id and datastore id is needed for creating an extract")
|
201
|
+
return nil
|
41
202
|
end
|
42
|
-
|
203
|
+
end
|
43
204
|
|
44
|
-
|
45
|
-
|
205
|
+
def createInsightReportCard(insightID, reportID, cardName)
|
206
|
+
if !cardName.nil? && !cardName.empty? && !insightID.nil? && !reportID.nil?
|
46
207
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
208
|
+
cardID = nil
|
209
|
+
cardID = getReportCardID(insightID, reportID, cardName)
|
210
|
+
|
211
|
+
if !cardID.nil?
|
212
|
+
return cardID
|
213
|
+
else
|
214
|
+
paramHash = Hash.new
|
215
|
+
paramHash["context"] = "insights"
|
216
|
+
paramHash["contextID"] = insightID
|
217
|
+
paramHash["subContext"] = "insight_reports"
|
218
|
+
paramHash["subContextID"] = reportID
|
219
|
+
paramHash["leafContext"] = "insight_cards"
|
220
|
+
paramHash["data"] = {"name" => cardName}
|
54
221
|
|
222
|
+
log("DEBUG", "Attempting creation of report card with name " + cardName + "...")
|
223
|
+
card = updateCloudmunchData(paramHash)
|
55
224
|
|
225
|
+
if card["id"].nil? then return nil else card["id"] end
|
226
|
+
end
|
227
|
+
else
|
228
|
+
log("DEBUG", "Extract name, insight id and report id is needed for creating a report card")
|
229
|
+
return nil
|
230
|
+
end
|
231
|
+
end
|
56
232
|
|
233
|
+
def createInsightReportKeyMetric(insightID, reportID, keyMetricName)
|
234
|
+
if !keyMetricName.nil? && !keyMetricName.empty? && !insightID.nil? && !reportID.nil?
|
57
235
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
if
|
62
|
-
return
|
236
|
+
keyMetricID = nil
|
237
|
+
keyMetricID = getReportKeyMetricID(insightID, reportID, keyMetricName)
|
238
|
+
|
239
|
+
if !keyMetricID.nil?
|
240
|
+
return keyMetricID
|
63
241
|
else
|
64
|
-
|
65
|
-
|
66
|
-
|
242
|
+
paramHash = Hash.new
|
243
|
+
paramHash["context"] = "insights"
|
244
|
+
paramHash["contextID"] = insightID
|
245
|
+
paramHash["subContext"] = "insight_reports"
|
246
|
+
paramHash["subContextID"] = reportID
|
247
|
+
paramHash["leafContext"] = "insight_cards"
|
248
|
+
paramHash["data"] = {"name" => keyMetricName}
|
67
249
|
|
250
|
+
log("DEBUG", "Attempting creation of report key metric with name " + keyMetricName + "...")
|
251
|
+
keyMetric = updateCloudmunchData(paramHash)
|
68
252
|
|
69
|
-
|
70
|
-
|
71
|
-
|
253
|
+
if keyMetric["id"].nil? then return nil else keyMetric["id"] end
|
254
|
+
end
|
255
|
+
else
|
256
|
+
log("DEBUG", "Key metric name, insight id and report id is needed for creating a report key metric")
|
257
|
+
return nil
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def createInsightReport(insightID, reportName)
|
262
|
+
if !reportName.nil? && !reportName.empty? && !insightID.nil?
|
72
263
|
|
73
|
-
|
74
|
-
|
75
|
-
|
264
|
+
reportID = nil
|
265
|
+
reportID = getExtractID(insightID, reportName)
|
266
|
+
|
267
|
+
if !reportID.nil?
|
268
|
+
return reportID
|
76
269
|
else
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
270
|
+
paramHash = Hash.new
|
271
|
+
paramHash["context"] = "insights"
|
272
|
+
paramHash["contextID"] = insightID
|
273
|
+
paramHash["subContext"] = "insight_reports"
|
274
|
+
paramHash["data"] = {"name" => reportName}
|
275
|
+
|
276
|
+
log("DEBUG", "Attempting creation of report with name " + reportName + "...")
|
277
|
+
report = updateCloudmunchData(paramHash)
|
278
|
+
|
279
|
+
if report["id"].nil? then return nil else report["id"] end
|
81
280
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
281
|
+
else
|
282
|
+
log("DEBUG", "Report name and insight id is needed for creating a report")
|
283
|
+
return nil
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def updateInsightDataStoreExtract(insightID, dataStoreID, data)
|
288
|
+
# /applications/{application_id}/insights/{insight_id}/datastores/{datastore_id}
|
289
|
+
|
290
|
+
if (insightID.nil? || insightID.empty?) && (dataStoreID.nil? || dataStoreID.empty?) && data.nil?
|
291
|
+
log("DEBUG", "Insight id, datastore id and data is needed to be update an existing data store")
|
292
|
+
return nil
|
293
|
+
end
|
294
|
+
paramHash = {}
|
295
|
+
paramHash["context"] = "insights"
|
296
|
+
paramHash["contextID"] = insightID
|
297
|
+
paramHash["subContext"] = "datastores"
|
298
|
+
paramHash["subContextID"] = dataStoreID
|
299
|
+
paramHash["data"] = data
|
300
|
+
return updateCloudmunchData(paramHash)
|
301
|
+
end
|
302
|
+
|
303
|
+
def updateInsightReport(insightID, reportID, data)
|
304
|
+
# /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}
|
305
|
+
|
306
|
+
if (insightID.nil? || insightID.empty?) && (reportID.nil? || reportID.empty?) && data.nil?
|
307
|
+
log("DEBUG", "Insight id, report id and data is needed to be update an existing report")
|
308
|
+
return nil
|
309
|
+
end
|
310
|
+
paramHash = {}
|
311
|
+
paramHash["context"] = "insights"
|
312
|
+
paramHash["contextID"] = insightID
|
313
|
+
paramHash["subContext"] = "insight_reports"
|
314
|
+
paramHash["subContextID"] = reportID
|
315
|
+
paramHash["data"] = data
|
316
|
+
return updateCloudmunchData(paramHash)
|
317
|
+
end
|
318
|
+
|
319
|
+
def updateInsightDataStoreExtract(insightID, dataStoreID, extractID, data)
|
320
|
+
# /insights/{insight_id}/datastores/{datastore_id}/extracts/{extract_id}
|
321
|
+
|
322
|
+
if (insightID.nil? || insightID.empty?) && (dataStoreID.nil? || dataStoreID.empty?) && (extractID.nil? || extractID.empty?) && data.nil?
|
323
|
+
log("DEBUG", "Insight id, datastore id, extract id and data is needed to be update an existing extract")
|
324
|
+
return nil
|
325
|
+
end
|
326
|
+
paramHash = {}
|
327
|
+
paramHash["context"] = "insights"
|
328
|
+
paramHash["contextID"] = insightID
|
329
|
+
paramHash["subContext"] = "datastores"
|
330
|
+
paramHash["subContextID"] = dataStoreID
|
331
|
+
paramHash["leafContext"] = "extracts"
|
332
|
+
paramHash["leafContextID"] = extractID
|
333
|
+
paramHash["data"] = data
|
334
|
+
return updateCloudmunchData(paramHash)
|
335
|
+
end
|
336
|
+
|
337
|
+
|
338
|
+
def updateInsightReportCard(insightID, reportID, cardID, data)
|
339
|
+
# /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/insight_cards/{insight_card_id}
|
340
|
+
|
341
|
+
if (insightID.nil? || insightID.empty?) && (reportID.nil? || reportID.empty?) && (cardID.nil? || cardID.empty?) && data.nil?
|
342
|
+
log("DEBUG", "Insight id, report id, cardID and data is needed to be update an existing report card")
|
343
|
+
return nil
|
344
|
+
end
|
345
|
+
|
346
|
+
paramHash = {}
|
347
|
+
paramHash["context"] = "insights"
|
348
|
+
paramHash["contextID"] = insightID
|
349
|
+
paramHash["subContext"] = "insight_reports"
|
350
|
+
paramHash["subContextID"] = reportID
|
351
|
+
paramHash["leafContext"] = "insight_cards"
|
352
|
+
paramHash["leafContextID"] = cardID
|
353
|
+
paramHash["data"] = data
|
354
|
+
return updateCloudmunchData(paramHash)
|
355
|
+
end
|
356
|
+
|
357
|
+
|
358
|
+
def updateInsightReportKeyMetric(insightID, reportID, keyMetricID, data)
|
359
|
+
# /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/key_metrics/{key_metric_id}
|
360
|
+
|
361
|
+
if (insightID.nil? || insightID.empty?) && (reportID.nil? || reportID.empty?) && (keyMetricID.nil? || keyMetricID.empty?) && data.nil?
|
362
|
+
log("DEBUG", "Insight id, report id, keyMetricID and data is needed to be update an existing report key metric")
|
363
|
+
return nil
|
364
|
+
end
|
365
|
+
|
366
|
+
paramHash = {}
|
367
|
+
paramHash["context"] = "insights"
|
368
|
+
paramHash["contextID"] = insightID
|
369
|
+
paramHash["subContext"] = "insight_reports"
|
370
|
+
paramHash["subContextID"] = reportID
|
371
|
+
paramHash["leafContext"] = "key_metrics"
|
372
|
+
paramHash["leafContextID"] = keyMetricID
|
373
|
+
paramHash["data"] = data
|
374
|
+
return updateCloudmunchData(paramHash)
|
375
|
+
end
|
376
|
+
|
377
|
+
def getInsightReportKeyMetrics(paramHash)
|
378
|
+
# /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/key_metrics/{key_metric_id}
|
379
|
+
paramReportId = paramHash["reportID"].nil? ? nil : paramHash["reportID"]
|
380
|
+
paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]
|
381
|
+
|
382
|
+
if paramInsightID.nil? || paramInsightID.empty? || paramReportId.nil? || paramReportId.empty?
|
383
|
+
log("DEBUG", "Insight id and report id is needed to gets its report key metric details")
|
384
|
+
return nil
|
385
|
+
end
|
386
|
+
|
387
|
+
paramFormatted = Hash.new
|
388
|
+
paramFormatted = paramHash
|
389
|
+
paramFormatted["context"] = "insights"
|
390
|
+
paramFormatted["subContext"] = "insight_reports"
|
391
|
+
paramFormatted["leafContext"] = "key_metrics"
|
392
|
+
paramFormatted["contextID"] = paramInsightID
|
393
|
+
paramFormatted["subContextID"] = paramReportId
|
394
|
+
|
395
|
+
if !paramHash["keyMetricID"].nil?
|
396
|
+
paramFormatted["leafContextID"] = paramHash["keyMetricID"]
|
397
|
+
end
|
398
|
+
|
399
|
+
return getCloudmunchData(paramFormatted)
|
400
|
+
end
|
401
|
+
|
402
|
+
def updateInsight(insightID, data)
|
403
|
+
# /applications/{application_id}/insights/{insight_id}
|
404
|
+
|
405
|
+
if (insightID.nil? || insightID.empty?) && data.nil?
|
406
|
+
log("DEBUG", "Insight id and data is needed to be update an existing data store")
|
407
|
+
return nil
|
408
|
+
end
|
409
|
+
|
410
|
+
paramHash = {}
|
411
|
+
paramHash["context"] = "insights"
|
412
|
+
paramHash["contextID"] = insightID
|
413
|
+
paramHash["data"] = data
|
414
|
+
return updateCloudmunchData(paramHash)
|
415
|
+
end
|
416
|
+
|
417
|
+
def updateCloudmunchData(paramHash, method = "POST")
|
418
|
+
paramData = Hash.new
|
419
|
+
paramData["data"] = paramHash["data"]
|
420
|
+
|
421
|
+
serverurl = nil
|
422
|
+
serverurl = generateServerURL(paramHash)
|
423
|
+
|
424
|
+
if serverurl.nil?
|
425
|
+
log("DEBUG", "Unable to generate server url")
|
426
|
+
log("ERROR", "Unable to "+method+" data on cloudmunch")
|
427
|
+
return nil
|
428
|
+
end
|
429
|
+
|
430
|
+
uri = URI.parse(serverurl)
|
431
|
+
|
432
|
+
log("DEBUG", "URI for "+method+" : ")
|
433
|
+
log("DEBUG", uri)
|
434
|
+
|
435
|
+
if method.casecmp("post") == 0
|
436
|
+
responseJson = Net::HTTP.post_form(uri,"data" => paramData.to_json)
|
437
|
+
elsif method.casecmp("patch") == 0
|
438
|
+
#code for patch
|
439
|
+
elsif method.casecmp("put") == 0
|
440
|
+
#code for put
|
441
|
+
end
|
442
|
+
return parseResponse(responseJson.body)
|
443
|
+
end
|
444
|
+
|
445
|
+
def parseResponse(responseJson)
|
446
|
+
requestDetails = (JSON.load(responseJson))['request']
|
447
|
+
responseData = (JSON.load(responseJson))['data']
|
448
|
+
|
449
|
+
log("DEBUG", "Response : ")
|
450
|
+
log("DEBUG", responseJson)
|
451
|
+
|
452
|
+
if !requestDetails['status'].nil? && requestDetails['status'].casecmp('success') == 0
|
453
|
+
return responseData
|
454
|
+
else
|
455
|
+
if !requestDetails['message'].nil?
|
456
|
+
log("ERROR", requestDetails['message'])
|
92
457
|
end
|
93
|
-
|
458
|
+
return nil
|
459
|
+
end
|
460
|
+
end
|
94
461
|
|
95
|
-
|
96
|
-
|
97
|
-
|
462
|
+
def getCloudmunchData(paramHash)
|
463
|
+
serverurl = nil
|
464
|
+
serverurl = generateServerURL(paramHash,true)
|
98
465
|
|
466
|
+
if serverurl.nil?
|
467
|
+
log("DEBUG", "Unable to generate server url")
|
468
|
+
log("ERROR", "Unable to get data from cloudmunch")
|
469
|
+
return nil
|
470
|
+
end
|
99
471
|
|
100
|
-
|
472
|
+
uri = URI.parse(serverurl)
|
473
|
+
|
474
|
+
log("DEBUG", "URI for get : ")
|
475
|
+
log("DEBUG", uri)
|
476
|
+
|
477
|
+
responseJson = Net::HTTP.get(uri)
|
478
|
+
return parseResponse(responseJson)
|
479
|
+
end
|
480
|
+
|
481
|
+
def getInsights(paramHash)
|
482
|
+
# /insights/{insight_id}
|
483
|
+
paraminsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]
|
484
|
+
|
485
|
+
paramFormatted = Hash.new
|
486
|
+
paramFormatted = paramHash
|
487
|
+
paramFormatted["context"] = "insights"
|
488
|
+
|
489
|
+
if !paraminsightID.nil? && !paraminsightID.empty?
|
490
|
+
paramFormatted["contextID"] = paramInsightID
|
491
|
+
end
|
492
|
+
|
493
|
+
return getCloudmunchData(paramFormatted)
|
494
|
+
end
|
495
|
+
|
496
|
+
def getInsightDataStoreExtracts(paramHash)
|
497
|
+
# /insights/{insight_id}/datastores/{datastore_id}/extracts/{extract_id}
|
498
|
+
paramDataStoreId = paramHash["dataStoreID"].nil? ? nil : paramHash["dataStoreID"]
|
499
|
+
paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]
|
500
|
+
|
501
|
+
serverurl = nil
|
502
|
+
|
503
|
+
if paramInsightID.nil? || paramInsightID.empty? || paramDataStoreId.nil? || paramDataStoreId.empty?
|
504
|
+
log("DEBUG", "Insight id and datastore id is needed to gets its extract details")
|
505
|
+
return nil
|
506
|
+
end
|
507
|
+
|
508
|
+
paramFormatted = Hash.new
|
509
|
+
paramFormatted = paramHash
|
510
|
+
paramFormatted["context"] = "insights"
|
511
|
+
paramFormatted["subContext"] = "datastores"
|
512
|
+
paramFormatted["leafContext"] = "extracts"
|
513
|
+
paramFormatted["contextID"] = paramInsightID
|
514
|
+
paramFormatted["subContextID"] = paramDataStoreId
|
515
|
+
|
516
|
+
if !paramHash["extractID"].nil?
|
517
|
+
paramFormatted["leafContextID"] = paramHash["extractID"]
|
518
|
+
end
|
519
|
+
|
520
|
+
return getCloudmunchData(paramFormatted)
|
521
|
+
end
|
522
|
+
|
523
|
+
def getInsightDataStores(paramHash)
|
524
|
+
# /insights/{insight_id}/datastores/{datastore_id}
|
525
|
+
paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]
|
526
|
+
|
527
|
+
if paramInsightID.nil? || paramInsightID.empty?
|
528
|
+
log("DEBUG", "Insight id is not provided")
|
529
|
+
return nil
|
530
|
+
end
|
531
|
+
|
532
|
+
paramFormatted = Hash.new
|
533
|
+
paramFormatted = paramHash
|
534
|
+
paramFormatted["context"] = "insights"
|
535
|
+
paramFormatted["subContext"] = "datastores"
|
536
|
+
paramFormatted["contextID"] = paramInsightID
|
537
|
+
|
538
|
+
if !paramHash["dataStoreID"].nil?
|
539
|
+
paramFormatted["subContextID"] = paramHash["dataStoreID"]
|
540
|
+
end
|
541
|
+
return getCloudmunchData(paramFormatted)
|
542
|
+
end
|
543
|
+
|
544
|
+
def getInsightReports(paramHash)
|
545
|
+
# /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}
|
546
|
+
paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]
|
547
|
+
|
548
|
+
if paramInsightID.nil? || paramInsightID.empty?
|
549
|
+
log("DEBUG", "Insight id is needed to gets its report details")
|
550
|
+
return nil
|
551
|
+
end
|
552
|
+
|
553
|
+
paramFormatted = Hash.new
|
554
|
+
paramFormatted = paramHash
|
555
|
+
paramFormatted["context"] = "insights"
|
556
|
+
paramFormatted["subContext"] = "insight_reports"
|
557
|
+
paramFormatted["contextID"] = paramInsightID
|
558
|
+
|
559
|
+
if !paramHash["reportID"].nil?
|
560
|
+
paramFormatted["subContextID"] = paramHash["reportID"]
|
561
|
+
end
|
562
|
+
|
563
|
+
return getCloudmunchData(paramFormatted)
|
564
|
+
end
|
565
|
+
|
566
|
+
def getInsightReportCards(paramHash)
|
567
|
+
# /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/insight_cards/{insight_card_id}
|
568
|
+
paramReportId = paramHash["reportID"].nil? ? nil : paramHash["reportID"]
|
569
|
+
paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]
|
570
|
+
|
571
|
+
if paramInsightID.nil? || paramInsightID.empty? || paramReportId.nil? || paramReportId.empty?
|
572
|
+
log("DEBUG", "Insight id and report id is needed to gets its report card details")
|
573
|
+
return nil
|
574
|
+
end
|
575
|
+
|
576
|
+
paramFormatted = Hash.new
|
577
|
+
paramFormatted = paramHash
|
578
|
+
paramFormatted["context"] = "insights"
|
579
|
+
paramFormatted["subContext"] = "insight_reports"
|
580
|
+
paramFormatted["leafContext"] = "insight_cards"
|
581
|
+
paramFormatted["contextID"] = paramInsightID
|
582
|
+
paramFormatted["subContextID"] = paramReportId
|
583
|
+
|
584
|
+
if !paramHash["cardID"].nil?
|
585
|
+
paramFormatted["leafContextID"] = paramHash["cardID"]
|
586
|
+
end
|
587
|
+
|
588
|
+
return getCloudmunchData(paramFormatted)
|
589
|
+
end
|
590
|
+
|
591
|
+
def generateServerURL(paramHash, appendQueryParams = nil)
|
592
|
+
|
593
|
+
serverurl = ""
|
594
|
+
|
595
|
+
if !paramHash["url"].nil?
|
596
|
+
serverurl = @appContext.get_data("{master_url}")+"/"+paramHash["url"]
|
597
|
+
elsif !paramHash["context"].nil?
|
598
|
+
paramContext = paramHash["context"].nil? ? nil : paramHash["context"]
|
599
|
+
paramContextID = paramHash["contextID"].nil? ? nil : paramHash["contextID"]
|
600
|
+
paramSubContext = paramHash["subContext"].nil? ? nil : paramHash["subContext"]
|
601
|
+
paramSubContextID = paramHash["subContextID"].nil? ? nil : paramHash["subContextID"]
|
602
|
+
paramLeafContext = paramHash["leafContext"].nil? ? nil : paramHash["leafContext"]
|
603
|
+
paramLeafContextID = paramHash["leafContextID"].nil? ? nil : paramHash["leafContextID"]
|
604
|
+
|
605
|
+
serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+paramContext
|
606
|
+
|
607
|
+
if !paramContextID.nil? && !paramContextID.empty?
|
608
|
+
serverurl=serverurl+"/"+paramContextID;
|
609
|
+
if !paramSubContext.nil? && !paramSubContext.empty?
|
610
|
+
serverurl=serverurl+"/"+paramSubContext;
|
611
|
+
if !paramSubContextID.nil? && !paramSubContextID.empty?
|
612
|
+
serverurl=serverurl+"/"+paramSubContextID;
|
613
|
+
if !paramLeafContext.nil? && !paramLeafContext.empty?
|
614
|
+
serverurl=serverurl+"/"+paramLeafContext;
|
615
|
+
if !paramLeafContextID.nil? && !paramLeafContextID.empty?
|
616
|
+
serverurl=serverurl+"/"+paramLeafContextID;
|
617
|
+
end
|
618
|
+
end
|
619
|
+
end
|
620
|
+
end
|
621
|
+
end
|
622
|
+
else
|
623
|
+
log("DEBUG", "No context provided for get api call");
|
624
|
+
return nil
|
625
|
+
end
|
626
|
+
|
627
|
+
queryString = ""
|
628
|
+
|
629
|
+
if !appendQueryParams.nil?
|
630
|
+
queryString = queryString + "filter=" + paramHash["filter"].to_json + "&" if !paramHash["filter"].nil?
|
631
|
+
queryString = queryString + "fields=" + paramHash["fields"].to_s + "&" if !paramHash["fields"].nil?
|
632
|
+
queryString = queryString + "count=" + paramHash["count"].to_s + "&" if !paramHash["count"].nil?
|
633
|
+
queryString = queryString + "offset=" + paramHash["offset"].to_s + "&" if !paramHash["offset"].nil?
|
634
|
+
queryString = queryString + "request_category=" + paramHash["requestCategory"].to_s + "&" if !paramHash["requestCategory"].nil?
|
635
|
+
queryString = queryString + "order_by=" + paramHash["orderBy"].to_s + "&" if !paramHash["orderBy"].nil?
|
636
|
+
queryString = queryString + "group_by=" + paramHash["groupBy"].to_s + "&" if !paramHash["groupBy"].nil?
|
637
|
+
end
|
638
|
+
serverurl = serverurl+"?"+queryString+"apikey="+@appContext.get_data("{api_key}")
|
639
|
+
return serverurl
|
640
|
+
end
|
641
|
+
|
642
|
+
def deleteCloudmunchData(paramHash)
|
643
|
+
paramContext = paramHash["context"]
|
644
|
+
paramContextID = paramHash["contextID"]
|
645
|
+
|
646
|
+
if !paramContext.nil? && !paramContext.empty? && !paramContextID.nil? && !paramContextID.empty?
|
647
|
+
serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+context+"/"+contextID;
|
648
|
+
serverurl=serverurl+"?apikey="+@appContext.get_data("{api_key}")
|
649
|
+
uri = URI.parse(serverurl)
|
650
|
+
Net::HTTP::Delete(uri)
|
651
|
+
return 1
|
652
|
+
else
|
653
|
+
return nil
|
654
|
+
end
|
655
|
+
end
|
656
|
+
|
657
|
+
def deleteCloudmunchDataBKUP(context,contextID)
|
658
|
+
serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+context+"/"+contextID;
|
659
|
+
serverurl=serverurl+"?apikey="+@appContext.get_data("{api_key}")
|
660
|
+
uri = URI.parse(serverurl)
|
661
|
+
Net::HTTP::Delete(uri)
|
662
|
+
end
|
663
|
+
|
664
|
+
def self.putCustomDataContext(server, endpoint, param)
|
665
|
+
result = self.http_post(server, endpoint, param)
|
666
|
+
#p result.code.to_s
|
667
|
+
if result.code.to_s == "200"
|
668
|
+
return true
|
669
|
+
else
|
670
|
+
return false
|
671
|
+
end
|
672
|
+
end
|
673
|
+
|
674
|
+
def self.getCustomDataContext(server, endpoint, param)
|
675
|
+
return self.http_get(server, endpoint, param)
|
676
|
+
end
|
677
|
+
|
678
|
+
def self.http_get(server,path,params)
|
679
|
+
if params.nil?
|
680
|
+
return Net::HTTP.get(server, path)
|
681
|
+
else
|
682
|
+
queryStr = "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
|
683
|
+
puts ("SDKDEBUG: Calling URL " + server+queryStr)
|
684
|
+
uri = URI(server + "/" + queryStr)
|
685
|
+
return Net::HTTP.get(uri)
|
686
|
+
end
|
687
|
+
end
|
688
|
+
|
689
|
+
def self.http_post(server,path,params)
|
690
|
+
queryStr = "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
|
691
|
+
puts ("SDKDEBUG: Calling URL " + server+queryStr)
|
692
|
+
if params.nil?
|
693
|
+
return Net::HTTP.post(server, path)
|
694
|
+
else
|
695
|
+
uri = URI(server + path)
|
696
|
+
return Net::HTTP.post_form(uri, params)
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
700
|
+
def self.getDataContext(server, endpoint, param)
|
701
|
+
getCustomDataContext(server, endpoint, param)
|
702
|
+
end
|
703
|
+
|
704
|
+
def self.updateDataContext(server, endpoint, param)
|
101
705
|
putCustomDataContext(server, endpoint, param)
|
102
|
-
|
103
|
-
end
|
706
|
+
end
|
707
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudmunch_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- ganesan krishnamurthy
|
7
8
|
- syamk
|
8
9
|
- rosmi
|
9
|
-
- ganesankrishnamurthy
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-12-
|
13
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|