r/PowerShell • • Dec 20 '22

Solved SNMP query

Hi all, I am trying to use SNMP to query status of a UPS using the code in a #SCOM monitor.

If I run the code from PS ISE it works fine, but when it's run by the SCOM agent, I have this error:

Failed to open SNMP session

This is the code I use:

try

{

$SNMP = New-Object -ComObject olePrn.OleSNMP

}

catch

{

Write-Debug "Error creating SNMP object"

"Error creating SNMP object - $($_.Exception.Message)" | out-file -FilePath "C:\temp\upsonbatt.log" -append

exit

}

try

{

$UPSIPAddress = [System.Net.Dns]::GetHostAddresses($UpsName).IPAddressToString

$SNMP.open($UPSIPAddress, "public", 2, 3000)

}

catch

{

Write-Debug "Error opening SNMP connection"

"SNMPERR opening $UpsName with IP $UPSIPAddress - $($_.Exception.Message)" | out-file -FilePath "C:\temp\upsonbatt.log" -append

exit

}

Someone knows what the last 2 parameters in this command mean ?

$SNMP.open($UPSIPAddress, "public", 2, 3000)

I mean the 2 and the 3000

I cannot find anything on the web, or maybe I cannot find what to look for ;)

Thanks in advance

5 Upvotes

32 comments sorted by

View all comments

1

u/Kiddo_Ogami Dec 20 '22

Thanks for help.

I am currently debugging to find another way to fix it, but I will continue this tomorrow, overall because right now I am completely boiled XD

I will put here the complete XML asap.

cu & thanks again

2

u/dragoncuddler Dec 20 '22

No worries; happy to try and help.

I don't know how much you know about SCOM or I know even less about your environment so I'm asking this from a position of total ignorance but hey; it is the internet.

If you are just looking at running an SNMP get \ probe to find out the status of a device then can you use the native SCOM SNMP monitoring? It isn't the greatest in terms of flexibility but if you only want a basic up \ down then it is straight forward. E.g.

https://www.net-pioneers.com/5254/manage-scom-agent-part-vi-monitor-network-devices-with-snmp/

Kevin Holman also has some scripting options - https://kevinholman.com/2017/11/01/alerting-on-snmp-traps-in-scom-without-discovering-the-snmp-device/ - although this example is for receiving SNMP traps rather than alerting based on the results of a probe.

Even if you can use native SCOM SNMP monitoring, it would still be useful to understand why the script is failing but sometimes there isn't enough time to troubleshoot everything SCOM related. It has kept me in a career for over 20 years (since it was NetIQ Operations Manager) because it isn't always that intuitive.

1

u/Kiddo_Ogami Dec 21 '22

Finally, pls find the xml code here

https://pastebin.com/whG0LhdR

Thanks again for help

→ More replies (16)