Reading ServersCheck Status page from command line – Part 2.

In the Part 1. of the article I showed command line tool written with Google Go that reads current values from ServersCheck temperature and humidity sensor. In part 2 of the article I’ll show you how I did the same with PowerShell 3.0 script. In a way this script is more sophisticated than the golang variant. First because of the way how password for ServersCheck is handled, instead of security by obscurity I’m asking user once for a password, then storing password encrypted with a combination of his/her computer private key + user session key in a local file vpctemp-pwd.txt. Not bullet proof but nevertheless a big improvement from golang version of the script.
Second, the way I parse xml in powershell is simplified, thanks to select-xml cmdlet built in powershell 3.0.

A prerequisite for running the script is:
– PowerShell 3.0 (hence .NET 4 framework is also needed)
– execution policy must be set to RemoteSigned

You can check PowerShell version with:

PS> get-host | select version

and execution policy with (make sure that you run PowerShell in Admin mode!):

PS> Get-ExecutionPolicy

and if it's not RemoteSigned change it with:

PS> Set-ExecutionPolicy RemoteSigned

Final result of the script is output similar to golang version:


And here is the powershell script source:

# vpctemp.ps1 - PowerShell 3.0 script
# by AlesK 
$version = "v0.10"
$uri = ""
$username = "admin"
$pwdfile = ".\vpctemp-pwd.txt"

if (Test-Path $pwdfile) {
 $password = Get-Content $pwdfile | ConvertTo-SecureString
else {
 $password = Read-Host "Password for Admin" -AsSecureString
 $password | ConvertFrom-SecureString | Out-File $pwdfile

$credential = New-Object System.Management.Automation.PSCredential $username,$password

$result = Invoke-Webrequest -URI $uri -Credential $credential -UseBasicParsing

[xml]$xml = $result | select -expand Content 

$temp1 = $xml | select-xml -xpath '/retcurvalue/ssvalue0' | select -expand Node 
$temp2 = $xml | select-xml -xpath '/retcurvalue/ssvalue1' | select -expand Node 
$hum1  = $xml | select-xml -xpath '/retcurvalue/ssvalue2' | select -expand Node 
$timestamp = Get-Date

Write-Host "VPCtemp $version        Location: VPC1"
Write-Host "***********************************"
Write-Host "Timestamp     :", $timestamp
Write-Host "Temp. internal:", $temp1."#text"
Write-Host "Temp. external:", $temp2."#text" -foregroundcolor "yellow" -backgroundcolor "red"
Write-Host "Humidity      :", $hum1."#text"

In the final, part 3 of the article I’ll show you how we’re using Oracle external table “preprocessor” feature to display data center temperature and humidity with simple SQL statement.


Posted on 26.08.2013, in Scripting and tagged , . Bookmark the permalink. Comments Off on Reading ServersCheck Status page from command line – Part 2..

Comments are closed.