What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Get data from PRTG with Powershell

Votes:

0

Your Vote:

Up

Down

Is it possible to get data from PRTG, with powershell? Has anybody done that before?

I would like to receive data like disk-usages and uptime-information.

information powershell prtg

Created on Apr 7, 2016 7:14:16 AM by  Poort80 Hosting Services (0) 1



2 Replies

Votes:

0

Your Vote:

Up

Down

Hi,
Sure, this is possible. PRTG offers an HTTP API which can be queried using Powershell. The API Dcoumentation can be found at YOUR_PRTG_SERVER/api.htm. I personally am using the Invoke-WebRequest cmdlet here. Example code below:

param(
    [string]$user = "prtgadmin",
    [string]$pass = "prtgadmin",
    [string]$prtgserver = "https://127.0.0.1",
    [string]$time = "yesterday",
    [string]$path = "D:\Temp\"
)
# function from http://stackoverflow.com/questions/11696944 to override SSL Cert check
function Ignore-SSLCertificates
{
    $Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
    $Compiler = $Provider.CreateCompiler()
    $Params = New-Object System.CodeDom.Compiler.CompilerParameters
    $Params.GenerateExecutable = $false
    $Params.GenerateInMemory = $true
    $Params.IncludeDebugInformation = $false
    $Params.ReferencedAssemblies.Add("System.DLL") > $null
    [email protected]'
        namespace Local.ToolkitExtensions.Net.CertificatePolicy
        {
            public class TrustAll : System.Net.ICertificatePolicy
            {
                public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)
                {
                    return true;
                }
            }
        }
'@ 
    $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
    $TAAssembly=$TAResults.CompiledAssembly
    ## We create an instance of TrustAll and attach it to the ServicePointManager
    $TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
    [System.Net.ServicePointManager]::CertificatePolicy = $TrustAll
}
Ignore-SSLCertificates

$get_devices_uri = ("{0}/api/table.json?content=devices&output=json&columns=objid&username={1}&password={2}" -f $prtgserver, $user, $pass)

try{
    $JSON = Invoke-WebRequest -Uri $get_devices_uri | ConvertFrom-Json
}
catch{
    Write-Host "Error. Cannot get device ids. Exiting!"
    exit 0
}
foreach($object in $JSON.devices){
    $destination = ("{0}\{1}.csv" -f $path, $object.objid)
    $get_messages_uri = ("{0}/api/table.xml?content=messages&output=csvtable&columns=objid,datetime,parent,type,name,status,message&filter_drel={1}&id={2}&username={3}&password={4}" -f $prtgserver, $time, $object.objid, $user, $pass)
    try{
        Invoke-WebRequest -Uri $get_messages_uri -OutFile $destination
    }
    catch{
        Write-Host "Error. Cannot get messages. Exiting!"
        exit 0
    }
}

Above code gets messages from a sensor but can easily be adapted to sensor data. Please note that the function from Stackoverflow has to stay in place when you are using a self signed Certificate as this will (I know this is not optimal) overwrite the certificate check. If not needed please remove!

Created on Apr 7, 2016 1:36:05 PM by  Konstantin Wolff [Paessler Support]



Votes:

1

Your Vote:

Up

Down

Certainly done it before..

Have a look here:

Look at the function Get-prtgSensorData

Params: SensorID, [datetime]StartDate, [datetime]EndDate

Returns a table of the raw data.

More details here:

Created on Apr 21, 2016 11:43:48 AM by  AndrewG (1,783) 2 2

Last change on Jun 6, 2016 6:13:41 AM by  Luciano Lingnau [Paessler]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.