lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

Creating Sensors (ping) #133

Closed schoenm1 closed 4 years ago

schoenm1 commented 4 years ago

I found your Powrshell PRTGAPI today. Great work! A lot of feature I was looning for I found in wiki. But can you tell me how I can create some basic ping Sensors (not copy, but create new). I was not able to do this. (Sensortype?) Regards Micha

Due Dilligance Please enter an 'x' between the brackets to indicate you have done these

lordmilko commented 4 years ago

Hi @schoenm1,

Please see the wiki for information on creating new sensors.

In the case of Ping sensors, you can create these by using a set of Dynamic Sensor Parameters.

Please let me know if you have any specific issues with any of the specific steps

Regards, lordmilko

schoenm1 commented 4 years ago

Hi @lordmilko Thanks for your help. I'm now able to create a new pingsensor. :-) $param = Get-Device PS-Switch | New-SensorParameters -RawType ping $param.size = 16 $param.Interval = "01:00:00" $param.Name = "Ping [Master] param" $param.tags = "pingsensor, Ping, Test-Tag" $param.AutoAcknowledge = "False" Get-Device PS-Switch | Add-Sensor $param

But I can not add some more parameters like DependencyType: PS C:\WINDOWS\system32> $param.DependencyType = "MasterObject" Parameter with name 'DependencyType' does not exist. To add new parameters object must first be unlocked.[...]

But if I change the parameter manually on the sensor and GetObjectProperty, I see the parameter. How can I add custom parameters to e.g. a PingSensor, which I assume these param are not implemented in your PowerShell Library. Get-Sensor -Id 2155 | Get-ObjectProperty
...
DependencyType : MasterObject ... Regards Micha

lordmilko commented 4 years ago

Hi @schoenm1,

PrtgAPI dynamically calculates DynamicSensorParameters by querying the parameters that would normally be present when you try and create the sensor in the PRTG UI. In the case of Ping sensors, you can see that there is no option in the UI for specifying dependency type during object creation; as such this has to be done after the object has been created.

As PrtgAPI does not yet natively support modifying the properties of the Schedules, Dependencies and Maintenance Window section, to set this property you need to specify a collection of raw parameters

To create a new ping sensor with the Master Sensor dependency type, you can use the following code

$param = Get-Device PS-Switch | New-SensorParameters -RawType ping
$param.size = 16
$param.Interval = "01:00:00"
$param.Name = "Ping [Master] param"
$param.tags = "pingsensor, Ping, Test-Tag"

$sensor = Get-Device PS-Switch | Add-Sensor $param

$sensor | Set-ObjectProperty -RawParameters @{
    scheduledependency = 0
    dependencytype_ = 2
} -Force

Also note that in your code you had the following

$param.AutoAcknowledge = "False"

This is illegal. If you attempt to create a sensor with this value you will find that the sensor is set to neither auto-acknowledge or don't auto-acknowledge. As per the wiki

Native (and therefore type safe) properties can be identified as those containing uppercase letters, whereas those specific to a particular sensor type are all lowercase.

In the case of the autoacknowledge property, its default value was 0 (false). Valid values for this would therefore be 0 (false) or 1 (true). False is a boolean value, and as PrtgAPI as no idea what type each dynamic property is supposed to use, it won't help convert your value into the required internal value of 0 or 1. Generally speaking you won't need to modify most properties of sensor parameters, and can leave them with their default values

Regards, lordmilko

schoenm1 commented 4 years ago

Hi lordmilko Thanks for your help. Ping Sensor is working now. Other question: If I try to add e.g. all Traffic Sensors. Get-Device PS-Switch | New-SensorParameters -RawType snmptraffic will show only the first value of the interface: interfacenumber : 1 interfacenumber__check : (001) Vlan1 Traffic trafficmode : errors monitorstate : 0 namein : Traffic In ... Adding with WebGUI, i see all interfaces: image How can I get multiple interfaces as a reply of the command Get-Device PS-Switch | New-SensorParameters -RawType snmptraffic Regards Micha

lordmilko commented 4 years ago

Specify the sensor targets