• 0

How to test the existence of a property in a custom query in a custom property on a device in Logicmonitor?


Go to solution Solved by mnagel,

Question

Hello,

How to test the existence of a property in a custom query in a custom property on a group in Logicmonitor?

I tried various syntax but it does not seem to work properly

isWindows() && ip2dns.result

or

isWindows() && exists ("ip2dns.result")

This is not returning anything!!!

Thanks,

Dominique

Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0
  • Solution

As far as I recall, you cannot define a dynamic group using inherited properties.  We have had to do contortions to get around that restriction as well.  You might be forced to create a propertysource that assigns auto.XX properties and then use that to define the dynamic group.  I am not sure why this restriction exists, never have received a satisfactory answer.

Link to post
Share on other sites
  • 1

I have always used the first method, and it is actually documented to work unambiguously (until I checked, I thought perhaps it evaluated it and could be false if the value is 0).  The exists() function says that it will check the values of all properties and is true if one or more have that value.  I don't know when that would be useful :).

Function: exists("<property value>")

This function returns TRUE if the specified value is assigned to any of the resource’s properties.

Function: <property name>

Any property name can be referenced as an AppliesTo function. When used alone, it returns TRUE for any resource which has a value set for the specified property. It can be used with operators for comparison purposes.

 

Link to post
Share on other sites
  • 1
  • Administrators
On 8/15/2020 at 7:10 PM, mnagel said:

As far as I recall, you cannot define a dynamic group using inherited properties.  We have had to do contortions to get around that restriction as well.  You might be forced to create a propertysource that assigns auto.XX properties and then use that to define the dynamic group.  I am not sure why this restriction exists, never have received a satisfactory answer.

You cannot use inherited properties for dynamic grouping. The reason for this is that an inherited property could cause a device to go into a group, which might change the inherited property (because now it's inheriting from a new additional group). This could cause the device to no longer match, causing it to be removed from the group. The removal would reset the property to its original state that matches the dynamic group rule, causing it to be added back in, causing it to inherit the property that removes it from the group. You get an infinite loop of adding then removing from the group.

Link to post
Share on other sites
  • 1
26 minutes ago, Stuart Weenig said:

You cannot use inherited properties for dynamic grouping. The reason for this is that an inherited property could cause a device to go into a group, which might change the inherited property (because now it's inheriting from a new additional group). This could cause the device to no longer match, causing it to be removed from the group. The removal would reset the property to its original state that matches the dynamic group rule, causing it to be added back in, causing it to inherit the property that removes it from the group. You get an infinite loop of adding then removing from the group.

Yes, understood,  but most often it would be beneficial to allow (with some sort of rapid add/remove iteration blocker) and you must go through contortions to get around the restriction. Like copying a property to an auto.X property via a propertysource.  In this scenario, it would behave the same, just perhaps slower :).  I would be fine if the system disabled all dynamic groups associated with a device until the add/remove rate dropped to zero.

Link to post
Share on other sites
  • 1
  • Administrators
2 minutes ago, mnagel said:

Yes, understood,  but most often it would be beneficial to allow (with some sort of rapid add/remove iteration blocker) and you must go through contortions to get around the restriction. Like copying a property to an auto.X property via a propertysource.  In this scenario, it would behave the same, just perhaps slower :).  I would be fine if the system disabled all dynamic groups associated with a device until the add/remove rate dropped to zero.

Totally agree. 

Link to post
Share on other sites
  • 0
Posted (edited)

Hello,

I am doing a test on a property "Ip2dns.accessid"

507719356_2020-08-15_16-47-21DeviceInfoProperty.thumb.png.2f314163ea3bb202df3a1fbc3430b1c3.png

the property is listed on the device...

For the dynamic group I have

1521214855_2020-08-15_16-45-07DeviceInfo01.thumb.png.3c85a63f5896a9eb0ba7f50227d9fb73.png

 

isWindows() && ip2dns.accessid

but the dynamic group remains empty, why??? 

1100804667_2020-08-15_16-45-49DeviceInfo02.thumb.png.1c82a81585d772e41944933312abe353.png

Thanks,

Dominique

Edited by Dominique
Link to post
Share on other sites
  • 0

The original one "ip2dns.result" is a propertysource and is set to auto.ip2dns.result, I was able to populate the dynamic group iswindows() && !ip2dns.result with the devices but I have always the iswindows() && ip2dns.result group empty...

I was trying to test on a regular property but if it is not possible I am going back to the PropertySource original done. Let me check again...

Thanks,

Dom

Link to post
Share on other sites
  • 0

Hello,

#########################      API Function Script      #########################
#------------------------------------------------------------------------------------------------------------
# Prerequisites:
#
#Requires -Version 3
#------------------------------------------------------------------------------------------------------------
# Initialize Variables
<# account info #>
$accessId = '##IP2DNS.ACCESSID##'
$accessKey = '##IP2DNS.KEY##'
$company = 'uclahealth'

