What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

How can I get the downtime percentage of a sensor for a specific time span via API

Votes:

0

I'm trying to get the Downtime time of a sensor via API.

  • table.xml gives me the downtime, but does not support sdate and edate.
  • historicdata.xml support sdate and edate, but doesn't give me the downtime

So how do I do it?

api downtime historic-data report

Created on Feb 14, 2012 9:53:06 AM by  Dirk Paessler [Founder Paessler AG] (11,025) 3 6



7 Replies

Accepted Answer

Votes:

2

I have created a new API call for you to do this

/api/historicdata_totals.xml

requires the same parameters as /api/historicdata.xml, but gives you the desired data.

Go to the \website\api folder and create a new textfile with the name "historicdata_totals.xml". Open the file with a text editor and paste the following code into it:

<#checkobjecttype objecttype="sensor"><#droplive>


<?xml version="1.0" encoding="UTF-8"?>
<historicdata>
	<prtg-version><#system type="version"></prtg-version>
	<clusternode>
		<![CDATA[<#cluster type="name" show="textraw" utfencode="true">]]>
	</clusternode>

	<startdate>
		<![CDATA[<#startdate show="textraw" utfencode="true">]]>
	</startdate>
	<enddate>
		<![CDATA[<#enddate show="textraw" utfencode="true">]]>
	</enddate>

	<name>
		<![CDATA[<#objectproperty name="Name" show="textraw" utfencode="true">]]>
	</name>
	<sensortype>
		<![CDATA[<#objectstatus name="type" show="textraw" utfencode="true">]]>
	</sensortype>

	<probename>
		<![CDATA[<#objectstatus name="probe" show="textraw" utfencode="true">]]>
	</probename>
	<parentgroupname>
		<![CDATA[<#objectproperty name="ParentGroup" show="textraw" utfencode="true">]]>
	</parentgroupname>
	<parentdevicename>
		<![CDATA[<#objectproperty name="ParentDevice" show="text" utfencode="true">]]>
	</parentdevicename>
	<parentdeviceid>  
		<![CDATA[<#objectstatus name="parentid" show="text" utfencode="true">]]>
	</parentdeviceid>

	<uptimepercent>
		<![CDATA[<#objectproperty type="uptimeper" usetz="1" show="raw" utfencode="true">]]>
	</uptimepercent>
	<uptime>
		<![CDATA[<#objectproperty type="uptime" usetz="1" show="raw" utfencode="true">]]>
	</uptime>

	<downtimepercent>
		<![CDATA[<#objectproperty type="downtimeper" usetz="1" show="raw" utfencode="true">]]>
	</downtimepercent>
	<downtime>
		<![CDATA[<#objectproperty type="downtime" usetz="1" show="raw" utfencode="true">]]>
	</downtime>

	<goodreqpercent>
		<![CDATA[<#objectproperty type="goodreqper" usetz="1" show="textraw" utfencode="true">]]>
	</goodreqpercent>
	<goodreq>
		<![CDATA[<#objectproperty type="goodreq" usetz="1" show="textraw" utfencode="true">]]>
	</goodreq>

	<failedreqpercent>
		<![CDATA[<#objectproperty type="failedreqper" usetz="1" show="textraw" utfencode="true">]]>
	</failedreqpercent>
	<failedreq>
		<![CDATA[<#objectproperty type="failedreq" usetz="1" show="textraw" utfencode="true">]]>
	</failedreq>

	<averagelabel>
		<![CDATA[<#objectproperty type="avgvaluelabel" usetz="1"  show="textraw" utfencode="true">]]>
	</averagelabel>
	<average>
		<![CDATA[<#objectproperty type="avgvalue" usetz="1" show="textraw" utfencode="true">]]>
	</average>

	<sumlabel>
		<![CDATA[<#objectproperty type="sumvaluelabel" usetz="1"  show="textraw" utfencode="true">]]>
	</sumlabel>
	<sum>
		<![CDATA[<#objectproperty type="sumvalue" usetz="1" show="textraw" utfencode="true">]]>
	</sum>
</historicdata>	

The URLs look like this

http://YOURPRTGSERVER/api/historicdata_totals.xml?id=1003&sdate=2012-02-12-00-00-00&edate=2012-02-12-23-59-59&avg=3600&pctavg=300&pctshow=false&pct=95&pctmode=true

The result looks like this:



<?xml version="1.0" encoding="UTF-8"?>
<historicdata>
	<prtg-version>1.0.0.0</prtg-version>
	<clusternode>
		<![CDATA[]]>
	</clusternode>

	<name>
		<![CDATA[Probe Health]]>
	</name>
	<sensortype>
		<![CDATA[ProbeState]]>
	</sensortype>

	<probename>
		<![CDATA[Local probe]]>
	</probename>
	<parentgroupname>
		<![CDATA[Local probe]]>
	</parentgroupname>
	<parentdevicename>
		<![CDATA[Probe Device]]>
	</parentdevicename>
	<parentdeviceid>  
		<![CDATA[40]]>
	</parentdeviceid>

	<uptimepercent>
		<![CDATA[99.925 %]]>
	</uptimepercent>
	<uptime>
		<![CDATA[22h4m26s]]>
	</uptime>

	<downtimepercent>
		<![CDATA[0.075 %]]>
	</downtimepercent>
	<downtime>
		<![CDATA[1m0s]]>
	</downtime>

	<goodreqpercent>
		<![CDATA[100 %]]>
	</goodreqpercent>
	<goodreq>
		<![CDATA[1327]]>
	</goodreq>

	<failedreqpercent>
		<![CDATA[0 %]]>
	</failedreqpercent>
	<failedreq>
		<![CDATA[0]]>
	</failedreq>

	<averagelabel>
		<![CDATA[Average (Health):]]>
	</averagelabel>
	<average>
		<![CDATA[0000000000000990.8421]]>
	</average>

	<sumlabel>
		<![CDATA[]]>
	</sumlabel>
	<sum>
		<![CDATA[]]>
	</sum>
</historicdata>	

(Note: the file will be part of future versions, too).

Created on Feb 14, 2012 10:02:37 AM by  Dirk Paessler [Founder Paessler AG] (11,025) 3 6



Votes:

0

This is fantastic. Can this be extended by Iterating down through devices starting at a Root device and filtering on PING sesnor. This report then run against that sensor for each device in the tree that it finds a ping sensor for.

Would really appreciate some assistance with this. With the help of the above code I can now run API queries against a PING sensor for a device and specify the period I want the Uptime Stats for.

I am sure this would also correct the issue with this functionality not being put into PRTG currently. We are really needing this facility for management as this is the only factor causing my place of work to consider SolarWinds.

Created on Jun 17, 2015 11:36:36 PM



Votes:

0

Hello Steve,
Since the historicdata API requires a sensor ID, it can't be filtered at that query level, in that case you will require two distinct API calls, a first one to get you the oids of all ping sensors, it would look like:

http://YOURPRTGSERVER/api/table.xml?content=sensors&output=xml&columns=objid,sensor&filter_tags=@tag(pingsensor)"

By default all Ping Sensors have the pingsensor tag, the output will look like:

<?xml version="1.0" encoding="UTF-8"?>
  <sensors totalcount="11" listend="1">
   <prtg-version>15.2.18.2816</prtg-version>
   <item>
    <objid>2010</objid>
    <sensor>Ping</sensor>
   </item>
   <item>
    <objid>2019</objid>
    <sensor>Ping</sensor>
   </item>
  </sensors>

You can then use any iteration method (for, while, ...) to perform the next API call using the previously obtained objid (in this example, 2019) as parameter for the new API call:

http://YOURPRTGSERVER/api/historicdata_totals.xml?id=2019&sdate=2015-06-10-00-00-00&edate=2015-06-23-00-00-00&avg=3600&pctavg=300&pctshow=false&pct=95&pctmode=true

This should provide you with the solution to what you want to achieve using only two API Calls. For further questions.

Best regards.

Created on Jun 23, 2015 12:31:27 PM by  Luciano Lingnau [Paessler]



Votes:

0

Hello,

i'm currently looking for a way to display our availability of ping sensors that are taged with a certain keyword, within a list, on a map and where the Data from the last Year is used only.

I'm able to display a list with the taged Ping Sensors and their Uptime, Accumulated since Downtime, Last Down Value and the Devicename, this list only shows devices whose availability ist below 99,95%. But im unable to get this with a secific time window, like the last year. We like to show the availablility of the last year (the last 365 days) and possibly even for the last month or quarter.

Is there currently a way to retrieve this data within a map. I can create a powershell shript to get the data we desire with the two API calls but this way i dosn't get them on a map and this is also not very dynamic to show the current status.

Is there a solution i'm unaware of or a workaround to achieve this?

Many thanks in advance.

Created on Dec 13, 2018 9:44:46 AM



Votes:

0

Hi Jacqueline,

Thank you for your KB-post.

Could you please provide us more details about the Powershell script? Have you tried using it within Advanced Script Sensor?

Created on Dec 14, 2018 1:06:46 PM by  Isidora Jeremic [Paessler Support]



Votes:

0

Hello Isidora,

I'm sorry, I did not express myself completely understandable. I have not written a powershell script yet, i was hoping to solve this without an additional sensor. Is there a way to get this working in a list within an mapobject?

edit: I already have a list with all the information, i just can't limit it to last year.

Many thanks in advance.

Created on Dec 17, 2018 7:21:19 AM

Last change on Dec 18, 2018 8:13:18 AM by  Isidora Jeremic [Paessler Support]



Votes:

0

Hi Jacqueline,

Did you use parameters for date/time range in the API calls?

I am referring to the following parameters:

"sdate": Start of the time span (date and time) yyyy-mm-dd-hh-mm-ss

"edate": End of the time span (date and time) yyyy-mm-dd-hh-mm-ss

Created on Dec 20, 2018 10:17:49 AM by  Isidora Jeremic [Paessler Support]




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.