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

XML: Junk after document element </prtg> KlimaLogg

Votes:

0

Hi , i still get this error when i built a custom sensor to get Data from KlimaLogg Service

Does somebody know what is this error for ?

param (
	[string]$inputfile = "C:\ProgramData\KlimaLogg.dat1"
)

set-psdebug -strict
$ErrorActionPreference="SilentlyContinue"
$error.clear()

write-host "Start PRTG Sensor" 
write-host "Inputfile:" $Inputfile 

$inifile = get-content $inputfile

[string]$resultxml="<inifile>"
[string]$inisection=""
foreach ($line in $inifile) {
	write-host "Processing $line"
	if ($line[0] -eq "[") {
		if ($inisection -ne "") {
			write-host "Closing old inisection: $inisection"
			$resultxml+=("</$inisection>`r`n")
		}
		$inisection = $line.replace("[","").replace("]","")
		write-host "Found new inisection: $inisection"
		$resultxml+=("<$inisection>`r`n")
	}
	elseif ($line -like "*=*") {
		$key=($line.split("=")[0])
		$value=($line.split("=")[1])
		write-host "Found parameterline Key: $key    Value:$value"
		$resultxml+=("<$key>$value</$key>`r`n")
	}
	else {
		write-host "Skip line"
	}
}
$resultxml+=("</$inisection>`r`n")
$resultxml+="</inifile>"
[xml]$inixml= $resultxml
[string]$result="<prtg>`r`n"

$lastactualization = [long]($inixml.inifile.time.last_actualisation.replace("""",""))
write-host "Timestamp lastactualization: $lastactualization"
$timestampageseconds = [long](((Get-Date).touniversaltime().addseconds(-$lastactualization) -  (get-date 1.1.1900)).totalseconds)
write-host "Timestamp age in minutes $timestampageseconds"
if ($timestampageseconds -gt 120) {
	$result+="<error>1</error>`r`n"
	$result+="<text>Data to old. last update $timestampageseconds Seconds. Check Klimalogger-Service</text>`r`n"
}
else {			  
	foreach ($count in (0..8)) {
		write-host "Processing Channel $count"
		$result+="  <result>`r`n"
		$result+="    <channel>Temperature("+$count+")</channel>`r`n"
		$result+="    <value>"+$inixml.inifile.("temperature_channel_"+$count).deg_c.replace("""","")+"</value>`r`n"
		$result+="    <unit>Temperature</unit>`r`n"
		$result+="    <CustomUnit>Celsius</CustomUnit>`r`n"
		$result+="    <mode>Absolute</mode>`r`n"
		$result+="    <float>1</float>`r`n"
		$result+="  </result>`r`n"
		$result+="  <result>`r`n"
		$result+="    <channel>Humidy("+$count+")</channel>`r`n"
		$result+="    <value>"+$inixml.inifile.("humidity_channel_"+$count).percent.replace("""","")+"</value>`r`n"
		$result+="    <unit>Percent</unit>`r`n"
		$result+="    <mode>Absolute</mode>`r`n"
		$result+="  </result>`r`n"	
	}
	$result+="<text>No errors found</text>`r`n"
}
	
$result+="</prtg>"
write-host "End: ExitCode "$error.count
 
Write-host "Sending Result to output pipeline"
$result
 
if ($error) {
	#write-host "Found Errors"
	EXIT 1
}

customsensor klimalogg xml

Created on Aug 31, 2015 7:46:40 PM

Last change on Aug 31, 2015 8:00:07 PM by  Felix Saure [Paessler Support]



2 Replies

Votes:

0

Hi,

When you run this script from the commandline, what does the output look like? Is there anything after the closing </prtg> tag?

Created on Sep 1, 2015 7:55:00 AM



Votes:

7

Hi, please take a look at this example: https://kb.paessler.com/en/topic/64817-how-can-i-show-special-characters-with-exe-script-sensors

Write-Host puts out Text to Stdout and so your XML is destroyed by your logging. All what you see in the console, when you run your script manually, was send to PRTG.

Mit freundlichen Grüßen

Jens

Created on Sep 1, 2015 1:12:17 PM




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.