From 9b579f5f7911911552af4aa95a2fbd9585eb9542 Mon Sep 17 00:00:00 2001 From: mjr2595 Date: Tue, 30 Jul 2024 18:01:03 -0500 Subject: [PATCH] Update log-ingest.py and .groovylintrc.json formatting --- .groovylintrc.json | 41 ++++++++++++++++++++++ Rest API/Python/log-ingest.py | 66 +++++++++++++++++++---------------- 2 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 .groovylintrc.json diff --git a/.groovylintrc.json b/.groovylintrc.json new file mode 100644 index 0000000..684f374 --- /dev/null +++ b/.groovylintrc.json @@ -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 + } + } +} diff --git a/Rest API/Python/log-ingest.py b/Rest API/Python/log-ingest.py index caec162..033b334 100644 --- a/Rest API/Python/log-ingest.py +++ b/Rest API/Python/log-ingest.py @@ -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) \ No newline at end of file +# Print status and body of response +print(httpVerb + " " + url) +print("Response Status:", response.status_code) +print("Response Body:", response.content)