Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
prtg [2024/07/26 16:23] admin [Powershell] |
prtg [2024/07/27 22:46] (aktuell) jango |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| =====PrtgAPI===== | =====PrtgAPI===== | ||
| - | Siehe [[https:// | + | Für [[coding: |
| <code powershell> | <code powershell> | ||
| Install-Package PrtgAPI -Source PSGallery | Install-Package PrtgAPI -Source PSGallery | ||
| Import-Module PrtgAPI | Import-Module PrtgAPI | ||
| + | </ | ||
| - | # Erstellen der Anmeldeinformationen | + | Verbindung mit Anmeldeinformationen aufbauen |
| + | <code powershell> | ||
| + | # Verbindung mit Anmeldeinformationen | ||
| $username = " | $username = " | ||
| $password = " | $password = " | ||
| $credential = New-Object System.Management.Automation.PSCredential($username, | $credential = New-Object System.Management.Automation.PSCredential($username, | ||
| - | |||
| - | # Verbindung herstellen | ||
| Connect-PrtgServer -Server $server -Credential $credential -IgnoreSSL | 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 | # Sensoren suchen | ||
| - | #Get-Sensor " | + | Get-Sensor " |
| + | </ | ||
| + | Deviced suchen | ||
| + | <code powershell> | ||
| # Devices suchen | # Devices suchen | ||
| - | #Get-Device | select-object * | where-object { $_.Name -like " | + | Get-Device | select-object * | where-object { $_.Name -like " |
| + | </ | ||
| - | # Sensor erstellen | + | Custom |
| - | <# | + | <code powershell> |
| + | # Custom Sensor erstellen | ||
| $raw = @{ | $raw = @{ | ||
| name_ = "my test sensor" | name_ = "my test sensor" | ||
| Zeile 39: | Zeile 75: | ||
| sensortype = " | sensortype = " | ||
| } | } | ||
| + | |||
| $params = New-SensorParameters $raw | $params = New-SensorParameters $raw | ||
| + | |||
| Get-Device " | Get-Device " | ||
| - | #> | + | </code> |
| - | # Verbindung trennen | + | Schedule zu Device hinzufügen |
| - | Disconnect-PrtgServer | + | <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===== | =====Custom Sensor===== | ||
| Zeile 52: | Zeile 135: | ||
| XML und JSON Beispiel mit Powershell | XML und JSON Beispiel mit Powershell | ||
| - | < | + | < |
| $ProcessCount = (Get-Process).Count | $ProcessCount = (Get-Process).Count | ||
| $UserCount = (query user | Measure-Object).Count - 1 | $UserCount = (query user | Measure-Object).Count - 1 | ||