Skip to content

New-LMAlertRule Not Handling Hashtable Correctly #83

@aggie87

Description

@aggie87

Trying to use the New-LMAlertRule function to add a rule that has a -ResourceProperties associated with it. A simple command below results in the debug that follows:

New-LMAlertRule -Name Test -Priority 70000 -ResourceProperties @{"test"="value"} -EscalatingChainId 2 -Debug

DEBUG: ============ LogicMonitor API Debug Info ==============
DEBUG: Command: New-LMAlertRule | Method: POST | Timestamp: 2026-01-13 14:54:07.984
DEBUG: Parameters: Name: Test | Priority: 70000 | ResourceProperties: {test} | EscalatingChainId: 2 | Debug: True
DEBUG: Endpoint: /santaba/rest/setting/alert/rules
DEBUG: Portal: xxxxsandbox.logicmonitor.com
DEBUG: Headers: User-Agent: Logic.Monitor-PowerShell-Module/7.7.5 | Content-Type: application/json | Authorization: LMv1 XXXXXXX| X-Version: 3
DEBUG: Request Payload:
DEBUG:     {
DEBUG:         "priority":  70000,
DEBUG:         "name":  "Test",
DEBUG:         "escalatingChainId":  2,
DEBUG:         "resourceProperties":  {
DEBUG:                                    "test":  "value"
DEBUG:                                },
DEBUG:         "levelStr":  "All"
DEBUG:     }
DEBUG: ========================================================
New-LMAlertRule : Invalid json body - Cannot deserialize value of type `java.util.ArrayList` from Object value (token `JsonToken.START_OBJECT`)
At line:1 char:1
+ New-LMAlertRule -Name Test -Priority 70000 -ResourceProperties @{"tes ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (https://lphsand...ing/alert/rules:String) [New-LMAlertRule], LMException
    + FullyQualifiedErrorId : LMAPIError.ClientError,New-LMAlertRule

There are a couple of issues with the Debug results as it relates to the resourceProperties object.

  1. it should be an array object of hashes []
  2. the hash itself should be in the format name:, value: as noted below:
    "resourceProperties": [
        {
        "name":"test",
        "value":"value"
        }
    ],

When I put this in Postman it works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions