PowerShell script to get temperature from NetBotz

Wrote this to extract the temperature reading from a few NetBotz devices that I have in my datacentres.

Note that the second time I call the function, it is getting the temperature from a second (non-docked) sensor pod attached to the first NetBotz.

function Get-NetBotzTemp($Name,$URL,$User,$Pass){
    # set up web client and authentication
    $WebClient = New-Object System.Net.WebClient
    $CredCache = New-Object System.Net.CredentialCache
    $Credential = New-Object System.Net.NetworkCredential($CredUser,$CredPass)
    $CredCache.Add($URL,"Basic", $Credential)
    $WebClient.Credentials = $CredCache
    # get text contents of web page
    $WebPage = $WebClient.DownloadString($URL)
    # ditch the first part of the page, up until the numeric temperature value
    $LastPart = ($WebPage -split ',*_TEMP.+pic">')[1]
    # ditch the last part of the page, after the numeric temperature value
    $Farenheight = ($LastPart -split ' °F')[0]
    # NetBotz defaults to farenheit based on what it think the browser is, so convert the centigrade
    $Celcius = ($Farenheight - 32) / 1.8
    $Celcius = "{0:N1}" -f $Celcius
    # display output
    Write-Host ("Temperature in "+$Name+" is $Celcius")
}

Get-NetBotzTemp -Name "DC1" -URL "http://192.168.100.21/pages/status.html" -User "netbotz" -Pass "netbotz"
Get-NetBotzTemp -Name "DC2" -URL "http://192.168.100.21/pages/status.html?encid=nbHawkEnc_1" -User "netbotz" -Pass "netbotz"
Get-NetBotzTemp -Name "DC3" -URL "http://192.168.100.22/pages/status.html" -User "netbotz" -Pass "netbotz"

This entry was posted in PowerShell, Scripting and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s