# Functionize the reusable code that builds and executes the query
function Send-Request() {
    Param(
        [Parameter(position = 0, Mandatory = $true)]
        [string]$path,
        [Parameter(position = 1, Mandatory = $false)]
        [string]$httpVerb = 'GET',
        [Parameter(position = 2, Mandatory = $false)]
        [string]$queryParams,
        [Parameter(position = 3, Mandatory = $false)]
        [PSObject]$data
    )
    # Use TLS 1.2
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    <# Construct URL #>
    $url = "https://$company.logicmonitor.com/santaba/rest$path$queryParams"
    <# Get current time in milliseconds #>
    $epoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end (Get-Date).ToUniversalTime()).TotalMilliseconds)
    <# Concatenate Request Details #>
    $requestVars = $httpVerb + $epoch + $data + $path
    <# Construct Signature #>
    $hmac = New-Object System.Security.Cryptography.HMACSHA256
    $hmac.Key = [Text.Encoding]::UTF8.GetBytes($accessKey)
    $signatureBytes = $hmac.ComputeHash([Text.Encoding]::UTF8.GetBytes($requestVars))
    $signatureHex = [System.BitConverter]::ToString($signatureBytes) -replace '-'
    $signature = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($signatureHex.ToLower()))
    <# Construct Headers #>
    $auth = 'LMv1 ' + $accessId + ':' + $signature + ':' + $epoch
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Authorization", $auth)
    $headers.Add("Content-Type", 'application/json')
    $headers.Add("X-version", '2')
    <# Make request & retry if failed due to rate limiting #>
    $Stoploop = $false
    do {
        try {
            <# Make Request #>
            $response = Invoke-RestMethod -Uri $url -Method $httpVerb -Body $data -Header $headers
            $Stoploop = $true
        } catch {
            switch ($_) {
                { $_.Exception.Response.StatusCode.value__ -eq 429 } {
#                    Write-Host "Request exceeded rate limit, retrying in 60 seconds..."
                    Start-Sleep -Seconds 60
                    $response = Invoke-RestMethod -Uri $url -Method $httpVerb -Body $data -Header $headers
                }
                { $_.Exception.Response.StatusCode.value__ } {
#                    Write-Host "Request failed, not as a result of rate limiting"
                    # Dig into the exception to get the Response details.
                    # Note that value__ is not a typo.
#                    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
#                    Write-Host "StatusDescription:" $_.Exception.Response.StatusCode
#                    $_.ErrorDetails.Message -match '{"errorMessage":"([\d\S\s]+)","errorCode":(\d+),'
#                    Write-Host "LM ErrorMessage" $matches[1]
#                    Write-Host "LM ErrorCode" $matches[2]
                    $response = $null
                    $Stoploop = $true
                }
                default {
#                    Write-Host "An Unknown Exception occurred:"
#                    Write-Host $_ | Format-List -Force
                $response = $null
                $Stoploop = $true
            }
        }
    }
} While ($Stoploop -eq $false)
Return $response
}
##
#------------------------------------------------------------------------------------------------------------
#  Starting Script 
#------------------------------------------------------------------------------------------------------------
##
$deviceID = '##SYSTEM.DEVICEID##'
$currentName = '##SYSTEM.HOSTNAME##'
$currentDisplayName = '##SYSTEM.DISPLAYNAME##'
$oldResult = '##AUTO.IP2DNS.RESULT##'
$oldIP = '##AUTO.IP2DNS.OLDIP##'

if ($currentName -ne $currentDisplayName) {
  #Request Info
  $httpVerb = 'PATCH'
  $resourcePath = "/device/devices/$($deviceID)"
  $queryParams = '?patchFields=name'
  $data = "{`"name`":`"$($currentDisplayName)`"}"
  $results = Send-Request $resourcePath $httpVerb $queryParams $data
  Write-Host "ip2dns.debug=Send-Request $($resourcePath) $($httpVerb) $($queryParams) $($data)"
  Write-Host "ip2dns.result=Changed IP $($currentName) to DNS $($currentDisplayName): $($results)"
  Write-Host "ip2dns.oldIP=$($currentName)"
} else {
  if ($oldResult -like "No change to IP*"){
      Write-Host "ip2dns.result=$($oldResult)"
  } else {
      Write-Host "ip2dns.result=No change to IP. $($oldResult)"
  }
  Write-Host "ip2dns.oldIP=$($oldIP)"
}

So I will test the existence of ip2dns.result, am I correct?

Thanks,

Dominique

Link to post
Share on other sites
  • 0
38 minutes ago, Stuart Weenig said:

This property is not an inherited property though, so 


isWindows() && !auto.ip2dns.result

should work.

 

I forgot to add the auto I was using !ip2dns.result, I will try when the property source will be reactivated !auto.ip2dns.result.

Thanks

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.