Dear all, I configured a powershell script which works in my PRTG testing platform installed over a windows 8 Pro with latest powershell version.
Then I translated the working script to my production server but it didn´t work there. The production PRTG server is installed over a Windows 2008 Server R2. I attach here the complete powershell script:
_________________________________________________________________ Param ( [Parameter(mandatory=$True,Position=0)] [string]$Agent ) Import-Module C:\_strap\prtgshell\prtgshell.psm1 $Oper1 = snmpget.exe -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6.1.2.1.2.2.1.8.17" $Oper2 = snmpget.exe -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6.1.2.1.2.2.1.8.18" $Oper3 = snmpget.exe -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6.1.2.1.2.2.1.8.19" $Oper4 = snmpget.exe -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6.1.2.1.2.2.1.8.20" if ($Oper1 -eq "up") { $Oper1 = 0 } ` elseif ($Oper1 -eq "down") { $Oper1 = 1 } ` elseif ($Oper1 -eq "notPresent") { $Oper1 = 2 } ` else { $Oper1 = 3 } if ($Oper2 -eq "up") { $Oper2 = 0 } ` elseif ($Oper2 -eq "down") { $Oper2 = 1 } ` elseif ($Oper2 -eq "notPresent") { $Oper2 = 2 } ` else { $Oper2 = 3 } if ($Oper3 -eq "up") { $Oper3 = 0 } ` elseif ($Oper3 -eq "down") { $Oper3 = 1 } ` elseif ($Oper3 -eq "notPresent") { $Oper3 = 2 } ` else { $Oper3 = 3 } if ($Oper4 -eq "up") { $Oper4 = 0 } ` elseif ($Oper4 -eq "down") { $Oper4 = 1 } ` elseif ($Oper4 -eq "notPresent") { $Oper4 = 2 } ` else { $Oper4 = 3 } $SwitchPorts = ($Oper1,$Oper2,$Oper3,$Oper4) -eq "0" $ActivePorts = $SwitchPorts.Count $XmlOutput = "<prtg>`n" $XmlOutput += Set-PrtgResult "Active Ports" $ActivePorts Active_Ports $XmlOutput += "</prtg>" $XmlOutput _________________________________________________________________
If I execute this script in the powershell interface in production server I can get the following output:
PS C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML> .\prtgshell.ps1 cmdlet prtgshell.ps1 at command pipeline position 1 Supply values for the following parameters: Agent: 11.163.0.68 <prtg> <result> <channel>Active Ports</channel> <value>0</value> <unit>custom</unit> <customunit>Active_Ports</customunit> <showchart>0</showchart> </result> </prtg> PS C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML>
Then in PRTG server when I add the Advanced Script, with the parameter "%host" i get the message:
Error reading response: Invalid XML (XML Parser mismatch: Wanted </<<<>, got </prtg>)
The logs of C:/program data/Paessler/Logs(Sensors) is:
The term 'snmpget.exe' is not recognized as the name of a cmdlet, function, scr ipt file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\prtgshell. ps1:10 char:30 + $Oper1 = snmpget.exe <<<< -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6. 1.2.1.2.2.1.8.17" + CategoryInfo : ObjectNotFound: (snmpget.exe:String) [], Command NotFoundException + FullyQualifiedErrorId : CommandNotFoundException The term 'snmpget.exe' is not recognized as the name of a cmdlet, function, scr ipt file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\prtgshell. ps1:11 char:30 + $Oper2 = snmpget.exe <<<< -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6. 1.2.1.2.2.1.8.18" + CategoryInfo : ObjectNotFound: (snmpget.exe:String) [], Command NotFoundException + FullyQualifiedErrorId : CommandNotFoundException The term 'snmpget.exe' is not recognized as the name of a cmdlet, function, scr ipt file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\prtgshell. ps1:12 char:30 + $Oper3 = snmpget.exe <<<< -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6. 1.2.1.2.2.1.8.19" + CategoryInfo : ObjectNotFound: (snmpget.exe:String) [], Command NotFoundException + FullyQualifiedErrorId : CommandNotFoundException The term 'snmpget.exe' is not recognized as the name of a cmdlet, function, scr ipt file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\prtgshell. ps1:13 char:30 + $Oper4 = snmpget.exe <<<< -Ovq -r 3 -v 2c -c teldat $Agent ".1.3.6. 1.2.1.2.2.1.8.20" + CategoryInfo : ObjectNotFound: (snmpget.exe:String) [], Command NotFoundException + FullyQualifiedErrorId : CommandNotFoundException <prtg> <result> <channel>Active Ports</channel> <value>0</value> <unit>custom</unit> <customunit>Active_Ports</customunit> <showchart>0</showchart> </result> </prtg>
Seems like he can't find the snmpget executable. Can you try adding the path to the scripts runtime environment variable? Like this:
Then, the line...
...should look like this:
All the other calls of snmpget as well. Of course, modify it to suit your path. Then it should find the snmpget.exe at least. Also, please make sure to suppress any other output other than XML.
Jun, 2014 - Permalink