Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
|
prtg [2024/07/27 14:11] |
prtg [2024/07/27 22:46] (aktuell) |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | =====PrtgAPI===== | ||
| + | Für [[coding: | ||
| + | |||
| + | <code powershell> | ||
| + | Install-Package PrtgAPI -Source PSGallery | ||
| + | Import-Module PrtgAPI | ||
| + | </ | ||
| + | |||
| + | Verbindung mit Anmeldeinformationen aufbauen | ||
| + | <code powershell> | ||
| + | # Verbindung mit Anmeldeinformationen | ||
| + | $username = " | ||
| + | $password = " | ||
| + | $credential = New-Object System.Management.Automation.PSCredential($username, | ||
| + | Connect-PrtgServer -Server $server -Credential $credential -IgnoreSSL | ||
| + | </ | ||
| + | |||
| + | Verbindung mit Passhash aufbauen | ||
| + | <code powershell> | ||
| + | # Verbindung mit PassHash herstellen | ||
| + | # Statt Passwort den Passhash als Passwort angeben und Parameter -PassHash anhängen | ||
| + | $username = " | ||
| + | $password = " | ||
| + | $credential = New-Object System.Management.Automation.PSCredential($username, | ||
| + | Connect-PrtgServer -Server $server -Credential $credential -PassHash -IgnoreSSL | ||
| + | </ | ||
| + | |||
| + | Verbindung trennen | ||
| + | <code powershell> | ||
| + | # Verbindung trennen | ||
| + | Disconnect-PrtgServer | ||
| + | </ | ||
| + | |||
| + | <code powershell> | ||
| + | Get-Probe | ||
| + | |||
| + | Get-Device | where-object { $_.Name -like " | ||
| + | |||
| + | Get-Sensor | where-object { $_.Name -like " | ||
| + | Get-Sensor -Id 22243 | Get-ObjectProperty -Raw | ||
| + | Get-Sensor -Id 22243 | Set-ObjectProperty -interval (60*60*6) | ||
| + | Get-SensorHistory -Sensor (Get-Sensor -Id 22243) | ||
| + | </ | ||
| + | |||
| + | Sensoren suchen | ||
| + | <code powershell> | ||
| + | # Sensoren suchen | ||
| + | Get-Sensor " | ||
| + | </ | ||
| + | |||
| + | Deviced suchen | ||
| + | <code powershell> | ||
| + | # Devices suchen | ||
| + | Get-Device | select-object * | where-object { $_.Name -like " | ||
| + | </ | ||
| + | |||
| + | Custom Sensor erstellen | ||
| + | <code powershell> | ||
| + | # Custom Sensor erstellen | ||
| + | $raw = @{ | ||
| + | name_ = "my test sensor" | ||
| + | tags_ = " | ||
| + | priority_ = 4 | ||
| + | exefile_ = " | ||
| + | exeparams_ = " | ||
| + | environment_ = 1 | ||
| + | usewindowsauthentication_ = 1 | ||
| + | mutexname_ = " | ||
| + | timeout_ = 70 | ||
| + | writeresult_ = 1 | ||
| + | intervalgroup = 0 | ||
| + | interval_ = " | ||
| + | errorintervalsdown_ = 2 | ||
| + | sensortype = " | ||
| + | } | ||
| + | |||
| + | $params = New-SensorParameters $raw | ||
| + | |||
| + | Get-Device " | ||
| + | </ | ||
| + | |||
| + | Schedule zu Device hinzufügen | ||
| + | <code powershell> | ||
| + | # Custom method | ||
| + | function Set-PRTGSchedule { | ||
| + | [CmdletBinding(SupportsShouldProcess)] | ||
| + | param ( | ||
| + | [Parameter(Mandatory, | ||
| + | [Parameter(Mandatory)][prtgapi.schedule]$Schedule | ||
| + | ) | ||
| + | |||
| + | begin { | ||
| + | if (-not (Get-PrtgClient)) {Connect-PrtgServer} | ||
| + | } | ||
| + | |||
| + | process { | ||
| + | if (-not $Object.id) { | ||
| + | write-error "Could not find valid ID on schedule object $schedule" | ||
| + | continue | ||
| + | } | ||
| + | |||
| + | [string]$scheduleValue = ($Schedule.id, | ||
| + | if ($PSCmdlet.ShouldProcess($Object.name," | ||
| + | Set-ObjectProperty -Force -Object $Object -RawParameters @{ | ||
| + | scheduledependency = 0 | ||
| + | schedule_ = $scheduleValue | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | $schedule = Get-PRTGSchedule " | ||
| + | Get-Device " | ||
| + | </ | ||
| + | |||
| + | Schedule zu Sensor hinzufügen | ||
| + | <code powershell> | ||
| + | Get-Sensor -Id 22243 | Set-ObjectProperty -RawParameters @{ | ||
| + | " | ||
| + | " | ||
| + | } -Force | ||
| + | </ | ||
| + | |||
| + | Schedule zu Probe hinzufügen | ||
| + | <code powershell> | ||
| + | Get-Probe -Id 17834 | Set-ObjectProperty -RawParameters @{ | ||
| + | " | ||
| + | " | ||
| + | } -Force | ||
| + | </ | ||
| + | =====Custom Sensor===== | ||
| + | |||
| + | Ein Custom Script Sensor kann XML oder JSON ausgeben. Die äußersten Tags (prtg) markieren das Gesamtergebnis. Die einzelnen " | ||
| + | |||
| + | XML und JSON Beispiel mit Powershell | ||
| + | <code powershell> | ||
| + | $ProcessCount = (Get-Process).Count | ||
| + | $UserCount = (query user | Measure-Object).Count - 1 | ||
| + | $tasks = (tasklist | Measure-object).Count | ||
| + | |||
| + | $XMLResult = @" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | </ | ||
| + | "@ | ||
| + | |||
| + | $JsonResult = @" | ||
| + | { | ||
| + | " | ||
| + | |||
| + | " | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | ], | ||
| + | | ||
| + | " | ||
| + | | ||
| + | } | ||
| + | } | ||
| + | "@ | ||
| + | |||
| + | $JsonResult | ||
| + | </ | ||
| + | |||
| + | =====Placeholders===== | ||
| + | |||
| + | ^ Placeholder | ||
| + | | %sensorid | ||
| + | | %deviceid | ||
| + | | %groupid | ||
| + | | %probeid | ||
| + | | %host | The IP address/DNS name of the device the sensor is created on. | | ||
| + | | %device | ||
| + | | %group | ||
| + | | %probe | ||
| + | | %name | The name of the EXE/Script sensor. | ||
| + | | %windowsdomain | ||
| + | | %windowsuser | ||
| + | | %windowspassword | ||
| + | | %linuxuser | ||
| + | | %linuxpassword | ||
| + | | %snmpcommunity | ||
| + | |||
| + | |||
| + | =====Tags===== | ||
| + | |||
| + | ====PRTG Tags==== | ||
| + | |||
| + | ^ TAG ^ MANDATORY ^ DESCRIPTION ^ POSSIBLE CONTENT ^ | ||
| + | | < | ||
| + | | < | ||
| + | |||
| + | |||
| + | ====RESULT Tags==== | ||
| + | |||
| + | Tags im Result Bereich | ||
| + | |||
| + | ^ TAG ^ MANDATORY ^ DESCRIPTION | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | | < | ||
| + | |||
| + | =====Links===== | ||
| + | |||
| + | * [[https:// | ||