Logic.Monitor (PowerShell) module
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 originally 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:
Upgrading:
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:
Once connected you can then run an appropriate command, a full list of commands available can be found using:
To disconnect from an account simply run the Disconnect-LMAccount command:
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:
Modify a device:
***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:
Send a LM Log Message:
Add a new user to LogicMonitor:
There are over ~200 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/logicmonitor/lm-powershell-module
Additional Documentation: https://logicmonitor.github.io/lm-powershell-module-docs/
Note: This PowerShell module is an open-source project created and maintained by LogicMonitor users. While not an official LogicMonitor product, it's designed by people who use and understand the platform.
The module is freely available for everyone to use, modify, and improve. We welcome your feedback and contributions! If you have ideas or encounter any issues, please share them through GitHub issues or pull requests.
Many community members rely on this module in their daily operations. Though we can't offer formal support guarantees, our collaborative community strives to address questions and continuously enhance functionality.
We hope you find this tool valuable for your LogicMonitor workflows!
Darren Dudgeon
·1 year agoSteve, I just have to say that this Module has allowed me to easily navigate the LM API. It's wonderful at code reduction and makes my scripts clean and readable. Thank-you very much for putting this together and maintaining it!
Steven Villardi
OP2 years agoThanks for creating this. We’ve been using it for a while and ran into a strange issue with authentication on Linux. It works perfectly when we run from a Windows machine, but if we run from a Linux machine (pwsh), we get authentication errors even though the credentials aren’t changed. I’m not sure if this is generally an issue with Linux PowerShell or specific to the module, but thought I’d mention in case it was perhaps a known issue. Here is the type of error we see (the error shows on the LM logs too… but again, the auth credentials are unchanged from what works when the same script is run from a Windows box):
Out-PsLogging: [ERROR] 2024-03-02T17:47:29: Unexpected error getting device groups. To prevent errors, Get-LogicMonitorDeviceGroup will
exit. If present, the following details were returned: Error message: Authentication failed
Error code: 1401 Invoke-Request: Response status code does not indicate success: 401 ().
Headers: Name Value ---- ----- X-Version 3
Content-Type application/json Authorization LMv1
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx… Body:
@S P are you sure you’re talking about the Logic.Monitor ps module? The cmdlet name is not one that I recognize and the error output is different. The Logic.Monitor module is tested on 5.1 and core 7+ for both linux/win OSes so there should not be an issue specific to linux that does not effect windows users as well.
S_P
·2 years agoThanks for creating this. We’ve been using it for a while and ran into a strange issue with authentication on Linux. It works perfectly when we run from a Windows machine, but if we run from a Linux machine (pwsh), we get authentication errors even though the credentials aren’t changed. I’m not sure if this is generally an issue with Linux PowerShell or specific to the module, but thought I’d mention in case it was perhaps a known issue. Here is the type of error we see (the error shows on the LM logs too… but again, the auth credentials are unchanged from what works when the same script is run from a Windows box):
Out-PsLogging: [ERROR] 2024-03-02T17:47:29: Unexpected error getting device groups. To prevent errors, Get-LogicMonitorDeviceGroup will
exit. If present, the following details were returned: Error message: Authentication failed
Error code: 1401 Invoke-Request: Response status code does not indicate success: 401 ().
Headers: Name Value ---- ----- X-Version 3
Content-Type application/json Authorization LMv1
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx… Body:
Steven Villardi
OP2 years ago@Steve Villardi
I was looking at the get-lmalert one and trying to use the customColumns part to get the ##externalticketid## field back.
I tried a few different ways to encode it in PowerShell but it did not seem to work properly or I am just doing it wrong.
Have you done it before to get the ticket id back since that is the field where things like a ServiceNow incident # would appear?
@Jeff Batchelor Should just able able to specify it in double quotes: “##externalticketid##”. How are you building your command. Below is an example for reference:
Response:
Jeffrey Batchelor
·2 years ago@Steve Villardi
I was looking at the get-lmalert one and trying to use the customColumns part to get the ##externalticketid## field back.
I tried a few different ways to encode it in PowerShell but it did not seem to work properly or I am just doing it wrong.
Have you done it before to get the ticket id back since that is the field where things like a ServiceNow incident # would appear?
Steven Villardi
OP2 years agoHi,
I am stringing together a few of your commands to setup Collectors, Resources, Dashboards etc so things are setup consistently.
Do you have any plans for: “Creating ReportGroup”? (Would be pretty similar to: New-LMDashboardGroup)
I see Get-LMReportGroup.ps1 but not a new-LMReportGroup yet.
@ryang I can certainly add it into the next update. If there are other commands that would be of use please feel free to open an enhancement issue on the github repo.
@ryang I have add support for New/Set/Remove cmdlets for report groups in the latest pull request on github. If you want to grab the updates from there feel free to do so, if your not in a hurry you can also just wait for the 5.0.1 release sometime next week which will have these changed included.
Steven Villardi
OP2 years agoHi,
I am stringing together a few of your commands to setup Collectors, Resources, Dashboards etc so things are setup consistently.
Do you have any plans for: “Creating ReportGroup”? (Would be pretty similar to: New-LMDashboardGroup)
I see Get-LMReportGroup.ps1 but not a new-LMReportGroup yet.
@ryang I can certainly add it into the next update. If there are other commands that would be of use please feel free to open an enhancement issue on the github repo.
Ryan Gillan
·2 years agoHi,
I am stringing together a few of your commands to setup Collectors, Resources, Dashboards etc so things are setup consistently.
Do you have any plans for: “Creating ReportGroup”? (Would be pretty similar to: New-LMDashboardGroup)
I see Get-LMReportGroup.ps1 but not a new-LMReportGroup yet.
Laurie Street
·2 years agoI didn’t even have time to write up an issue!
Thanks Steve. I will test this out tomorrow!
Steven Villardi
OP2 years agoHi Steve, is there a way to update the static threshold at the resource/instance level using one of the already available modules?
Cheers
I don’t believe there currently is any cmdlet for threshold modification outside of the datasource global definition. If that is something that would be helpful to have I can certainly look to add it in the next update. If you want to open it as an issue on github as an enhancement I can notify you when it gets put in the next release.
@StLaurie I had some time this evening and was able to add device group and device instance level alert threshold support in the latest release 4.6.2. See below for the full release notes and example command usage. Let me know if this is along the lines of what you were looking for, hopefully it helps your usecase!
Release 4.6.2
New Commands:
Get-LMDeviceGroupDatasourceAlertSetting: New cmdlet to retrieve alert settings for datasources associated with resources that are a member of a device group. Useful for looking up datasource ids and datapoint info so you can modify group level alert settings using Set-LMDeviceGroupDatasourceAlertSetting.
Set-LMDeviceGroupDatasourceAlertSetting: New cmdlet to set group level alert settings for datasources associated with resources that are a member of a device group.
Get-LMDeviceGroupDatasourceList: New cmdlet to list out datasource info for all datasources associated with a specified device group.
Get-LMDeviceDatasourceInstanceAlertSetting: New cmdlet to retrieve alert settings for datasources instances associated with a resource. Useful for looking up datasource ids and datapoint info so you can modify device/instance level alert settings using Set-LMDeviceDatasourceInstanceAlertSetting.
Set-LMDeviceDatasourceInstanceAlertSetting: New cmdlet to set device/instance level alert settings for datasources associated with a resource.
Example Usage:
Note: Below examples use name parameters to reference portal objects. You should use IDs where possible to avoid excessive look ups when changing configurations in bulk.
Steven Villardi
OP2 years agoHi Steve, is there a way to update the static threshold at the resource/instance level using one of the already available modules?
Cheers
I don’t believe there currently is any cmdlet for threshold modification outside of the datasource global definition. If that is something that would be helpful to have I can certainly look to add it in the next update. If you want to open it as an issue on github as an enhancement I can notify you when it gets put in the next release.
Laurie Street
·2 years agoHi Steve, is there a way to update the static threshold at the resource/instance level using one of the already available modules?
Cheers
Steven Villardi
OP2 years ago@Steve Villardi Awesome - thanks so much for the super quick turn around. Really appreciate it. My only other gentle suggestion is to use Write-Output instead of Write-Host for Write-LMHost as commands can then have their output sent to $null resulting in no output to the host/console. Happy to create a pul request on the repo.
Thanks again!
_Loz
@StLaurie Feel free to open a pull request. Most of the write-lmhost should really be moved to debug/verbose output for the most part but I need to go through and add in cmdletbinding functionality. It’s been on my list to clean up just have yet to get to it. But always appreciate the feedback!
Laurie Street
·2 years ago@Steve Villardi Awesome - thanks so much for the super quick turn around. Really appreciate it. My only other gentle suggestion is to use Write-Output instead of Write-Host for Write-LMHost as commands can then have their output sent to $null resulting in no output to the host/console. Happy to create a pul request on the repo.
Thanks again!
_Loz
Steven Villardi
OP2 years agoFantastic Module, but adding #Requires -Version 7 to 4.5.6 in Build-LMDataModel.ps1 & Submit-LMDataModel.ps1 has effectively killed the module for me in a corporate setting. Some backwards compatibility or reduction in function while still allowing other modules to work would be excellent.
Apologies for the recent update, did not realize that the requires on those two cmdlets would break the module elsewhere. I have pushed a 4.5.7 out which rolls back that change until I can find a better method to control version requirements.
@StLaurie So I have pushed out a version 4.6 that removes the “utility” cmdlets that I originally had included in the Logic.Monitor module a while back. These are no longer part of the module suite and were mainly used by me so it did not make sense to keep them in the module any longer. Going forward only API cmdlets will be published in this module as to keep things clean and organized better than it was before. This should help with the frequent updates that have nothing to do with the API wrapper functionality and avoid introducing breaking changes unintentionally. I am also working on introducing version 5.1 of pwsh in my pester testing to ensure backwards compatibility with older versions of PowerShell are not effected. Appreciate you bringing this to my attention so I could address it swiftly.
Steven Villardi
OP2 years agoFantastic Module, but adding #Requires -Version 7 to 4.5.6 in Build-LMDataModel.ps1 & Submit-LMDataModel.ps1 has effectively killed the module for me in a corporate setting. Some backwards compatibility or reduction in function while still allowing other modules to work would be excellent.
Apologies for the recent update, did not realize that the requires on those two cmdlets would break the module elsewhere. I have pushed a 4.5.7 out which rolls back that change until I can find a better method to control version requirements.
Laurie Street
·2 years agoFantastic Module, but adding #Requires -Version 7 to 4.5.6 in Build-LMDataModel.ps1 & Submit-LMDataModel.ps1 has effectively killed the module for me in a corporate setting. Some backwards compatibility or reduction in function while still allowing other modules to work would be excellent.
Steven Villardi
OP2 years ago@ryang glad you find the module useful. I believe the update device endpoint only allows add/update operations. In order to remove a property you would need to use the Remove-LMDeviceProperty command.
Ryan Gillan
·2 years ago@Steve Villardi
Thank you so much for this Powershell.
I have been working with a few things for a while and this has speed up my work day.
One question, for you or my peers.
Does anyone know how we can REMOVE a property from a device?
# Set a property
Set-LMDevice -Id 123 -Properties @{'snmp.community'='public';}
If I can set a property, then I can bulk remove.
Steven Villardi
OP2 years ago@Magna_FL Just wanted to let you know version 4.5 was just released that includes full support for managing SDT. Below is a full list of changes along with usage examples. Let me know if you have any questions, thanks again for reaching out!
Version 4.5 Updates:
New Commands:
New-LMDeviceSDT: New command to create device level SDT. Supports oneTime, daily, weekly, monthly and dayOfMonth occurrences.
New-LMDeviceGroupSDT: New command to create device group level SDT. Supports oneTime, daily, weekly, monthly and dayOfMonth occurrences.
New-LMDeviceDatasourceSDT: New command to create a datasource level SDT for a targeted device. Supports oneTime, daily, weekly, monthly and dayOfMonth occurrences.
New-LMDeviceDatasourceInstanceSDT: New command to create an instance level SDT for a targeted device. Supports oneTime, daily, weekly, monthly and dayOfMonth occurrences.
Set-LMSDT: New command to manage existing scheduled SDT windows. Supports pipeline input from Get-LMSDT, Get-LMDeviceSDT and Get-LMDeviceGroupSDT.
Remove-LMSDT: New command to delete scheduled SDT windows. Supports pipeline input from Get-LMSDT, Get-LMDeviceSDT and Get-LMDeviceGroupSDT.
Updated Commands:
Get-SDT: Added custom object typing for returned results.
Get-LMDeviceSDT: Added custom object typing for returned results.
Get-LMDeviceGroupSDT: Added custom object typing for returned results.
Example Usage:
Ryan Gillan
·2 years agoHas anyone had any luck scripting moving bulk devices from Collector A to Collector B?
The device may or may not be in an Autobalanced group:
Set-LMDevice -Id 89073 -Properties @{'currentCollectorId'=454;}
I even tried:
Set-LMDevice -Id 89073 -PreferredCollectorGroupId 150 -PreferredCollectorId 454 -Properties @{'currentCollectorId'=454;}
Steven Villardi
OP2 years ago@Steve Villardi check this out if you want to get kick started
@Stuart Weenig Thanks, taking a look now!
LM User
·2 years ago@Steve Villardi check this out if you want to get kick started
Steven Villardi
OP2 years agoHello @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
Magna_FL
·2 years agoHello @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?
kendall
·2 years agoThis 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!
Kwame Armstrong
·3 years agoReally slick stuff here, @Steve Villardi !
Matt Airhart
·3 years agoThis 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:
Steven Villardi
OP3 years agoThis 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.
Jason Clemons
·3 years agoThis is amazingly helpful, and trashes about 2 months of my own scripting! 😂
Thanks for posting this, Steve!