I would like to use a value - which is available as XML file and accessible using a GET URL - as the value of a sensor in PRTG.
How can I do this?
Votes:
I would like to use a value - which is available as XML file and accessible using a GET URL - as the value of a sensor in PRTG.
How can I do this?
api custom-exe custom-script-exe custom-sensor http restful xml
Created on Nov 10, 2010 9:57:18 AM by
Dirk Paessler [Founder Paessler AG]
(11,025)
●3
●6
Last change on Mar 19, 2015 4:03:56 PM by
Martina Wittmann [Paessler Support]
8 Replies
Votes:
Important: The custom sensor which is described below is now an integrated part of PRTG (as of version 8.3).
Please see PRTG Manual: HTTP XML/REST Value Sensor for details.
There is a custom sensor that requests data from an HTTP or HTTPS URL (using GET), parses the XML results and uses selected data from the XML as sensor value in PRTG.
With this technique you can import data from many APIs into PRTG, as long as they are offering an interface that works with simple HTTP GETs and replies with XML data.
Services like these are often called “REST APIs or RESTful APIs”. This type of API is becoming more and more common, PRTG's own API is a RESTful API, too.
Please note that this sensor will not be able to access SOAP based APIs.
Step-by-Step
The last step is obviously the most complex and requires a good knowledge of the API and the XML output. We have compiled some samples below.
Note: Please understand that we can not support this "unofficial" feature as we do with all "official" features of PRTG, but we will try to do our best.
Here are the URL parameters of this sensor:
Required parameters:
Parameter | Description | Sample |
---|---|---|
-u=url | URL to call, with all parameters | -url=https://www.paessler.com |
-n=nodename | XML node to use the data from | -n=mydata |
or | ||
-n="nodename propertyname" | use a property value of the XML node | -n="mydata myproperty" |
Optional parameters:
Parameter | Description | Sample |
---|---|---|
-t=xx | Timeout in seconds (default is 15s) | -t=60 |
-c | count the number of nodes with the name given in -n parameter | -c |
-cc | count the number of childnodes of the xml node. | -cc |
-cs | count the number of sibbelings of the xml node. | -cs |
-rc=char | characters to remove from the xml value (i.e. to remove a thousands seperator from the result use -rc=,) | -rc=. |
-cm="%1 value" | a custom message to be displayed (i.e. -cm="There are %1 tickets in our ticketing system." where %1 will be replaced with the xml value). |
Using the following URL you can get weather data from Google (it seems to be a part of iGoogle):
http://www.google.com/ig/api?weather=yourcity
Important: This is an unofficial API. We have not found any usage terms that govern the use of this interface. So we are using this just as an example. If you use it, you are doing so at your own risk. It may disappear or break without notice.
The result of the URL is:
<xml_api_reply version="1"> <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0"> <forecast_information> <city data="Nuremberg, Bavaria"/> <postal_code data="nuernberg"/> <latitude_e6 data=""/> <longitude_e6 data=""/> <forecast_date data="2010-11-10"/> <current_date_time data="2010-11-10 11:20:00 +0000"/> <unit_system data="SI"/> </forecast_information> <current_conditions> <condition data="Meistens bewölkt"/> <temp_f data="50"/> <temp_c data="10"/> <humidity data="Feuchtigkeit: 71 %"/> <icon data="/ig/images/weather/mostly_cloudy.gif"/> <wind_condition data="Wind: S mit 13 km/h"/> </current_conditions> [...]
We use the following URL parameters for the XMLvalue sensor:
-u="http://www.google.com/ig/api?weather=nuernberg" -n="temp_c data" -cm="%1 Degrees Celsius"
The parameter -n="temp_c data" tells the sensor to use the data of property "data" from node "temp_c" as sensor value. If you want the Fahrenheit value, please use temp_f.
The API of weatherbug.com requires that you sign up for an account so you can get an API key. Then you must find out your "cityCode" parameter using their "search locations" function.
We use the following URL parameters for the custom sensor:
-u="http://your_api_key.api.wxbug.net/getLiveWeatherRSS.aspx?ACode=your_api_key&cityCode=your_city_code&&UnitType=1&OutputType=1" -n=aws:temp -cm="%1 Degrees Celsius at NUE Airport"
Note: Parameter unitType controls whether the value is in Fahrenheit (unitType=0) or Celsius (unitType=1).
The API of weather.com also requires that you sign up for an account so you can get a set of API keys. Then you must find out your location code using their website (note: with the API weather.com seems to support US locations only ).
We use the following URL parameters for the custom sensor:
-u="http://xoap.weather.com/weather/local/USNY0996?cc=*&dayf=5&link=xoap&prod=xoap&par=1210791329&key=1e8c160fbe39d347" -n=tmp -cm="%1 Fahrenheit in Central Park"
We monitor the number of new and open tickets in our support ticket system (Fogbugz by FogCreek Software, http://fogcreek.com/fogbugz/) in order to display the number in our company Intranet dashboard.
The command line options are:
-u="http://www.fogbugz.bsx/api.asp?cmd=search&q=project:'Paessler AG Support Inbox' status:open opened:'1/1/2010..-0d'&token=9q8jhha4v8pc6v54ls3rgiic6abm72" -n="cases count"
The response looks like this:
<response>
−
<cases count="81">
<case ixBug="159965" operations="edit,spam,assign,resolve,reply,forward,remind"/>
[...]
<case ixBug="198178" operations="edit,spam,assign,resolve,reply,forward,remind"/>
</cases>
</response>
With the parameter -n="cases count" we tell the sensor to use property "count" of the XML node "cases" as value for the sensor.
The API of compete.com allows you (among other features) to get the traffic ranking of a domain. First you must register for a developer user account, then you must register your application to get your personal API key.
We use the following parameters to get the ranking of paessler.com:
-u="http://api.compete.com/fast-cgi/MI?d=paessler.com&ver=3&apikey=your_api_key&size=large" -n=ranking -rc=,
First you must apply for an API key on their website. Using the following parameters you can get the number of views of a photo on photo sharing website Flickr.com:
-u="http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=your_api_key&photo_id=740325509" -n="photo views" -cm="%1 Total Views"
Created on Nov 10, 2010 11:55:23 AM by
Dirk Paessler [Founder Paessler AG]
(11,025)
●3
●6
Last change on May 26, 2014 5:04:17 PM by
Gerald Schoch [Paessler Support]
Votes:
That custom sensor has been deprecated because the author says this functionality is now included in PRTG. How do I do this? I don't see it in the sensor list.
Votes:
It is now integrated directly into PRTG and you will find it in the group of WebServer (HTTP) sensors.
Votes:
Is there a more sophisticated way to debug this than using the results.txt file? I am using the Intervals.com API and get 401 Unauthorized using the PRTG sensor but when I test it with my own development tools I'm able to authenticate and get the results. I'm wondering if my authentication is being mangled somehow. I included the credentials in the sensor configuration and also tried base64 encoded credentials (although I assume PRTG's sensor handles the encoding).
I'd like to see the header that PRTG is passing to the server, is that possible?
Votes:
No, sorry, you can not access the headers. You could set up a debugging proxy like "Fiddler2", enter the proxy settings into PRTG and then you can look into the HTTP traffic.
Votes:
Or use Microsoft Network Monitor to capture requests send to intervals.com
Votes:
The link: http://code.google.com/p/prtg-addons/wiki/PTF_Custom_Sensors
is broken
Votes:
Hi there,
All custom sensors from the PRTG Tools Family can be found here.
Kind regards
Felix Wiesneth - Team Tech Support
©2024 Paessler AG Terms & Conditions Privacy Policy Legal Notice Download & Install
Add comment