Module: CloudmunchService

Includes:
Util
Included in:
AppAbstract
Defined in:
lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

generateReport, getJSONArgs, getJSONArgsTEMP, getTemplate, getUrlForViewCards, log, logClose, logInit, logIt, openJSONFile

Class Method Details

.getCustomDataContext(server, endpoint, param) ⇒ Object



674
675
676
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 674

def self.getCustomDataContext(server, endpoint, param)
    return self.http_get(server, endpoint, param)
end

.getDataContext(server, endpoint, param) ⇒ Object



700
701
702
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 700

def self.getDataContext(server, endpoint, param)
    getCustomDataContext(server, endpoint, param)     
end

.http_get(server, path, params) ⇒ Object



678
679
680
681
682
683
684
685
686
687
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 678

def self.http_get(server,path,params)
  if params.nil?
   return Net::HTTP.get(server, path)
  else
     queryStr =  "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
     puts ("SDKDEBUG: Calling URL " + server+queryStr)
     uri = URI(server + "/" + queryStr)
     return Net::HTTP.get(uri) 
  end
end

.http_post(server, path, params) ⇒ Object



689
690
691
692
693
694
695
696
697
698
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 689

def self.http_post(server,path,params)
  queryStr =  "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
  puts ("SDKDEBUG: Calling URL " + server+queryStr)
  if params.nil?
      return Net::HTTP.post(server, path)
  else
      uri = URI(server +  path)
      return Net::HTTP.post_form(uri, params)
  end
end

.putCustomDataContext(server, endpoint, param) ⇒ Object



664
665
666
667
668
669
670
671
672
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 664

def self.putCustomDataContext(server, endpoint, param)
  result = self.http_post(server, endpoint, param)
  #p result.code.to_s 
  if result.code.to_s == "200"
    return true 
  else
    return false 
  end     
end

.updateDataContext(server, endpoint, param) ⇒ Object



704
705
706
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 704

def self.updateDataContext(server, endpoint, param)
    putCustomDataContext(server, endpoint, param)  
end

Instance Method Details

#createInsight(insightName) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 122

def createInsight(insightName)
  if !insightName.nil?
    insightID = nil
    insightID = getInsightID(insightName)
    
    if !insightID.nil?
      log("DEBUG", "Insight with name "+insightName+" already exists!")
      return insightID
    else
      paramHash = {}
      paramHash["context"]    = "insights"
      paramHash["data"]       = {"name" => insightName}
      insight = updateCloudmunchData(paramHash)
      
      if insight["id"].nil?
        log("DEBUG", "Unable to create insight : "+insightName+"! refer log for more details")
        return nil
      else
        return insight["id"]
      end
    end
  else
      log("DEBUG", "Insights name is needed for creating an insight")
      return nil
  end
end

#createInsightDataStore(insightID, dataStoreName) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 149

def createInsightDataStore(insightID, dataStoreName)
  if !dataStoreName.nil? && !dataStoreName.empty? && !insightID.nil?
    dataStoreID = nil
    dataStoreID = getDataStoreID(insightID, dataStoreName)
    
    if !dataStoreID.nil?
      log("DEBUG", "Data store with name "+dataStoreName+" already exists!")
      return dataStoreID
    else
      paramHash = {}
      paramHash["context"]    = "insights"
      paramHash["contextID"]  = insightID
      paramHash["subContext"] = "datastores"
      paramHash["data"]       = {"name" => dataStoreName}
      dataStore = updateCloudmunchData(paramHash)
      
      if dataStore["id"].nil?
        return nil
      else
        return dataStore["id"]
      end
    end
  else
      log("DEBUG", "Datastore name and insights id is needed for creating a data store")
      return nil
  end
end

#createInsightDataStoreExtract(insightID, dataStoreID, extractName) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 177

def createInsightDataStoreExtract(insightID, dataStoreID, extractName)
  if !extractName.nil? && !extractName.empty? && !insightID.nil?  && !dataStoreID.nil?

    extractID = nil
    extractID = getExtractID(insightID, dataStoreID, extractName)
    
    if !extractID.nil?
      return extractID
    else
      paramHash = Hash.new
      paramHash["context"]      = "insights"
      paramHash["contextID"]    = insightID
      paramHash["subContext"]   = "datastores"
      paramHash["subContextID"] = dataStoreID
      paramHash["leafContext"]  = "extracts"
      paramHash["data"]         = {"name" => extractName}

      log("DEBUG", "Attempting creation of extract with name " + extractName + "...")
      extract = updateCloudmunchData(paramHash)

      if extract["id"].nil? then return nil else extract["id"] end
    end
  else
      log("DEBUG", "Extract name, insights id and datastore id is needed for creating an extract")
      return nil
  end
