From 089e84c0303228accd91c24ad2ac17781548e129 Mon Sep 17 00:00:00 2001 From: Sanjay Chopra Date: Thu, 22 Apr 2021 11:40:03 +0530 Subject: [PATCH] Updated example and fixed authentication bug --- example/log_non_batch.py | 32 +++++++--------- example/simple_example.py | 52 ++++++++++++++++++-------- logicmonitor_data_sdk/configuration.py | 6 +-- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/example/log_non_batch.py b/example/log_non_batch.py index a16e68d..1fe71d2 100644 --- a/example/log_non_batch.py +++ b/example/log_non_batch.py @@ -1,29 +1,25 @@ - -import logging +# Sample Program to send Logs to LogicMonitor Platform +# import os -import time - -import psutil as psutil - import logicmonitor_data_sdk from logicmonitor_data_sdk.api.logs import Logs from logicmonitor_data_sdk.models import Resource -logger = logging.getLogger('lmdata.api') -logger.setLevel(logging.INFO) +# Initialize LM SDK and provide required authentication parameters +# On LM Portal, create 'API Token' for the user to get access Id and access Key +configuration = logicmonitor_data_sdk.Configuration( company='your_company', + id='API access id', + key='API access key') -configuration = logicmonitor_data_sdk.Configuration(company='yourcompany', - id='accessID', - key='accessKey') - +# The resource which is already present on LM Platform. Use a unique property to match +# the resource and send log for that. +resource = Resource(ids={"system.hostname": 'your_system'}) -resource = Resource(ids={"System.hostname": "192.168.1.33"}) +#Create an api handle for sending the logs +# "batch" would club logs for 8MB size or 30 Sec - whichever is earlier. Its default is "True". log_api = Logs(batch = False) -log_api.send_logs(resource = resource,msg= "this is smaple log") - - - - +return_value = log_api.send_logs(resource=resource, msg= "this is sample log") +print(return_value) diff --git a/example/simple_example.py b/example/simple_example.py index 4417840..48c9ef2 100644 --- a/example/simple_example.py +++ b/example/simple_example.py @@ -2,22 +2,44 @@ from random import seed, random import logicmonitor_data_sdk + +# LogicMonitor metric data model is as below +# +#Company +# |--- Resource (like device/service. Ex: VM) +# |--- Data Source (Ex. CPU) +# |--- Instance (of a Data Source on a resource. Ex. CPU-1) +# |--- Data Point (the metric which is being monitored. Ex. %Used) +# |-