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

Show the uptime/downtime for a certain time period in a map

Votes:

5

Not a question, just wanted to share how I'm getting the uptime/downtime or sensors for a certain time period in maps. For example, I was tasked with generating a dashboard that had certain sensor's uptime/downtime for the last month. By default the <#objectstatus name="uptime" id="<@objectid>"> provides the uptime for the life of the sensor, but I want to provide my own start and end date (like using a report) but in a map. Using the 'historicdata_totals.xml' api and writing a custom map object, this was possible...

<!--Custom Map Objects: Sensor Stats Up/Downtime Last Month-->

<div class="map_object" id="<@itemid>" objectid="<@objectid>" subid="<@subid>" style="<#mapobject type="topleftcoordinates" subid="<@subid>" mode="<@editmode>">">
	<#checkobjecttype objecttype="sensor" nicemessage="true" id="<@objectid>">
	<#mapobject type="objectgrip" mode="<@editmode>">
	<#mapobject type="htmlbefore" subid="<@subid>">
	<font face="arial;" size="2"><b><#objectstatus name="name" id="<@objectid>"></b></font>
	<#objectstatus name="downsens" id="<@objectid>">
	<font color="green"><b><div id="<@objectid>uptime"></div></font>
	<font color="red"><b><div id="<@objectid>downtime"></div></font>
	<#mapobject type="htmlafter" subid="<@subid>">
</div>

<SCRIPT LANGUAGE="JavaScript">
// set start date to 1 month before current date
var startDate = new Date();
startDate.setMonth(startDate.getMonth()-1); 
// date format required for historicdata_totals.xml = 2017-02-12 (yyyy-mm-dd)
var d = new Date(startDate),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
startDate = [year, month, day].join('-');

// set end date to today
var endDate = new Date();
// date format required for historicdata_totals.xml = 2017-02-12 (yyyy-mm-dd)
var d = new Date(endDate),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
endDate = [year, month, day].join('-');

//console.log(startDate);
//console.log(endDate);

var xhr = new XMLHttpRequest();
// false makes the request synchronous, doesn't work async when used multiple times in a single map
xhr.open('GET', 'https://YOURPRTGSERVER/api/historicdata_totals.xml?id=<@objectid>&sdate='+startDate+'-00-00-00&edate='+endDate+'-23-59-59', false);

xhr.onload = function () {
	if (xhr.readyState === xhr.DONE) {
		if (xhr.status === 200) {
			console.log(xhr.responseText);
			parser = new DOMParser();
			xmlDoc = parser.parseFromString(xhr.responseText,"text/xml");

			var UptimePercent = xmlDoc.getElementsByTagName("uptimepercent")[0].childNodes[1].nodeValue;
			var Uptime = xmlDoc.getElementsByTagName("uptime")[0].childNodes[1].nodeValue;
			document.getElementById("<@objectid>uptime").innerHTML = "<b>Uptime:</b> " + UptimePercent;
			
			var DowntimePercent = xmlDoc.getElementsByTagName("downtimepercent")[0].childNodes[1].nodeValue;
			var Downtime = xmlDoc.getElementsByTagName("downtime")[0].childNodes[1].nodeValue;
			document.getElementById("<@objectid>downtime").innerHTML = "<b>Downtime:</b> " + DowntimePercent + " ["+Downtime+"]";
		}
	}
};
xhr.send(null);
</SCRIPT>

This may not be the most elegant, or best way to accomplish this; and I'd be glad to hear what may be a better solution, but for the time being this is working great. Hopefully someone might find it handy.

historicdata map maps prtg xml

Created on Apr 20, 2017 12:16:08 AM

Last change on Apr 20, 2017 7:42:41 AM by  Torsten Lindner [Paessler Support]



6 Replies

Votes:

0

How would I go about using this in my PRTG application?

Created on May 14, 2018 9:00:43 AM



Votes:

0

@Steve: Thank you for sharing this, we appreciate it.

@Matthew: You basically take the code portion from Steve's post and save it as a file with file extension "*.htm" to PRTG's installation path, subfolder "webroot\mapobjects". You need to adjust potion https://YOURPRTGSERVER in the file accordingly with your PRTG server (and custom port if necessary).

You will have this object then at your disposal in PRTG's map editor in section "Custom Map Objects" to drag&drop into the map and then drop a sensor onto it from the left pane.

Kind regards,

Erhard

Created on May 14, 2018 12:24:04 PM by  Erhard Mikulik [Paessler Support]

Last change on May 14, 2018 3:59:57 PM by  Erhard Mikulik [Paessler Support]



Votes:

0

I'm no expert but it looks to me like the script auto-populates the start/end date and sensor id. I did add the address of my PRTG server into the script where it says 'https://YOURPRTGSERVER ' I managed to get the custom sensor to show in the properties section of the map designer however I cannot get it to show on the map.

Created on May 14, 2018 1:40:33 PM



Votes:

0

Hi Matthew,

Ah, yes, you are right, actually adjusting the url for your PRTG server, I will correct that, that is the only thing you need to do. Drag&drop the object to the map and then you can drag&drop the sensor from the left pane onto it in order to display the data.

Kind regards,

Erhard

Created on May 14, 2018 3:58:11 PM by  Erhard Mikulik [Paessler Support]



Votes:

0

I can drag & drop any other object into the map but not this one.

Created on May 17, 2018 1:17:01 PM



Votes:

0

Hi Matthew,

Send me an email ([email protected]) with more details like screenshots of what you're doing and which browser you use.

Kind regards,

Erhard

Created on May 17, 2018 2:07:32 PM by  Erhard Mikulik [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.