end

#createInsightReport(insightID, reportName) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 261

def createInsightReport(insightID, reportName)
  if !reportName.nil? && !reportName.empty? && !insightID.nil?

    reportID = nil
    reportID = getExtractID(insightID, reportName)
    
    if !reportID.nil?
      return reportID
    else
      paramHash = Hash.new
      paramHash["context"]     = "insights"
      paramHash["contextID"]   = insightID
      paramHash["subContext"]  = "insight_reports"
      paramHash["data"]        = {"name" => reportName}

      log("DEBUG", "Attempting creation of report with name " + reportName + "...")
      report = updateCloudmunchData(paramHash)

      if report["id"].nil? then return nil else report["id"] end
    end
  else
      log("DEBUG", "Report name and insight id is needed for creating a report")
      return nil
  end
end

#createInsightReportCard(insightID, reportID, cardName) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 205

def createInsightReportCard(insightID, reportID, cardName)
  if !cardName.nil? && !cardName.empty? && !insightID.nil?  && !reportID.nil?

    cardID = nil
    cardID = getReportCardID(insightID, reportID, cardName)
    
    if !cardID.nil?
      return cardID
    else
      paramHash = Hash.new
      paramHash["context"]      = "insights"
      paramHash["contextID"]    = insightID
      paramHash["subContext"]   = "insight_reports"
      paramHash["subContextID"] = reportID
      paramHash["leafContext"]  = "insight_cards"
      paramHash["data"]         = {"name" => cardName}

      log("DEBUG", "Attempting creation of report card with name " + cardName + "...")
      card = updateCloudmunchData(paramHash)

      if card["id"].nil? then return nil else card["id"] end
    end
  else
      log("DEBUG", "Extract name, insight id and report id is needed for creating a report card")
      return nil
  end
end

#createInsightReportKeyMetric(insightID, reportID, keyMetricName) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 233

def createInsightReportKeyMetric(insightID, reportID, keyMetricName)
  if !keyMetricName.nil? && !keyMetricName.empty? && !insightID.nil?  && !reportID.nil?

    keyMetricID = nil
    keyMetricID = getReportKeyMetricID(insightID, reportID, keyMetricName)
    
    if !keyMetricID.nil?
      return keyMetricID
    else
      paramHash = Hash.new
      paramHash["context"]      = "insights"
      paramHash["contextID"]    = insightID
      paramHash["subContext"]   = "insight_reports"
      paramHash["subContextID"] = reportID
      paramHash["leafContext"]  = "insight_cards"
      paramHash["data"]         = {"name" => keyMetricName}

      log("DEBUG", "Attempting creation of report key metric with name " + keyMetricName + "...")
      keyMetric = updateCloudmunchData(paramHash)

      if keyMetric["id"].nil? then return nil else keyMetric["id"] end
    end
  else
      log("DEBUG", "Key metric name, insight id and report id is needed for creating a report key metric")
      return nil
  end
end

#deleteCloudmunchData(paramHash) ⇒ Object



642
643
644
645
646
647
648
649
650
651
652
653
654
655
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 642

def deleteCloudmunchData(paramHash)
  paramContext = paramHash["context"]
  paramContextID = paramHash["contextID"]

  if !paramContext.nil? && !paramContext.empty? && !paramContextID.nil? && !paramContextID.empty?
      serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+context+"/"+contextID;
      serverurl=serverurl+"?apikey="+@appContext.get_data("{api_key}")
      uri = URI.parse(serverurl)
      Net::HTTP::Delete(uri)
      return 1
  else
      return nil
  end
end

#deleteCloudmunchDataBKUP(context, contextID) ⇒ Object



657
658
659
660
661
662
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 657

def deleteCloudmunchDataBKUP(context,contextID)
  serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+context+"/"+contextID;
  serverurl=serverurl+"?apikey="+@appContext.get_data("{api_key}")
  uri = URI.parse(serverurl)
  Net::HTTP::Delete(uri)
