GENWiki

Premier IT Outsourcing and Support Services within the UK

User Tools

Site Tools


php:access_passler_prtg_using_php_and_retrieve_sensor_data

Pull values from Passler PRTG with PHP

function getJSON($id, $sid=0) {
    $server="https://10.1.1.14:443";
    $user="Username";
    $pass="Password";
        
    $con="sensors";
    $cols="objid,group,device,sensor,status,message,lastvalue,priority,favorite";
    $url=$server."/api/table.json?content=".$con."&columns=".$cols."&id=".$id;
    $url.="&username=".$user."&password=".$pass;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYSTATUS,false);
    curl_setopt($ch, CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1_2); 
    curl_setopt($ch, CURLOPT_VERBOSE, false);
    $response = curl_exec($ch);
    $httpcode=curl_getinfo($ch);
    curl_close($ch);
    
    $sensor=json_decode($response, true);

    if($sid!==false) {
        $sensor=$sensor[sensors][$sid];
    } 
    return $sensor;
}

Set $server to the url of your PRTG Server, set $user to a valid username, and $pass to a valid password. To use this function simply select the device ID, and the sensor number as an integer, to get all the sensors in the device simply set the second parameter to false.

e.g If you know your device is 1234 then call

$s=getJSON(1234,false);
print_r($s);

This will return each sensor on that device. When you know what number you want simply use that as the second parameter to select only that sensor for the device. Generally, they are numbered in the order they appear on the PRTG web interface, so that 0 is the first sensor for a device, 1 is the second and so on.

$s=getJSON(1234,1);
print_r($s);

Fetches the second sensor on the device 1234.

/home/gen.uk/domains/wiki.gen.uk/public_html/data/pages/php/access_passler_prtg_using_php_and_retrieve_sensor_data.txt · Last modified: 2023/01/31 11:48 by genadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki