Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom Endpoint and log_level metadata #42

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion logicmonitor_data_sdk/api/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def send_logs(self, **kwargs): # noqa: E501
returns the request thread.
"""

all_params = ['resource', 'msg', 'timestamp', 'metadata'] # noqa: E501
all_params = ['resource', 'msg', 'timestamp','log_level', 'metadata'] # noqa: E501
params = locals()
for key, val in six.iteritems(params['kwargs']):
if key not in all_params:
Expand All @@ -130,6 +130,8 @@ def send_logs(self, **kwargs): # noqa: E501
logs['timestamp'] = kwargs['timestamp']
if kwargs.__contains__('metadata'):
logs['metadata'] = kwargs['metadata']
if kwargs.__contains__('log_level'):
logs['log_level'] = kwargs['log_level']
self.add_request(resource=copy.deepcopy(kwargs['resource']),
logs=logs)
else:
Expand Down Expand Up @@ -196,6 +198,8 @@ def _single_request(self, **kwargs):
logs['timestamp'] = kwargs['timestamp']
if kwargs.__contains__('metadata'):
logs['metadata'] = kwargs['metadata']
if kwargs.__contains__('log_level'):
logs['logl_evel'] = kwargs['log_level']
body = []
body.append(logs)
# size limiting
Expand Down
7 changes: 5 additions & 2 deletions logicmonitor_data_sdk/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
>>> conf = logicmonitor_data_sdk.Configuration(company="ACCOUNT_NAME", id='API_ACCESS_ID', key= 'API_ACCESS_KEY')
"""

def __init__(self, company=None, authentication=None, id=None, key=None, gzip_flag=True, bearer_token=None):
def __init__(self, company=None, authentication=None, id=None, key=None, gzip_flag=True, bearer_token=None,domain_name=None):
"""Constructor"""
# Default Base url
self._authentication = {}
self.bearer_flag = False
self.gzip_flag = gzip_flag
self._domain_name= "logicmonitor.com"
company = company or os.environ.get('LM_COMPANY')
if company is None or company == '':
raise ValueError(
Expand Down Expand Up @@ -110,7 +111,9 @@ def __init__(self, company=None, authentication=None, id=None, key=None, gzip_fl
'Authentication must provide AccessID and AccessKey or Bearer Token'
)
self._company = company
self._host = "https://" + self._company + ".logicmonitor.com/rest"
if not domain_name:
domain_name = os.environ.get("LM_DOMAIN_NAME") or self._domain_name
self._host = "https://" + self._company + "." + domain_name + "/rest"
if not self.bearer_flag:
self.check_authentication(authentication)
elif self.bearer_flag:
Expand Down
7 changes: 5 additions & 2 deletions test/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
company = 'company'
id = 'id'
key = 'key'

configuration = Configuration(company=company, id=id, key=key)
domain_name="logicmonitor.com"
configuration = Configuration(company=company, id=id, key=key,domain_name=domain_name)


class TestConfiguration(TestCase):
Expand All @@ -34,6 +34,9 @@ def test_authentication(self):

def test_host(self):
self.assertEqual('https://'+company+'.logicmonitor.com/rest', configuration.host)

def test_domain_name(self):
self.assertEqual('logicmonitor.com', configuration.domain_name)

def test_auth_settings(self):
expected = {'LMv1': {'type': 'api_key', 'in': 'header', 'key': 'Authorization',
Expand Down