end

#generateServerURL(paramHash, appendQueryParams = nil) ⇒ Object



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 591

def generateServerURL(paramHash, appendQueryParams = nil)

  serverurl = ""
  
  if !paramHash["url"].nil?
      serverurl = @appContext.get_data("{master_url}")+"/"+paramHash["url"]
  elsif !paramHash["context"].nil?
      paramContext       = paramHash["context"].nil? ? nil : paramHash["context"]
      paramContextID     = paramHash["contextID"].nil? ? nil : paramHash["contextID"]
      paramSubContext    = paramHash["subContext"].nil? ? nil : paramHash["subContext"]
      paramSubContextID  = paramHash["subContextID"].nil? ? nil : paramHash["subContextID"]
      paramLeafContext   = paramHash["leafContext"].nil? ? nil : paramHash["leafContext"]
      paramLeafContextID = paramHash["leafContextID"].nil? ? nil : paramHash["leafContextID"]

      serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+paramContext

      if !paramContextID.nil? && !paramContextID.empty?
          serverurl=serverurl+"/"+paramContextID;
          if !paramSubContext.nil? && !paramSubContext.empty?
              serverurl=serverurl+"/"+paramSubContext;              
              if !paramSubContextID.nil? && !paramSubContextID.empty?
                  serverurl=serverurl+"/"+paramSubContextID;
                  if !paramLeafContext.nil? && !paramLeafContext.empty?
                      serverurl=serverurl+"/"+paramLeafContext;
                      if !paramLeafContextID.nil? && !paramLeafContextID.empty?
                          serverurl=serverurl+"/"+paramLeafContextID;
                      end
                  end
              end
          end
      end
  else
      log("DEBUG", "No context provided for get api call");
      return nil
  end

  queryString = ""
  
  if !appendQueryParams.nil?
    queryString = queryString + "filter=" + paramHash["filter"].to_json + "&" if !paramHash["filter"].nil?
    queryString = queryString + "fields=" + paramHash["fields"].to_s    + "&" if !paramHash["fields"].nil?
    queryString = queryString + "count="  + paramHash["count"].to_s     + "&" if !paramHash["count"].nil?
    queryString = queryString + "offset=" + paramHash["offset"].to_s    + "&" if !paramHash["offset"].nil?
    queryString = queryString + "request_category=" + paramHash["requestCategory"].to_s + "&" if !paramHash["requestCategory"].nil?
    queryString = queryString + "order_by=" + paramHash["orderBy"].to_s + "&" if !paramHash["orderBy"].nil?
    queryString = queryString + "group_by=" + paramHash["groupBy"].to_s + "&" if !paramHash["groupBy"].nil?
  end
  serverurl = serverurl+"?"+queryString+"apikey="+@appContext.get_data("{api_key}")
  return serverurl
end

#getCloudmunchData(paramHash) ⇒ Object



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 462

def getCloudmunchData(paramHash)
  serverurl = nil
  serverurl = generateServerURL(paramHash,true)

  if serverurl.nil?
      log("DEBUG", "Unable to generate server url")
      log("ERROR", "Unable to get data from cloudmunch")    
      return nil
  end

  uri = URI.parse(serverurl)              
  
  log("DEBUG", "URI for get : ")
  log("DEBUG", uri)          
  
  responseJson = Net::HTTP.get(uri)
  return parseResponse(responseJson)
end

#getDataStoreID(insightID, dataStoreName) ⇒ Object

def self.initialize(appcontext)

@appContext=appcontext

end



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 16

def getDataStoreID(insightID, dataStoreName)
    if insightID.nil? || dataStoreName.nil?
      log("DEBUG", "insight id and datastore name is needed to get datastore id")
      return nil
    end

    paramHash = Hash.new
    paramHash["insightID"] = insightID
    paramHash["filter"] = {"name" => dataStoreName} 
    paramHash["count"]  = 1
    paramHash["fields"] = "id" 

    dataStore = getInsightDataStores(paramHash)
    if dataStore.nil? || !dataStore.any?
      log("DEBUG", "Data store with name "+dataStoreName+" does not exist")
      return nil
    else
      return dataStore[0]["id"]
    end
end

#getExtractID(insightID, dataStoreID, extractName) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 58

