lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

Changing the "Default Limits" on the general tab on "wmidiskspace" sensors #265

Closed xasz closed 2 years ago

xasz commented 2 years ago

What's going on?

Hello lordmilko,

i am trying to get / set the default limits of an wmidiskspace settings which are listed on the settings tab on the prtg: image I have checked the New-SensorParameters:


> $device | New-SensorParameters -RawType wmidiskspace | fl

drive             : All
Targets           : {}
Source            : MyDeviceName
SensorType        : wmidiskspace
Priority          : Three
InheritTriggers   : True
InheritInterval   : True
Interval          : 00:01:00
IntervalErrorMode : OneWarningThenDown
DynamicType       : False
Name              : WMI Laufwerkskapazität (mehrfach) 1
Tags              : {diskspacesensor, wmidiskspacesensor}
Cookie            : False

Checked with the Get-Object on the sensor:

Get-Object -Id 138225 | fl # This is an wmidiskpacesensor

Id          : 138225
ParentId    : 136546
Name        : Laufwerke
Tags        : {diskspacesensor, wmidiskspacesensor, Laufwerke, PRTGAPIv2}
DisplayType : WMI Laufwerkskapazität (mehrf.)
Type        : Sensor (wmidiskspace)
Active      : True

Checked with the Get-Sensor on the sensor:

Get-Sensor -Id 138225 | fl # This is an wmidiskpacesensor

Probe              : MyProbe
Group              : MyGroup
Favorite           : False
DisplayLastValue   : 20 %
LastValue          : 20
Device             : MyDevice
Downtime           : 0
TotalDowntime      : 00:00:00
DownDuration       :
Uptime             : 100
TotalUptime        : 00:20:00
UpDuration         : 00:22:58
TotalMonitorTime   : 00:00:00
DataCollectedSince : 27.01.2022 09:17:42
LastCheck          : 27.01.2022 09:37:42
LastUp             : 27.01.2022 09:37:42
LastDown           :
MiniGraph          : 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                     ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
                     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,6,6,6|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 
                     ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
                     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Schedule           :
BaseType           : Sensor
Url                : /sensor.htm?id=138225
NotificationTypes  : Inheritance: False, State: 0, Threshold: 0, Change: 0, Speed: 0, Volume: 0
Interval           : 00:05:00
InheritInterval    : False
Access             : Full
Dependency         : MyDevice
Position           : 4
Status             : Warning
Comments           :
Priority           : Three
Message            : 20 % (Freier Platz C:) liegt unter dem Grenzwert für Warnungen von 25 % in Freier Platz C:
Id                 : 138225
ParentId           : 136546
Name               : Laufwerke
Tags               : {diskspacesensor, wmidiskspacesensor, Laufwerke, PRTGAPIv2}
DisplayType        : WMI Laufwerkskapazität (mehrf.)
Type               : Sensor (wmidiskspace)
Active             : True

But i could not figure out if or how i could change these values. I appreciate any help or hint and thank you again for your nice work.

Due Dilligance

lordmilko commented 2 years ago

Hi @xasz,

It looks like these settings can only be changed after the object has been created; therefore the cmdlets you are looking for are Get-ObjectProperty and Set-ObjectProperty respectively

C:\ Get-Sensor -Id 2061 | Get-ObjectProperty -Raw

name                            : Disk Free (Paused Sensor)
parenttags                      : C_OS_VMware TestGroup TestProbe
tags                            : diskspacesensor wmidiskspacesensor
limitpercent                    : 0
upperlimiterrorpct              :
upperlimitwarningpct            :
lowerlimitwarningpct            :
lowerlimiterrorpct              :
limitbytes                      : 0
upperlimiterrorbyte             :
upperlimiterrorbyte__factor     : 9.5367431640625E-7
upperlimitwarningbyte           :
upperlimitwarningbyte__factor   : 9.5367431640625E-7
lowerlimitwarningbyte           :
lowerlimitwarningbyte__factor   : 9.5367431640625E-7
lowerlimiterrorbyte             :
lowerlimiterrorbyte__factor     : 9.5367431640625E-7
erroronmissingdisk              : 0
writeresult                     : 0
stack                           : 0
...

To modify these properties you'll need to construct a request specifying all of the required raw parameters

C:\ Get-Sensor -Id 2061 | Set-ObjectProperty -RawParameters @{
    limitpercent_ = 1
    upperlimiterrorpct_ = 30
} -Force

Don't forget to add the trailing underscore to each property name!

Note that if you wish to modify the byte limit of the sensor rather than percent you'll need to specify the factor as well (might be easiest to store the output of Get-ObjectProperty -Raw in a variable and pull the relevant factors from the variable rather than hard coding any particular value)

For more information please see the wiki

Regards, lordmilko

xasz commented 2 years ago

Thank your lordmilko - that helped alot.

For anyone who exactly does need this, this works fine for me and as far as i have seen have not caused any trouble:

$param = $prtgDevice | New-SensorParameters -RawType wmidiskspace
$param.Name = $SensorName
# some more settings
$prtgDevice | Add-Sensor $param | Set-ObjectProperty -RawParameters @{lowerlimitwarningpct_ = 15; lowerlimiterrorpct_ = 15} -Force