ServerCheck : Get the Sensor value from CLI


I'm monitoring the temperature in the datacenter with sensors from ServerCheck. They are reliable and very efficient. They support SNMP and have a comprehensive UI. But, I recently had the need to get the value of one sensor from the CLI. I noticed the company has been renamed to InfraSensing, but the hardware is still the same. Let's see what can be done !


I first thought there are some APIs I can call. But ... not exactly. After doing some researches, I manage to find a hidden URL that returns a very long string formatted in XML with all the relevant details.

The problem is, it appears to be a different URL with different versions. So, here are the possibilities : 




I have no precisions about what version support what URL, just give it a try. What I know is : I'm running Release 8.6 (from Jan 6 2021) and I need to use the second URL.

It will produce something like this (Chrome did the XML parsing and display it as a tree structure) :

<ssname0>Temp back racks</ssname0>
<ssname2>Temp front racks</ssname2>
<ssname4>Dew Point1</ssname4>
<alert1>Temp r1,26.97,NORMAL,08 February 2023,15:50:17</alert1>

So, once you have this, that's only a matter of extracting the right information. It always been a pleasure to do that with php !

The below example is quick and dirty, but I'm sure you'll have an idea : 


$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, $login.":".$password);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_URL, "http://".$sensorGateway."/".$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);


$currDate=date('Y-m-d H:i:s');
print("Current Date time : ".$currDate."\n");
print("Sensor 1 Temp : ".$result->status->ssvalue0." °C\n");
print("Sensor 2 Temp : ".$result->status->ssvalue2." °C\n");

This will output the value for sensor0 and sensor2 : 

Current Date time : 2023-02-17 11:51:12
Sensor 1 Temp : 25.39 °C
Sensor 2 Temp : 26.62 °C

Now, you can improve the script in 2 ways : 
  • Create a function and pass the arguments;
  • Log the data on a file to get the trends.
Here is the function : 

function scGetSensor($sensorConnect,$sensorIdx)
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_USERPWD, $sensorConnect["username"].":".$sensorConnect["password"]);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_URL, "http://".$sensorConnect["ip"]."/".$url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);
    // Build the property name according to the senssor IDX

    return $tmp;

You probably notice I'm using a $sensorConnect array : 

    "ip" => "<your_sensor_gateway_ip>",
    "username" => "<your_login>",
    "password" => "<your_password>"

Simply call the function this way : 


If you wish to log the data to a file, you can use this trick : 

$fp = fopen($output, 'a');
fwrite($fp, $currDate.','.$result->status->ssvalue0.','.$result->status->ssvalue2."\n"); 

This will create a file called $output, if the file already exists, it will append the new data at the end.

I think it's always easier and more satisfying to extract the data by yourself since you know exactly how to deal with them by controlling the output format. In my use case, SNMP was available but I needed to open some requests to have firewall opened. It does not worth it since I needed to monitor the progress over 24 hours. But as always, Php came to the rescue.

I hope this helps anyone else ! ;)


What's hot ?

Wallbox : Get The Most Of It (with API)

PCBWay : CNC Machining