def getExtractID(insightID, dataStoreID, extractName)
    if insightID.nil? || dataStoreID.nil? || extractName.nil?
      log("DEBUG", "insight id, datastore id and extract name is needed to get extract id")
      return nil
    end

    extract = nil
    paramHash = Hash.new
    paramHash["insightID"]   = insightID
    paramHash["dataStoreID"] = dataStoreID
    paramHash["filter"] = {"name" => extractName}
    paramHash["count"]  = 1
    paramHash["fields"] = "id" 

    extract = getInsightDataStoreExtracts(paramHash)
    if extract.nil? || !extract.any?
      log("DEBUG", "Data store with name "+extractName+" does not exist")
      return nil
    else
      return extract[0]["id"]
    end
end

#getInsightDataStoreExtracts(paramHash) ⇒ Object



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 496

def getInsightDataStoreExtracts(paramHash)
  # /insights/{insight_id}/datastores/{datastore_id}/extracts/{extract_id}
  paramDataStoreId = paramHash["dataStoreID"].nil? ? nil : paramHash["dataStoreID"]
  paramInsightID   = paramHash["insightID"].nil? ? nil : paramHash["insightID"]

  serverurl   = nil

  if paramInsightID.nil? || paramInsightID.empty? || paramDataStoreId.nil? || paramDataStoreId.empty?
    log("DEBUG", "Insight id and datastore id is needed to gets its extract details")
    return nil
  end

  paramFormatted = Hash.new
  paramFormatted = paramHash
  paramFormatted["context"]      = "insights"
  paramFormatted["subContext"]   = "datastores"
  paramFormatted["leafContext"]  = "extracts"
  paramFormatted["contextID"]    = paramInsightID
  paramFormatted["subContextID"] = paramDataStoreId
  
  if !paramHash["extractID"].nil?
    paramFormatted["leafContextID"] = paramHash["extractID"]
  end

  return getCloudmunchData(paramFormatted)
end

#getInsightDataStores(paramHash) ⇒ Object



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 523

def getInsightDataStores(paramHash)
  # /insights/{insight_id}/datastores/{datastore_id}
  paramInsightID  = paramHash["insightID"].nil? ? nil : paramHash["insightID"]

  if paramInsightID.nil? || paramInsightID.empty?
    log("DEBUG", "Insight id is not provided")
    return nil
  end

  paramFormatted = Hash.new
  paramFormatted = paramHash
  paramFormatted["context"]    = "insights"
  paramFormatted["subContext"] = "datastores"
  paramFormatted["contextID"]  = paramInsightID
  
  if !paramHash["dataStoreID"].nil?
    paramFormatted["subContextID"] = paramHash["dataStoreID"]
  end
  return getCloudmunchData(paramFormatted)          
end

#getInsightReportCards(paramHash) ⇒ Object



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 566

def getInsightReportCards(paramHash)
  # /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/insight_cards/{insight_card_id}
  paramReportId  = paramHash["reportID"].nil? ? nil : paramHash["reportID"]
  paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]

  if paramInsightID.nil? || paramInsightID.empty? || paramReportId.nil? || paramReportId.empty?
    log("DEBUG", "Insight id and report id is needed to gets its report card details")
    return nil
  end

  paramFormatted = Hash.new
  paramFormatted = paramHash
  paramFormatted["context"]      = "insights"
  paramFormatted["subContext"]   = "insight_reports"
  paramFormatted["leafContext"]  = "insight_cards"
  paramFormatted["contextID"]    = paramInsightID
  paramFormatted["subContextID"] = paramReportId
  
  if !paramHash["cardID"].nil?
    paramFormatted["leafContextID"] = paramHash["cardID"]
  end

  return getCloudmunchData(paramFormatted)
end

#getInsightReportKeyMetrics(paramHash) ⇒ Object



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 377

def getInsightReportKeyMetrics(paramHash)
  # /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/key_metrics/{key_metric_id}
  paramReportId  = paramHash["reportID"].nil? ? nil : paramHash["reportID"]
  paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]

  if paramInsightID.nil? || paramInsightID.empty? || paramReportId.nil? || paramReportId.empty?
    log("DEBUG", "Insight id and report id is needed to gets its report key metric details")
    return nil
  end

  paramFormatted = Hash.new
  paramFormatted = paramHash
  paramFormatted["context"]      = "insights"
  paramFormatted["subContext"]   = "insight_reports"
  paramFormatted["leafContext"]  = "key_metrics"
  paramFormatted["contextID"]    = paramInsightID
  paramFormatted["subContextID"] = paramReportId
  
  if !paramHash["keyMetricID"].nil?
    paramFormatted["leafContextID"] = paramHash["keyMetricID"]
  end

  return getCloudmunchData(paramFormatted)
