How IT administrators can streamline operations using the LogicMonitor API

How IT admins can streamline operations using the LogicMonitor API

In today’s fast-paced IT ecosystem, agility and efficiency are not just goals but necessities. So why waste an hour (or more) manually onboarding individual devices when you can leverage the LogicMonitor API to automate the onboarding process for an entire site in just minutes from a simple CSV file? 

In this article, we’re going to review how LogicMonitor administrators can maximize efficiency and transform their IT operations using LogicMonitor’s REST API and Powershell. We will cover the following use cases:

  • Device onboarding/offboarding
  • User management
  • Retrieving data

Tailoring LogicMonitor to your needs with the API, SDKs, and PowerShell module

Designed to empower developers and IT administrators alike, LogicMonitor’s API serves as the backbone for automating and streamlining operations, offering a level of flexibility and power that can significantly enhance how LogicMonitor administrators manage their organization’s infrastructure. 

To make integration as smooth as possible, we provide comprehensive SDKs for both Python and Go, ensuring you have the tools to tailor our platform to your specific requirements. Because over 75% of our customers leverage Windows-based collectors, Senior Sales Engineer, Steven Villardi, has taken LogicMonitor’s adaptability a step further by developing the Logic.Monitor PowerShell module

This open-source module leverages the REST API to offer LogicMonitor administrators a seamless and familiar way to enhance their operational efficiency, embodying our commitment to meet and exceed the demands of modern IT management. 

Authentication methods

LogicMonitor’s latest customer-facing API is REST API v3. Two forms of authentication are supported by REST API v3: token-based LMv1 token and Bearer token authentication.

Installation and configuration

Before exploring some use cases and examples, we’ll need to ensure we have the Logic.Monitor PowerShell module installed from the PowerShell Gallery. To do so, simply follow the steps outlined below.

Install-Module -Name "Logic.Monitor"

Upgrading to the latest version:

Update-Module -Name "Logic.Monitor"

General usage:

Before you can use any module commands, you must be connected to a LogicMonitor portal. To connect your portal, type in the Connect-LMAccount command.

#Using LMv1 Token
Connect-LMAccount -AccessId "lm_access_id" -AccessKey "lm_access_key" -AccountName "lm_portal_prefix_name"

#Using Bearer Token
Connect-LMAccount -BearerToken "lm_bearer_token" -AccountName "lm_portal_prefix_name"

Once connected, you can then run an appropriate command. A full list of available commands is found using:

Get-Command -Module "Logic.Monitor"

To disconnect from an account, simply run the Disconnect-LMAccount command.

Disconnect-LMAccount

Use cases for LogicMonitor’s REST API

Device onboarding or offboarding

One of a LogicMonitor administrator’s fundamental responsibilities is device lifecycle management. Rather than onboard or offboard each device individually, LogicMonitor administrators can take advantage of LogicMonitor’s REST API. 

By employing the Logic.Monitor PowerShell module, administrators can complete device onboarding and offboarding processes in minutes while executing any requisite device updates, significantly reducing their administrative burden.

Onboarding a new device:

New-LMDevice -Name 192.168.1.1 -DisplayName device.example.com -Description "My new device" -PreferredCollectorId 8 -HostGroupIds @(1,2,3) -Properties @{"snmp.community"="public";location="NYC"}

Updating an existing device:

Set-LMDevice -Name device.example.com -Description "My updated description" -PreferredCollectorId 15 -Properties @{location="AMER"} -DisableAlerting $true

Offboarding a device:

Remove-LMDevice -Name device.example.com -HardDelete $true

Re-triggering ActiveDiscovery for a device:

Invoke-LMActiveDiscovery -Name device.example.com 

User management

In addition to device management, LogicMonitor administrators are also responsible for managing Role-Based Access Control (RBAC) settings and user accounts. The LogicMonitor API offers comprehensive management features for both user accounts and their associated role permissions.

Adding a user:

New-LMUser -RoleNames @("administrator") -Password "changeme" -FirstName John -LastName Doe -Email [email protected] -Username [email protected] -ForcePasswordChange $true -Phone "5558675309"

Suspending a user:

Set-LMUser -Status suspended -Username [email protected]

Creating a role to ingest and manage LM Logs for all resources:

New-LMRole -Name log_ingest -Description "Ability to ingest logs" -LogsPermission manage -ResourcePermission view

Retrieving data

Frequently, LogicMonitor administrators must retrieve device information, search audit logs, extract metric data, and more. The Logic.Monitor REST API provides numerous endpoints, enabling customers to access their device and portal data and facilitating integration with third-party systems.

Searching audit logs for activities:

Get-LMAuditLogs -SearchString "[email protected]" -StartDate $(Get-Date).AddDays(-7) -EndDate $(Get-Date)

Getting a list of devices based on filter criteria:

Get-LMDevice -Filter "name -eq '127.0.0.1' -and currentCollectorId -eq 8 -and disableAlerting -eq '$false'"

Getting metric data for a device:

Get-LMDeviceData -DeviceName "127.0.0.1" -DatasourceName Ping -InstanceName Ping -StartDate $(Get-Date).AddDays(-7) -EndDate $(Get-Date)

Putting it all together

With access to over 188 cmdlets within the Logic.Monitor module, LogicMonitor administrators can incorporate multiple commands into a single function/script to automate the onboarding process for an entire site in just minutes from a simple CSV file. The ability to enforce Standard Operating Procedures (SOPs) related to LogicMonitor administration guarantees that monitoring is accurately set up and activated for essential resources within your organization. Below is an example set of functions for auto-creating devices and device groups from a simple CSV file:

As we wrap up our exploration of the Logic.Monitor PowerShell Module, we invite you to take the leap into building and innovating with the LogicMonitor REST API. Your ideas and feedback are crucial for growth, so if you have any suggestions or would like to contribute to this open-source project, don’t hesitate to open an issue/enhancement request on GitHub.

Let’s harness this insight into LogicMonitor’s API as a catalyst for innovation and automation. Together, we can extend the capabilities of LogicMonitor’s platform and redefine what’s possible in hybrid observability.