This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

PowerShell Component Monitor - Not Defined - Looking for working examples

I've been looking for a solid example of a working PowerShell component monitor. I've been struggling with 'Not Defined' and I've been looking for a solid current example. 

I've located quite a few examples but without success. 

I'm trying to compare to arrays of IP Addresses. 

My Current (not working):

# Query external DNS server and store output as string
# Querying dns.google
$ExtIPs = Resolve-DnsName MyCompany.ca -DnsOnly -server 8.8.8.8 | Select-Object -ExpandProperty IPAddress | Sort-Object -Descending

# Setting the IntIP to match External IPs
$IntIPs = ('7.77.77.207','7.23.98.149')

# Check to see if IPs if are the same
$ListsEqual = $true

IF (diff $IntIPs $ExtIPs)
{
$ListsEqual = $false
Write-Host "Statistic: 1"
Write-Host "Message:" $ListsEqual
exit 1
}
ELSE
{
$ListsEqual = $true
Write-Host "Statistic: 0"
Write-Host "Message:" $ListsEqual
exit 0

  • , an exit code of 1 tells SolarWinds that the script failed to execute, try changing that exit code to 0. also  your $ListEquals for your message nedss to be witihn the quotes, not outside of it. 

  • Thank you Christopher for the reply. I continue to get an "Not Defined" error on test nodes. 

    I've been looking for a sold example of PS Component Monitor code to serve as a guide. I am looking for consistency to know when to use a ; or where to place " " .  The script does work within PowerShell. 

    The monitor checks the external IP addresses for our company and it compares it to our internal values set. If the external IP has changed, I want the monitor to return DOWN.

    Here's the latest attempt (names and IPs are set for generic tests):

    =================

    $ListsEqual = $true
    # Query external CNAME MyCompany.ca and output as string
    [array]$ExtIPs = Resolve-DnsName MyCompany.ca -DnsOnly -server 8.8.8.8 | foreach {$_.IP4Address} | Sort-Object -Descending
    # Setting internal DNS server IPs for MyCompany.ca (2023-03-20)
    [array]$IntIPs = ('1.1.1.1','2.2.2.2')

    # Check to see if IPs if are the same
    $IPMatch = Compare-Object $IntIPs $ExtIPs | ForEach-Object { $_.InputObject}

    $ListsEqual = [string]::IsNullOrWhiteSpace($IPMatch)

    IF ($ListsEqual -eq $false)
    {
    Write-Host "Message:" $($ListsEqual)
    Write-Host "Statistic:" 1
    exit 1
    }
    Write-Host "Statistic:" 0
    Write-Host "Message:" $($ListsEqual)
    exit 0

    ==================

    Any samples of a working PS Component monitor would be greatly appreciated. Thank you.

  • You are missing a closing } on what you posted above. That may be a cut/paste error. There are a few examples you could download in the Content Exchange here. There are also several examples on your local system under  Admin - Settings- Sam Settings - Component Monitor Library

    There are some logs you can check if you enable debugging    Application Monitor test hanging - How to debug? - Forum - Server & Application Monitor (SAM) - THWACK (solarwinds.com)

  • try this.

    $ListsEqual = $true
    # Query external CNAME MyCompany.ca and output as string
    [array]$ExtIPs = Resolve-DnsName MyCompany.ca -DnsOnly -server 8.8.8.8 | foreach {$_.IP4Address} | Sort-Object -Descending
    # Setting internal DNS server IPs for payments.ca (2023-03-20)
    [array]$IntIPs = ('1.1.1.1','2.2.2.2')
    
    # Check to see if IPs if are the same
    $IPMatch = Compare-Object $IntIPs $ExtIPs | ForEach-Object { $_.InputObject}
    
    $ListsEqual = [string]::IsNullOrWhiteSpace($IPMatch)
    
    IF ($ListsEqual -eq $false)
    {
    Write-Host "Message: $($ListsEqual)"
    Write-Host "Statistic: 1" 
    exit 1
    }
    Write-Host "Statistic: 0"
    Write-Host "Message: $($ListsEqual)"
    exit 0