end

#getInsightReports(paramHash) ⇒ Object



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 544

def getInsightReports(paramHash)
  # /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}
  paramInsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]

  if paramInsightID.nil? || paramInsightID.empty?
    log("DEBUG", "Insight id is needed to gets its report details")
    return nil
  end

  paramFormatted = Hash.new
  paramFormatted = paramHash
  paramFormatted["context"]    = "insights"
  paramFormatted["subContext"] = "insight_reports"
  paramFormatted["contextID"]  = paramInsightID
  
  if !paramHash["reportID"].nil?
    paramFormatted["subContextID"] = paramHash["reportID"]
  end

  return getCloudmunchData(paramFormatted)
end

#getInsights(paramHash) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 481

def getInsights(paramHash)
  # /insights/{insight_id}
  paraminsightID = paramHash["insightID"].nil? ? nil : paramHash["insightID"]

  paramFormatted = Hash.new
  paramFormatted = paramHash
  paramFormatted["context"] = "insights"
  
  if !paraminsightID.nil? && !paraminsightID.empty?
      paramFormatted["contextID"]  = paramInsightID
  end    

  return getCloudmunchData(paramFormatted)          
end

#getKeyMetricID(insightID, reportID, keyMetricName) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 104

def getKeyMetricID(insightID, reportID, keyMetricName)
    extract = nil
    paramHash = Hash.new
    paramHash["insightID"] = insightID
    paramHash["reportID"] = reportID
    paramHash["filter"] = {"name" => keyMetricName}
    paramHash["count"]  = 1
    paramHash["fields"] = "id" 

    keyMetric = getInsightReportCards(paramHash)
    if keyMetric.nil? || !keyMetric.any?
      log("DEBUG", "Report key metric with name "+keyMetricName+" does not exist")
      return nil
    else
      return keyMetric[0]["id"]
    end
end

#getReportCardID(insightID, reportID, cardName) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 81

def getReportCardID(insightID, reportID, cardName)
    if insightID.nil? || reportID.nil? || cardName.nil?
      log("DEBUG", "insight id, report id and card name is needed to get report card id")
      return nil
    end

    card = nil
    paramHash = Hash.new
    paramHash["insightID"] = insightID
    paramHash["reportID"] = reportID
    paramHash["filter"] = {"name" => cardName}
    paramHash["count"]  = 1
    paramHash["fields"] = "id" 

    card = getInsightReportCards(paramHash)
    if card.nil? || !card.any?
      log("DEBUG", "Report with name "+cardName+" does not exist")
      return nil
    else
      return card[0]["id"]
    end
end

#getReportID(insightID, reportName) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 37

def getReportID(insightID, reportName)
    if insightID.nil? || reportName.nil?
      log("DEBUG", "insight id and report name is needed to get report id")
      return nil
    end

    paramHash = Hash.new
    paramHash["insightID"] = insightID
    paramHash["filter"] = {"name" => reportName} 
    paramHash["count"]  = 1
    paramHash["fields"] = "id" 

    report = getInsightReports(paramHash)
    if report.nil? || !report.any?
      log("DEBUG", "Report with name "+reportName+" does not exist")
      return nil
    else
      return report[0]["id"]
    end
end

#parseResponse(responseJson) ⇒ Object



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 445

def parseResponse(responseJson)
  requestDetails = (JSON.load(responseJson))['request']
  responseData   = (JSON.load(responseJson))['data']

  log("DEBUG", "Response : ")
  log("DEBUG", responseJson)
  
  if !requestDetails['status'].nil? && requestDetails['status'].casecmp('success') == 0    
      return responseData
  else
      if !requestDetails['message'].nil?
        log("ERROR", requestDetails['message'])
      end
      return nil
  end
end

#updateCloudmunchData(paramHash, method = "POST") ⇒ Object



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 417

