New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate Hash Tabel entries #12
Comments
Hi @bvanbavel, This is a bit of a problem! So there are multiple ways to create a set of raw sensor parameters in PrtgAPI:
By accessing the underlying parameter set (demonstrated below) it is possible to achieve the functionality you desire. It is expected you cannot specify a trafficmode more than once in a hashtable, however the bigger issue is that when you interface with a The core issue is that the In C# this isn't too hard var parameters = RawSensorParameters("Traffic", "snmptraffic");
parameters.Parameters.Add(new CustomParameter("trafficmode_", "errors");
parameters.Parameters.Add(new CustomParameter("trafficmode_", "discards"); But in PowerShell it is a lot more tedious C:\> $params = New-SensorParameters -Empty
C:\> $params.Name = "Traffic"
C:\> $params.SensorType = "snmptraffic"
C:\> $params.Parameters.Add((New-Object PrtgAPI.Parameters.CustomParameter "trafficmode_","errors"))
C:\> $params.Parameters.Add((New-Object PrtgAPI.Parameters.CustomParameter "trafficmode_","discards"))
C:\> $params.Parameters
Name Value
---- -----
name_ Traffic
trafficmode_ errors
trafficmode_ discards Of course, if you just wrap the addition of raw custom parameters up in a function there's almost no issue! function AddParam($params, $name, $val)
{
$params.Parameters.Add((New-Object PrtgAPI.Parameters.CustomParameter $name,$val))
}
AddParam $params "trafficmode_" "errors"
AddParam $params "trafficmode_" "discards" A potential solution to this could potentially be to create a new type, I will have a think about this and try and implement a solution within the next few days Note: depending on your use case you may want to consider using dynamic sensor parameters instead of constructing parameters manually (however for now you will still have the duplicate trafficmode issue) Regards, |
Dear Lordmilko, I created the following code, but unfortunatly is does not add the variable for me: Result: Kind regards, Bart |
Hi @bvanbavel, There was a typo in my original response; if you type Name Value
---- -----
name_
interfacenumber_ 1
interfacenumber__check
trafficmode_ standinfornoselection
trafficmode_ errors
trafficmode_ discards
monitorstate_ 1 Note that you don't have to create a new $params = New-SensorParameters -Empty
$params.Name = "$($interface.name)"
$params.SensorType = "snmptraffic"
$params["interfacenumber_"] = 1
$params["interfacenumber__check"] = "$($interface.properties -join '|')"
$params["monitorstate_"] = 1
"standinfornoselection","errors","discards" | foreach { $params.Parameters.Add((New-Object PrtgAPI.Parameters.CustomParameter "trafficmode_",$_)) } Note you might have some issues with your interfacenumber__check value, as I have a feeling It'll need to be in the form Regards, |
You're right, it worked! Powershell ISE autocomplete didn't help as it tried to correct $params.Parameters into $params.getparameter(). Script is ready to be used for my customer migration this week. |
…meter -Raw/Dynamic custom parameters now use ParameterType.MultiParameter by default -Implemented support for modifying multi parameter properties with Set-ObjectProperty -Raw parameters now show all selected checkbox values when a field contain multiple values. If no checkboxes are selected, an empty string is displayed For #12
Hi @bvanbavel, PrtgAPI 0.8.4 has now been released.
All As such, it is now possible to create raw SNMP Traffic parameters as follows $params = New-SensorParameters -Empty
$params.Name = "$($interface.name)"
$params.SensorType = "snmptraffic"
$params["interfacenumber_"] = 1
$params["interfacenumber__check"] = "$($interface.properties -join '|')"
$params["monitorstate_"] = 1
$params["trafficmode_"] = "standinfornoselection","errors","discards" or, via a hashtable $table = @{
name_ = "Base Sensor"
sensortype = "snmptraffic"
interfacenumber_ = 1
interfacenumber__check = ("$($interface.properties -join '|')") + "|"
monitorstate_ = 1
trafficmode_ = "standinfornoselection","errors","discards"
}
$params = New-SensorParameters $table I have also fixed a bug wherein it was not possible to enumerate all enabled trafficmode values on existing SNMP Traffic sensor via You can update PrtgAPI by running Please see the release notes to be aware of any breaking changes Given your existing script appears to have been tested and working however, it may be worth holding off upgrading until after your migration has completed Regards, |
Great, Thanks again for the great help! The workaround also worked perfectly. We had a smooth migration last week! Regards, Bart |
When creating a raw sensor the hashtabel will not acces duplicate entries. This seems required when adding an snmptraffic sensor and you want to enable errors and discards. Fiddler shows the option Trafficmode_ is added three times:
&trafficmode_=standinfornoselection
&trafficmode_=errors
&trafficmode_=discards
This seems not possible with the API.
The text was updated successfully, but these errors were encountered: