Logic.Monitor (PowerShell) module


Userlevel 5
Badge +3

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.


21 replies

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

Thanks for posting this, Steve!

 

Userlevel 5
Badge +3

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.

Userlevel 4
Badge +3

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

 

Userlevel 5
Badge +5

Really slick stuff here, @Steve Villardi !

Userlevel 4
Badge +7

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!

Userlevel 1
Badge

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?

Userlevel 5
Badge +3

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

Userlevel 7
Badge +19

@Steve Villardi check this out if you want to get kick started

Userlevel 5
Badge +3

@Steve Villardi check this out if you want to get kick started

@Stuart Weenig Thanks, taking a look now!

Userlevel 5
Badge +3

@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:

#Example usage New-LMDeviceSDT
#OneTime SDT window
New-LMDeviceSDT -DeviceId 2798 -StartDate (Get-Date) -EndDate (Get-Date).AddHours(12) -Comment "Quick Reboot"

#Daily 30-minute SDT window from 12:00 to 12:30
New-LMDeviceSDT -DeviceId 2798 -DeviceId 2798 -StartHour 12 -StartMinute 0 -EndHour 12 -EndMinute 30 -Comment "Daily Reboot"

#Weekly 30-minute SDT window every Monday
New-LMDeviceSDT -DeviceId 2798 -StartHour 12 -StartMinute 0 -EndHour 12 -EndMinute 30 -WeekDay Monday -Comment "Patch Window"

#Monthly 30-minute SDT window every 1st day of the month
New-LMDeviceSDT -DeviceId 2798 -StartHour 12 -StartMinute 0 -EndHour 12 -EndMinute 30 -DayOfMonth 1 -Comment "Patch Window"

#Monthly 30-minute SDT window on the 1st Monday of every month
New-LMDeviceSDT -DeviceId 2798 -StartHour 12 -StartMinute 0 -EndHour 12 -EndMinute 30 -WeekDay Monday -WeekOfMonth First -Comment "Patch Window"

#Example usage Set-LMSDT
#Update SDT to the 5th day of the month
Set-LMSDT -id HG_77 -DayOfMonth 5 -Comment "New Patch Window (5th of each month)"

#Example usage Remove-LMSDT
#Update SDT to the 5th day of the month
Remove-LMSDT -id HG_77

 

@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.

 

Userlevel 5
Badge +3

@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. 

Userlevel 2
Badge

Fantastic Module, but adding #Requires -Version 7 to 4.5.6 in  Build-LMDataModel.ps1Submit-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.

Userlevel 5
Badge +3

Fantastic Module, but adding #Requires -Version 7 to 4.5.6 in  Build-LMDataModel.ps1Submit-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.

Userlevel 5
Badge +3

Fantastic Module, but adding #Requires -Version 7 to 4.5.6 in  Build-LMDataModel.ps1Submit-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.

Userlevel 2
Badge

@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

Userlevel 5
Badge +3

@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!

Userlevel 2
Badge

Hi Steve, is there a way to update the static threshold at the resource/instance level using one of the already available modules?

Cheers 

Userlevel 5
Badge +3

Hi 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.

Userlevel 5
Badge +3

Hi 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.

 

#Get list of datasources associated with devices that are a member of the Villa Villardi resource group
Get-LMDeviceGroupDatasourceList -Name "Villa Villardi"

#Get alert seetings for HTTPS datasource at the Villa Villardi resource group level
Get-LMDeviceGroupDatasourceAlertSetting -Name "Villa Villardi" -DatasourceName "HTTPS"

#Disable alerting at the resource group level for the HTTPS -> status datapoint for all resources in Villa Villardi resource group
Set-LMDeviceGroupDatasourceAlertSetting -Name "Villa Villardi" -DatasourceName "HTTPS" -DatapointName Status -DisableAlerting $true

#Get device instance alert settings info for datasource NoData_Tasks_By_Type_v2 where the instance name is ping
Get-LMDeviceDatasourceInstanceAlertSetting -DatasourceName NoData_Tasks_By_Type_v2 -Name 127.0.0.1 -InstanceName ping

#Set device instance alert setting to alert when instance ping has a datapoint named taskCount that has a value > 100 generate a warning
Set-LMDeviceDatasourceInstanceAlertSetting -DatasourceName NoData_Tasks_By_Type_v2 -Name 127.0.0.1 -InstanceName ping -DatapointName taskCount -AlertExpression "> 100"

 

Userlevel 2
Badge

I didn’t even have time to write up an issue!

Thanks Steve. I will test this out tomorrow!

Reply