-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_datasource_datapoints (1).py
75 lines (57 loc) · 2.03 KB
/
add_datasource_datapoints (1).py
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
import base64
import hashlib
import hmac
import time
import json
import requests
# Logicmonitor Variables
# Account Info
AccessId =''
AccessKey =''
Company = ''
# Request Info
httpVerb = 'GET'
resourcePath = '/setting/datasources/89130725'
queryParameters = ''
data = ''
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParameters
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
#Make request
response = requests.get(url, data=data, headers=headers)
response_json = json.loads(response.content)
# print(response.content)
my_new_datapoint = json.loads(json.dumps(response_json['data']['dataPoints'][-1]))
my_new_datapoint['name'] = "keyValue5"
my_new_datapoint['postProcessorParam'] = "##WILDVALUE##.keyValue5"
del my_new_datapoint['id']
response_json['data']['dataPoints'].append(my_new_datapoint)
data = json.dumps(response_json['data'])
# print(data)
# Request Info
httpVerb = 'PUT'
resourcePath = '/setting/datasources/89130725'
queryParameters = ''
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParameters
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
#Make request
put_response = requests.put(url, data=data, headers=headers)
# put_response_json = json.loads(response.content)
print(put_response.content)