Created
February 13, 2019 19:24
-
-
Save hkelley/8a37ec06d3f17ad7117f7d79c233f709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param | |
( | |
[Parameter(Mandatory = $true)] [string] $hostname | |
, [Parameter(Mandatory = $true)] [string] $username | |
, [Parameter(Mandatory = $true)] [string] $password | |
) | |
$url = "https://$hostname/status/minemeld" | |
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password))) | |
[datetime]$origin = '1970-01-01 00:00:00Z' | |
######### | |
try { ### GLOBAL ERROR HANDLER | |
######### | |
$resp = Invoke-RestMethod -Method Get -Uri $url -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} | |
$results = New-Object System.Collections.ArrayList # Keep an array of results so that we can report failures last (keeps the red lights on in the Tembria UI) | |
# get only inputs (which have runtimes) | |
foreach($r in $resp.result | ?{$_.last_successful_run -gt 0}) | |
{ | |
$dtLastSuccessRun = $origin.AddSeconds($r.last_successful_run/1000 ) | |
if($r.sub_state -eq "SUCCESS") | |
{ | |
# Put success events at the beginning of the array | |
$results.Insert(0, ("Success({0})=Miner {1} ran with {2} at {3:u}" -f $hostname,$r.name,$r.sub_state,$dtLastSuccessRun.ToUniversalTime()) ) | |
} | |
else | |
{ | |
# Put error events at the beginning of the array so that they are the last thing FrameFlow sees | |
[void] $results.Add(("Failure({0})=Miner {1} ran with {2} at {3:u}. {4}" -f $hostname,$r.name,$r.sub_state,$dtLastSuccessRun.ToUniversalTime(),$r.sub_state_message)) | |
} | |
} | |
#dequeue the messages | |
foreach( $result in $results) | |
{ | |
Write-Host $result | |
} | |
######### | |
} catch { ### GLOBAL ERROR HANDLER | |
######### | |
Write-Host ("Failure({0})=Script: {1} Line: {2} Position: {3}<br/>{4}<br/>{5}" -f $hostname,$_.InvocationInfo.ScriptName,$_.InvocationInfo.ScriptLineNumber,$_.InvocationInfo.OffsetInLine,$_.Exception,$_.Exception.StackTrace) | |
######### | |
} ### GLOBAL ERROR HANDLER | |
######### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment