We use an old Allnet All3000 web thermometer to monitor critical room temperatures. I have written two scripts to monitor this device, using the text-only output or the xml-output.
Feel free to comment and improve.
Script using the xml-output
#Script monitors the output of an Allnet All3000 thermometer device.
#User manual (German): ftp://212.18.29.48/ftp/pub/allnet/verschiedene/all3000/ALL3000_Handbuch_001.pdf
#We currently have only three channels active with temperature probes
#tbd: modification to allow descriptive name for each channel
#MRO 2016-09-21
#variables
[string] $prtgresult=''
$securepassword = ConvertTo-SecureString "password" -AsPlainText -Force #password for device
$credentials = New-Object System.Management.Automation.PSCredential("Admin", $securepassword) #username for device
$url = "http://all3000.domain.internal/xml" #URL of the All3000 device, make sure to add /xml for xml-formatted return string!
cls
#retrieve xml output from device
[xml] $xml=Invoke-WebRequest -Uri $url -Credential $credentials -UseBasicParsing
#[xml] $xml= [xml] (get-content -Path c:\temp\temp.xml) #for testing only
#build header for PRTG XML-file
$prtgresult+="<?xml version=""1.0"" encoding=""Windows-1252"" ?>`r`n"
$prtgresult+="<prtg>`r`n"
#build PRTG results data, adjust number of channels as needed. Only consecutive channels are supported, max. 0 - 7.
for ($i=0; $i -le 2; $i++)
{
write-host " Processing Datapoint :" $i
#this loops through the output fiels xml.data.t0 ... t7
$value= '$xml.xml.data.t' + "$i"|invoke-expression
write-host $value
$prtgresult+=" <result>`r`n"
$prtgresult+=" <channel>Channel "+$i+" </channel>`r`n"
$prtgresult+=" <value>"+$value +"</value>`r`n"
$prtgresult+=" <float>1</float>`r`n"
$prtgresult+=" <mode>absolute</mode>`r`n"
$prtgresult+=" <unit>Temperature</unit>`r`n"
$prtgresult+=" </result>`r`n"
}
$prtgresult+="</prtg>"
#send data to host
Write-Host $prtgresult
Alternative approach, using the text-output:
#Script monitors the output of an Allnet All3000 Device.
#We currently have only three channels active with temperature probes
#Tbd: Better string handling that can cope with variable lengths of the readouts
#Variables
$outputfile = 'c:\temp\output.txt' #for debug purposes
$result = '' #output for file
$Value='' #returned string from All3000
$Value1 = ''
$Value2 = ''
$Value3 = '' #only three channels are in use, extend as needed
$securepassword = ConvertTo-SecureString "password" -AsPlainText -Force #password for the All3000 device
$credentials = New-Object System.Management.Automation.PSCredential("Admin", $securepassword) #user for the All3000 device
$url = "http://all3000.domain.internal/s" #URL of the All3000 device, make sure you add the /s to get the text-only output!
#retrieve current values from All3000
$value=(Invoke-WebRequest -Uri $url -Credential $credentials -UseBasicParsing).rawcontent
#cut off headers and unneeded garbage
$value=$Value.Remove(0,85)
$value=$value.Split("U",2)
$value=$value[0]
$value
#reformat return string and check for letters (device sometimes has sudden reboots an returns garbage chars then)
#separate active channels from inactive and select active part
$Value=$Value.Split("-")
$Value=$Value[0]
$Value
#get first value (will only work with 2-digit temperatures :-(
$Value1=$Value.substring(1,4).Insert(2,".")
if($value1 -match '[a-z]'){
$Value1=""}
$value1
# get second value
$Value2=$Value.substring(6,4).Insert(2,".")
if($value2 -match '[a-z]'){
$Value2=""}
$value2
#get third value - continue as necessary if you have more channels
$Value3=$Value.substring(11,4).Insert(2,".")
if($value3 -match '[a-z]'){
$Value3=""}
$value3
#check for completely empty string in case of device malfunction, append valid results to output file
$checkresult=$Value1 + $Value2 + $Value3
if ($checkresult -ne "") {
#add timestamp
$now=(get-date -Format "yyyy-MM-dd HH:mm:ss").tostring()
#build result string for debug log
$result=$now + ";" + $Value1 + ";" + $Value2 + ";" + $Value3
# uncomment for debug log on hdd, log an be used eg. in Excel
# $result|out-file $outputfile -Append
#output prtg xml code - a little clumsy, to allow explicit names for each sensor
#extend as needed if more channels are in use
write-host "<?xml version="1.0" encoding="UTF-8" ?>"
write-host "<prtg>"
write-host "<result>"
write-host "<channel>Serverraum1</channel>"
write-host "<value>$Value1</value>"
write-host "<Unit>Temperature</Unit>"
write-host "<float>1</float>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMaxWarning>28</LimitMaxWarning>"
write-host "<LimitMaxError>30</LimitMaxError>"
write-host "<LimitErrorMsg>Kühlung ausgefallen!</LimitErrorMsg>"
write-host "</result>"
write-host "<result>"
write-host "<channel>Serverraum2</channel>"
write-host "<value>$Value2</value>"
write-host "<Unit>Temperature</Unit>"
write-host "<float>1</float>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMaxWarning>28</LimitMaxWarning>"
write-host "<LimitMaxError>30</LimitMaxError>"
write-host "<LimitErrorMsg>Kühlung ausgefallen!</LimitErrorMsg>"
write-host "</result>"
write-host "<result>"
write-host "<channel>Unterverteiler 1</channel>"
write-host "<value>$Value3</value>"
write-host "<Unit>Temperature</Unit>"
write-host "<float>1</float>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMaxWarning>28</LimitMaxWarning>"
write-host "<LimitMaxError>30</LimitMaxError>"
write-host "<LimitErrorMsg>Kühlung ausgefallen!</LimitErrorMsg>"
write-host "</result>"
write-host "</prtg>"
}
else
{
write-host "<prtg>"
write-host "<error>1</error>"
write-host "<text>Thermometer ist ausgefallen!</text>"
write-host "</prtg>"
}
Add comment