Blog Post

Tech Talk
3 MIN READ

Logic.Monitor (PowerShell) module

Steve_Villardi's avatar
Steve_Villardi
Icon for LM Champion rankLM Champion
2 years ago

If you're a LogicMonitor user looking to streamline your workflows and automate repetitive tasks, you'll be pleased to know that there's is a PowerShell module available to help you do just that. As a longtime Windows administrator, I've relied on PowerShell as my go-to tool for automating and managing my infrastructure. I've found that the ability to automate tasks through PowerShell not only saves time, but also reduces errors and ensures consistency across the environment. Developed by myself as a personal side project, this module provides a range of cmdlets that can be used to interact with the LogicMonitor API, making it easier than ever to manage your monitoring setup directly from the command line. Whether you're looking to retrieve information about your monitored devices, update alert thresholds, or perform other administrative tasks, this module has you covered. In this post, we'll take a closer look at the features and capabilities of this module, and show you how to get started with using it in your own automation scripts.

This project is published in the PowerShell Gallery at https://www.powershellgallery.com/packages/Logic.Monitor/.

Installation From PowerShell Gallery:

Install-Module -Name "Logic.Monitor"

Upgrading:

#New releases are published often, to ensure you have the latest version you can run:
Update-Module -Name "Logic.Monitor"


General Usage:

Before you can use on module commands you will need to be connected to a LM portal. To connect your LM portal use the Connect-LMAccount command:

Connect-LMAccount -AccessId "lm_access_id" -AccessKey "lm_access_key" -AccountName "lm_portal_prefix_name"

Once connected you can then run an appropriate command, a full list of commands available can be found using:

Get-Command -Module "Logic.Monitor"

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

Disconnect-LMAccount

Examples:

Most Get commands can pull info by id or name to allow for easier retrieval without needing to know the specific resource id. The name parameters in get commands can also accept wildcard values. 

Get list of devices:

#Get all devices
Get-LMDevice

#Get device via id
Get-LMDevice -Id 1

#Get device via hostname
Get-LMDevice -Name device.example.com

#Get device via displayname/wildcard
Get-LMDevice -DisplayName "corp*"

Modify a device:

#Change device Name,DisplayName,Descrition,Link and set collector assignment
Set-LMDevice -Id 1 -DisplayName "New Device Name" -NewName "device.example.com" -Description "Critical Device" -Link "http://device.example.com" -PreferredCollectorId 1

#Add/Update custom properties to a resource and disable alerting
Set-LMDevice -Id 1 -Properties @{propname1="value1";propname2="value2"} -DisableAlerting $true

***Using the Name parameter to target a resource during a Set/Remove command will perform an initial get request for you automatically to retrieve the required id. When performing a large amount of changes using id is the preferred method to avoid excessive lookups and avoid any potential API throttling.

Remove a device:

#Remove device by hostname
Remove-LMDevice -Name "device.example.com" -HardDelete $false

Send a LM Log Message:

Send-LMLogMessage -Message "Hello World!" -resourceMapping @{"system.displayname"="LM-COLL"} -Metadata @{"extra-data"="value";"extra-data2"="value2"}

Add a new user to LogicMonitor:

New-LMUser -RoleNames @("administrator") -Password "changeme" -FirstName John -LastName Doe -Email jdoe@example.com -Username jdoe@example.com -ForcePasswordChange $true -Phone "5558675309"

There are over ~150 cmdlets exposed as part of this module and more are being added each week as I receive feedback internally and from customers. For more details and other examples/code snippets or to contribute you can visit the github repo where this is hosted.

Source Repository: https://github.com/stevevillardi/Logic.Monitor
Additional Code Examples: https://github.com/stevevillardi/Logic.Monitor/blob/main/EXAMPLES.md

Note: This is very much a personal project and not an official LogicMonitor integration. If the concept of a native PowerShell module interest you, I would recommend putting in a feedback request so that the demand can be tracked.

Published 2 years ago
Version 1.0

29 Comments

  • Hello @Steve Villardi - great work! Just a short question regarding this. We have several Windows System which we schedule from Task to reboot frequently. We thought to put some lines to the script to tell LM to put that Machine to that point to a short SDT. But i don´t find a module to set. Is that correct?

    @Magna_FL That is correct, I have been creating cmdlets based on need for the most part and somehow SDT has yet to come up surprisingly. I have added New-LMDeviceSDT and Set-LMDeviceSDT to my list of cmdlets to add to the next release. I will try and get those pushed out ASAP. Thanks for the note!

    I have raised the issue on GitHub if you want to track if for updates: https://github.com/stevevillardi/Logic.Monitor/issues/14

  • Hello @Steve Villardi - great work! Just a short question regarding this. We have several Windows System which we schedule from Task to reboot frequently. We thought to put some lines to the script to tell LM to put that Machine to that point to a short SDT. But i don´t find a module to set. Is that correct?

  • This is incredibly helpful @Steve Villardi ! Thank you so much. I’ve already had clients utilize these scripts and I’m just so grateful I could find this and not have to try to convert my python to PS. 😂 You’re the best!

  • This is amazingly helpful, and trashes about 2 months of my own scripting! 😂

    Thanks for posting this, Steve!

    Glad it can be of help! Feel free to provide feedback on the github repo or open an feature request if you come across something not already covered by the module. I also incline you to put in a feedback request within your LM portal asking for a native module, always helpful for product to hear it direct from the customer end that something like this would be useful out-of-box.

    We always appreciate feedback for our product! For any client watching this thread who is unsure where to submit feedback within your respective portal, I will provide a diagram of where to navigate to below:

    The “Support” button is located in the top-right corner of your portal
  • This is amazingly helpful, and trashes about 2 months of my own scripting! 😂

    Thanks for posting this, Steve!

    Glad it can be of help! Feel free to provide feedback on the github repo or open an feature request if you come across something not already covered by the module. I also incline you to put in a feedback request within your LM portal asking for a native module, always helpful for product to hear it direct from the customer end that something like this would be useful out-of-box.

  • This is amazingly helpful, and trashes about 2 months of my own scripting! 😂

    Thanks for posting this, Steve!