Forum Discussion
manthena2020
10 months agoAdvisor
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
import pandas as pd
# Account Info
AccessId =
AccessKey =
Company =
# Define start time
start_timestamp = int(time.mktime(time.strptime("2024-01-01", "%Y-%m-%d"))) * 1000
# Get the current time in milliseconds
current_timestamp = int(time.time() * 1000)
# Request Info
httpVerb = 'GET'
resourcePath = '/device/devices/659/devicedatasources/77499/instances/64341678/data'
queryParams = f'?start={start_timestamp}&end={current_timestamp}'
data = ''
# Construct URL
url = 'https://' + Company + '.logicmonitor.com/santaba/rest' + resourcePath + queryParams
# Get current time in milliseconds
epoch = str(int(time.time() * 1000))
# Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
# Construct signature
hmac1 = hmac.new(AccessKey.encode(), msg=requestVars.encode(), digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())
# Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type': 'application/json', 'Authorization': auth}
# Make request
response = requests.get(url, data=data, headers=headers)
# Print status and body of response
print('Response Status:', response.status_code)
print('Response Body:', response.content)
# Convert response content to JSON
json_response = json.loads(response.content)
# Check if "data" field exists in the JSON response
if "data" in json_response:
data_field = json_response["data"]
# Check if "values" field exists
if data_field and "values" in data_field:
# Extract the "values" field and create a Pandas DataFrame
df = pd.DataFrame(data_field["values"], columns=data_field["dataPoints"])
# Access the "time" field and add it as a new column
df["time"] = pd.to_datetime(data_field["time"], unit="ms")
# Print the Pandas DataFrame
print(df)
else:
print("No 'values' field found in the 'data' section of the JSON response.")
else:
print("No 'data' field found in the JSON response. Error message:", json_response.get("errmsg", "N/A"))
i want to capture Data from 1st January 2024 to till date. Any one Please look into this
Related Content
- 2 months ago
- 2 years ago