def updateCloudmunchData(paramHash, method = "POST") 
    paramData = Hash.new
    paramData["data"] = paramHash["data"]
    
    serverurl = nil
    serverurl = generateServerURL(paramHash)

    if serverurl.nil?
        log("DEBUG", "Unable to generate server url")
        log("ERROR", "Unable to "+method+" data on cloudmunch")    
        return nil
    end

    uri = URI.parse(serverurl)              
    
    log("DEBUG", "URI for "+method+" : ")
    log("DEBUG", uri)          
    
    if method.casecmp("post") == 0
      responseJson = Net::HTTP.post_form(uri,"data" => paramData.to_json)
    elsif method.casecmp("patch") == 0
      #code for patch
    elsif method.casecmp("put") == 0
      #code for put
    end
    return parseResponse(responseJson.body)      
end

#updateInsight(insightID, data) ⇒ Object



402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 402

def updateInsight(insightID, data)
  # /applications/{application_id}/insights/{insight_id}

  if (insightID.nil? || insightID.empty?) && data.nil?
    log("DEBUG", "Insight id and data is needed to be update an existing data store")
    return nil
  end

  paramHash = {}
  paramHash["context"]   = "insights"
  paramHash["contextID"] = insightID
  paramHash["data"]      = data
  return updateCloudmunchData(paramHash)
end

#updateInsightDataStoreExtract(insightID, dataStoreID, extractID, data) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 287

def updateInsightDataStoreExtract(insightID, dataStoreID, data)
  # /applications/{application_id}/insights/{insight_id}/datastores/{datastore_id}

  if (insightID.nil? || insightID.empty?) && (dataStoreID.nil? || dataStoreID.empty?) && data.nil?
    log("DEBUG", "Insight id, datastore id and data is needed to be update an existing data store")
    return nil
  end
      paramHash = {}
      paramHash["context"]      = "insights"
      paramHash["contextID"]    = insightID
      paramHash["subContext"]   = "datastores"
      paramHash["subContextID"] = dataStoreID
      paramHash["data"]         = data
      return updateCloudmunchData(paramHash)
end

#updateInsightReport(insightID, reportID, data) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 303

def updateInsightReport(insightID, reportID, data)
  # /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}

  if (insightID.nil? || insightID.empty?) && (reportID.nil? || reportID.empty?) && data.nil?
    log("DEBUG", "Insight id, report id and data is needed to be update an existing report")
    return nil
  end
      paramHash = {}
      paramHash["context"]      = "insights"
      paramHash["contextID"]    = insightID
      paramHash["subContext"]   = "insight_reports"
      paramHash["subContextID"] = reportID
      paramHash["data"]         = data
      return updateCloudmunchData(paramHash)
end

#updateInsightReportCard(insightID, reportID, cardID, data) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 338

def updateInsightReportCard(insightID, reportID, cardID, data)
  # /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/insight_cards/{insight_card_id}

  if (insightID.nil? || insightID.empty?) && (reportID.nil? || reportID.empty?) && (cardID.nil? || cardID.empty?) && data.nil?
    log("DEBUG", "Insight id, report id, cardID and data is needed to be update an existing report card")
    return nil
  end

  paramHash = {}
  paramHash["context"]       = "insights"
  paramHash["contextID"]     = insightID
  paramHash["subContext"]    = "insight_reports"
  paramHash["subContextID"]  = reportID
  paramHash["leafContext"]   = "insight_cards"
  paramHash["leafContextID"] = cardID
  paramHash["data"]          = data
  return updateCloudmunchData(paramHash)
end

#updateInsightReportKeyMetric(insightID, reportID, keyMetricID, data) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 358

def updateInsightReportKeyMetric(insightID, reportID, keyMetricID, data)
  # /applications/{application_id}/insights/{insight_id}/insight_reports/{insight_report_id}/key_metrics/{key_metric_id}

  if (insightID.nil? || insightID.empty?) && (reportID.nil? || reportID.empty?) && (keyMetricID.nil? || keyMetricID.empty?) && data.nil?
    log("DEBUG", "Insight id, report id, keyMetricID and data is needed to be update an existing report key metric")
    return nil
  end

  paramHash = {}
  paramHash["context"]       = "insights"
  paramHash["contextID"]     = insightID
  paramHash["subContext"]    = "insight_reports"
  paramHash["subContextID"]  = reportID
  paramHash["leafContext"]   = "key_metrics"
  paramHash["leafContextID"] = keyMetricID
  paramHash["data"]          = data
  return updateCloudmunchData(paramHash)
end