Dies ist eine alte Version des Dokuments!
Install-Package PrtgAPI -Source PSGallery Import-Module PrtgAPI # Erstellen der Anmeldeinformationen $username = "username" $password = "password" | ConvertTo-SecureString -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential($username, $password) # Verbindung herstellen Connect-PrtgServer -Server $server -Credential $credential -IgnoreSSL # Sensoren suchen #Get-Sensor "Commvault Backup Status *" | select-object * # Devices suchen #Get-Device | select-object * | where-object { $_.Name -like "*sql04*" } # Sensor erstellen <# $raw = @{ name_ = "my test sensor" tags_ = "xmlexesensor" priority_ = 4 exefile_ = "MyCustomSensorScript.ps1" exeparams_ = "-ClientName `"vie-t-srv-audit`" -DBName `"testdb`" -DeltaTime 86400" environment_ = 1 usewindowsauthentication_ = 1 mutexname_ = "testMutex" timeout_ = 70 writeresult_ = 1 intervalgroup = 0 interval_ = "21600" errorintervalsdown_ = 2 sensortype = "exexml" } $params = New-SensorParameters $raw Get-Device "devicename" | Add-Sensor $params #> # Verbindung trennen Disconnect-PrtgServer
Ein Custom Script Sensor kann XML oder JSON ausgeben. Die äußersten Tags (prtg) markieren das Gesamtergebnis. Die einzelnen „result“ Einträge sind „Channels“ in PRTG. Jede5rf Channel hat seine eigenen Einstellungen. Im PRTG Bereich kann man noch allgemeine Informationen in Tags angeben. Mehr zu Tags weiter unten.
XML und JSON Beispiel mit Powershell
$ProcessCount = (Get-Process).Count $UserCount = (query user | Measure-Object).Count - 1 $tasks = (tasklist | Measure-object).Count $XMLResult = @" <prtg> <result> <channel>Task Count</channel> <value>$($tasks)</value> <unit>Custom</unit> <customUnit>Tasks</customUnit> </result> <result> <channel>Process Count</channel> <unit>Custom</unit> <customunit>Processes</customunit> <mode>Absolute</mode> <showChart>1</showChart> <showTable>1</showTable> <warning>0</warning> <float>1</float> <value>$($ProcessCount)</value> <LimitMaxError>120</LimitMaxError> <LimitMaxWarning>80</LimitMaxWarning> <LimitWarningMsg>My custom note for warnings</LimitWarningMsg> <LimitErrorMsg>My custom note for errors</LimitErrorMsg> <LimitMode>1</LimitMode> </result> <result> <channel>User Sessions</channel> <unit>Custom</unit> <CustomUnit>User</CustomUnit> <mode>Absolute</mode> <showChart>1</showChart> <showTable>1</showTable> <warning>0</warning> <float>0</float> <value>$($UserCount)</value> </result> <text>Demo values. OS: $($env:OS)</text> </prtg> "@ $JsonResult = @" { "prtg": { "result": [ { "channel": "Task Count", "value": "$($tasks)", "unit": "custom", "customunit": "Tasks" }, { "channel": "Process Count", "unit": "cusom", "customunit": "Processes", "mode": "Absolute", "showChart": "1", "showTable": "1", "warning": "0", "float": "1", "value": "$($ProcessCount)", "LimitMaxError": "120", "LimitMaxWarning": "80", "LimitWarningMsg": "My custom note for warnings", "LimitErrorMsg": "My custom note for errors", "LimitMode": "1" }, { "channel": "User Sessions", "unit": "Custom", "customunit": "User", "mode": "Absolute", "showChart": "1", "showTable": "1", "warning": "0", "float": "0", "value": "$($UserCount)" } ], "text": "Demo values. OS: $($env:OS)" } } "@ $JsonResult
Placeholder | Description |
---|---|
%sensorid | The ID of the EXE/Script sensor. |
%deviceid | The ID of the device the sensor is created on. |
%groupid | The ID of the group the sensor is created in. |
%probeid | The ID of the probe the sensor is created on. |
%host | The IP address/DNS name of the device the sensor is created on. |
%device | The name of the device the sensor is created on. |
%group | The name of the group the sensor is created in. |
%probe | The name of the probe the sensor is created on. |
%name | The name of the EXE/Script sensor. |
%windowsdomain | The domain for Windows access (can be inherited from parent). |
%windowsuser | The user name for Windows access (can be inherited from parent). |
%windowspassword | The password for Windows access (can be inherited from parent). |
%linuxuser | The user name for Linux access (can be inherited from parent). |
%linuxpassword | The password for Linux access (can be inherited from parent). |
%snmpcommunity | The community string for SNMP v1 or v2 (can be inherited from parent). |
TAG | MANDATORY | DESCRIPTION | POSSIBLE CONTENT |
---|---|---|---|
<Text> | No | Text the sensor returns in the Message field with every scanning interval. | This element has to be provided outside of the <result> element. There can be one message per sensor, regardless of the number of channels. The default message is OK. Any string.Maximum length: 2000 characters. PRTG does not support the number sign (#) in sensor messages. If a message contains a number sign, PRTG clips the message at this point. |
<Error> | No | If enabled, the sensor returns the Down status. | This element has to be provided outside of the <result> element. A sensor in this error status cannot return any data in its channels. If used, all channel values in the <result> section are ignored. The default is 0. 0 (= no), 1 (= yes, set sensor to error; ignore <result> section) |
Tags im Result Bereich
TAG | MANDATORY | DESCRIPTION | POSSIBLE CONTENT |
---|---|---|---|
<Channel> | Yes | Name of the channel as displayed in user interfaces. | This parameter is required and must be unique for the sensor. |
<Value> | Yes | The value as integer or float. | Make sure the <Float> setting matches the kind of value provided. Otherwise PRTG shows 0 values. |
<Unit> | No | The unit of the value. The default is Custom. | BytesBandwidth, BytesDisk, Temperature, Percent, TimeResponse, TimeSeconds, Custom, Count, CPU, BytesFile, SpeedDisk, SpeedNet, TimeHours |
<CustomUnit> | No | If Custom is used as unit, this is the text displayed behind the value. | Any string (keep it short) |
<SpeedSize> | No | Size used for the display value. | One, Kilo, Mega, Giga, Tera, Byte, KiloByte, MegaByte, GigaByte, TeraByte, Bit, KiloBit, MegaBit, GigaBit, TeraBit |
<SpeedTime> | No | See above, used when displaying the speed. The default is Second. | Second, Minute, Hour, Day |
<Mode> | No | Select if the value is an absolute value or counter. The default is Absolute. | Absolute, Difference |
<Float> | No | Define if the value is a float. The default is 0 (no). | Define decimal places with the <DecimalMode> element. |
<DecimalMode> | No | Init value for the Decimal Places option. | You can change this initial setting later in the sensor's channel settings. |
<Warning> | No | If enabled for at least one channel, the entire sensor is set to the Warning status. | 0 (= no), 1 (= yes) |
<ShowChart> | No | Init value for the Show in graphs option. | 0 (= no), 1 (= yes) |
<ShowTable> | No | Init value for the Show in tables option. | 0 (= no), 1 (= yes) |
<LimitMaxError> | No | Define an upper error limit for the channel. | String with numbers |
<LimitMaxWarning> | No | Define an upper warning limit for the channel. | String with numbers |
<LimitMinWarning> | No | Define a lower warning limit for the channel. | String with numbers |
<LimitMinError> | No | Define a lower error limit for the channel. | String with numbers |
<LimitErrorMsg> | No | Define an additional message for lower error limits. | Any string |
<LimitWarningMsg> | No | Define an additional message for lower warning limits. | Any string |
<LimitMode> | No | Define if the limit settings defined above are active. | 0 (= no), 1 (= yes) |
<ValueLookup> | No | Define if you want to use a lookup file. | Any string |
<NotifyChanged> | No | Triggers a change notification for the channel. | No content required |