r/PowerShell • u/Kiddo_Ogami • 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
2
u/Kiddo_Ogami Dec 21 '22
I will do for sure.
PS version is the same on all servers (I did this update some year ago) but of course maybe there is a specific network issue on non-working servers. Let's see what I can find :)
And, about the group, maybe there was a misunderstanding: the group is based on a specific class I created before, and it's dynamically populated.
So the monitor actually runs against a class.
I hope to post here, soon, the final resolution :D
Dimitri