Skip to content

Commit

Permalink
Update some scripts to use env and added SDK example for ABCG fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mjr2595 committed Jan 27, 2024
1 parent ed0dcc9 commit 8580b04
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
60 changes: 60 additions & 0 deletions Rest API/Python/SDK/fix_abcg_collectors_sdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from __future__ import print_function
import os
import logicmonitor_sdk
from dotenv import load_dotenv
from logicmonitor_sdk.rest import ApiException

load_dotenv()

# Configure API key authorization: LMv1
configuration = logicmonitor_sdk.Configuration()
configuration.company = os.getenv("PORTAL")
configuration.auth_type = 'Bearer'
configuration.bearer_token = os.getenv("BEARER")

# create an instance of the API class
api_instance = logicmonitor_sdk.LMApi(
logicmonitor_sdk.ApiClient(configuration))


def main():
# Get list of auto-balanced collector group ids
abcg_id_list = get_abcg_ids()

if abcg_id_list is not None:
# For each aabcg id, get the list of devices in that group
# For each device, set autoBalancedCollectorGroupId to preferredCollectorGroupId
for abcg_id in abcg_id_list:
print("Fixing ABCG " + str(abcg_id))
fix_resource_collectors(abcg_id)
else:
print("No ABCG IDs found.")


def get_abcg_ids():
try:
response = api_instance.get_collector_group_list(
filter='autoBalance:true')
id_list = [item.id for item in response.items]
return id_list
except ApiException as e:
print("Exception when calling CollectorGroupsApi->getCollectorGroupList: %s\n" % e)


def fix_resource_collectors(abcg_id):
try:
filter = 'autoBalancedCollectorGroupId:0,preferredCollectorGroupId:' + \
str(abcg_id)
response = api_instance.get_device_list(filter=filter)
for device in response.items:
device_id = device.id
print("Updating deviceID " + str(device_id))
body = {"autoBalancedCollectorGroupId": abcg_id}
api_instance.patch_device(id=device_id, body=body)
except ApiException as e:
print(
"Exception when calling DevicesApi: %s\n" % e)


if __name__ == "__main__":
main()
15 changes: 9 additions & 6 deletions Rest API/Python/SDK/gettAllAlerts.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
from __future__ import print_function
import time
import os
import logicmonitor_sdk
from dotenv import load_dotenv
from logicmonitor_sdk.rest import ApiException
from pprint import pprint

load_dotenv()

# Configure API key authorization: LMv1
configuration = logicmonitor_sdk.Configuration()
configuration.company = 'COMPANY_NAME'
configuration.access_id = 'API_ACCESS_ID'
configuration.access_key = 'API_ACCESS_KEY'
configuration.company = os.getenv("PORTAL")
configuration.auth_type = 'Bearer'
configuration.bearer_token = os.getenv("BEARER")

# create an instance of the API class
api_instance = logicmonitor_sdk.LMApi(logicmonitor_sdk.ApiClient(configuration))
api_instance = logicmonitor_sdk.LMApi(
logicmonitor_sdk.ApiClient(configuration))

try:
# get alert list
api_response = api_instance.get_alert_list()
pprint(api_response)
except ApiException as e:
print("Exception when calling LMApi->getAlertList: %s\n" % e)
print("Exception when calling LMApi->getAlertList: %s\n" % e)
8 changes: 6 additions & 2 deletions Rest API/Python/fix_abcg_collectors.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#!/usr/bin/python

import os
import requests
from dotenv import load_dotenv

load_dotenv()

# Account Info
portal = ''
bearer = ''
portal = os.getenv("PORTAL")
bearer = os.getenv("BEARER")
auth = 'bearer ' + bearer
headers = {'Content-Type': 'application/json',
'X-version': '3', 'Authorization': auth}
Expand Down

0 comments on commit 8580b04

Please sign in to comment.