i'm using net-snmp extension features to be able to run a powershell script when i query a specific SNMP oid.
snmpd is configured to run a get-storageinfo.ps1 script with some parameters.
the script is being invoked like this by the net-snmp agent:
& c:\scripting\get-storageinfo.ps1 -name somedevicename -detaillevel 2 -oid oidstring
however, things break when i add parameter attributes or CmdletBinding (or both) to my parameter definitions in my get-storageinfo.ps1 script. I don't understand why. I have this at the very top of my script (after some comments actually).
[CmdletBinding()]
Param(
[string]$name,
[string]$detaillevel
[string]$oid
)
or this, same problem
Param(
[Parameter(Mandatory=$True)][string]$name,
[string]$detaillevel
[string]$oid
)
This breaks my snmpd functionality somehow. When the configured OID is being read, i get: "No Such Instance currently exists at this OID"
The following (and only this) works perfectly, without CmdletBinding and parameter attributes at all:
Param(
[string]$name,
[string]$detaillevel
[string]$oid
)
This returns values back to net-snmp just the way it's supposed to do. Net-SNMP (snmpd) is perfectly fine with running the script and returning values when the script is used without the attributes / cmdletbinding. Because of this, i know the arguments are being passed properly by the calling program (snmpd). Problem has to be specific to the attributes or cmdletbinding.
What could be a possible difference between these two declarations regarding the output to a external program like net-snmp? i can't figure out the difference.
UPDATE I've reverted back to the "extend" command of snmpd.conf istead of the "pass" commando. The pass command had no consistent results. I guess i don't understand its usage that well. The extend command has no problems as described earlier. It's a bit weird still, but i'm going forward with "extend".