Skip to content

Commit

Permalink
Update log-ingest.py and .groovylintrc.json formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mjr2595 committed Jul 30, 2024
1 parent edb50de commit 9b579f5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 30 deletions.
41 changes: 41 additions & 0 deletions .groovylintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"extends": "recommended",
"rules": {
"CompileStatic": {
"enabled": false
},
"DuplicateNumberLiteral": {
"enabled": false
},
"DuplicateStringLiteral": {
"enabled": false
},
"Indentation": {
"enabled": false
},
"MethodParameterTypeRequired": {
"enabled": false
},
"MethodReturnTypeRequired": {
"enabled": false
},
"NoDef": {
"enabled": false
},
"StaticMethodsBeforeInstanceMethods": {
"enabled": false
},
"ThrowException": {
"enabled": false
},
"UnnecessaryGetter": {
"enabled": false
},
"UnnecessarySetter": {
"enabled": false
},
"VariableTypeRequired": {
"enabled": false
}
}
}
66 changes: 36 additions & 30 deletions Rest API/Python/log-ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,48 @@
import time
import hmac

#Account Info
AccessId =''
AccessKey =''
Company = ''

#Request Info
httpVerb = 'POST'
resourcePath = '/log/ingest'
data = '{msg: "user john logged in",timestamp: 1582555792,_lm.resourceId: {system.deviceId: "281"},host: "systemY",username: "john",type_of_auth: "oauth"}'
queryParams = ''

#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
# Account Info
AccessId = ""
AccessKey = ""
Company = ""

# Request Info
httpVerb = "POST"
resourcePath = "/log/ingest"
data = """[
{
"msg": "this is a test",
"_lm.resourceId": {
"system.deviceId": "281"
}
}
]
"""
queryParams = ""

# Construct URL
url = "https://" + Company + ".logicmonitor.com/rest" + resourcePath + queryParams

# Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
# Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
# Construct signature
digest = hmac.new(
AccessKey.encode('utf-8'),
msg=requestVars.encode('utf-8'),
digestmod=hashlib.sha256
AccessKey.encode("utf-8"), msg=requestVars.encode("utf-8"), digestmod=hashlib.sha256
).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
signature = base64.b64encode(digest.encode("utf-8")).decode("utf-8")

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'2'}
# Construct headers
auth = "LMv1 " + AccessId + ":" + str(signature) + ":" + epoch
headers = {"Content-Type": "application/json", "Authorization": auth, "X-Version": "2"}

#Make request
# Make request
response = requests.post(url, data=data, headers=headers)

#Print status and body of response
print(httpVerb + ' ' + url)
print('Response Status:',response.status_code)
print('Response Body:',response.content)
# Print status and body of response
print(httpVerb + " " + url)
print("Response Status:", response.status_code)
print("Response Body:", response.content)

0 comments on commit 9b579f5

Please sign in to comment.