Skip to content

Instantly share code, notes, and snippets.

@utarn
Last active October 14, 2018 12:26
Show Gist options
  • Save utarn/471b060ab565b1f3a663abd78e865a3e to your computer and use it in GitHub Desktop.
Save utarn/471b060ab565b1f3a663abd78e865a3e to your computer and use it in GitHub Desktop.
param(
[Parameter(Mandatory=$false)]
[Array]$NicehashWallet = ("3L32PcgfiBEsySLrJpJWYN2thjm2NNGBt2"),
[Parameter(Mandatory=$false)]
[Array]$AhashWallet,
[Parameter(Mandatory=$false)]
[Array]$PhiPhiWallet,
[Parameter(Mandatory=$false)]
[Array]$ZpoolWallet = ("3G1RpD6mumCf2Hgo6h78WSn41ALA1432c5"),
[Parameter(Mandatory=$false)]
[Array]$BlazeWallet = ("3G1RpD6mumCf2Hgo6h78WSn41ALA1432c5"),
[Parameter(Mandatory=$false)]
[String]$LineAccessToken = "57yHPNUuzLJJqYbx4KeuV1If9MAjxp41N2ygY0GgsON",
[Parameter(Mandatory=$false)]
[Int]$WaitTime = 600,
[Parameter(Mandatory=$false)]
[Int]$Loop = 6,
[Parameter(Mandatory=$false)]
[String]$NHBaseURL = "https://api.nicehash.com",
[Parameter(Mandatory=$false)]
[String]$AhashBaseURL = "http://www.ahashpool.com",
[Parameter(Mandatory=$false)]
[String]$PhiPhiBaseURL = "http://www.phi-phi-pool.com",
[Parameter(Mandatory=$false)]
[String]$ZpoolBaseURL = "https://www.zpool.ca",
[Parameter(Mandatory=$false)]
[String]$BlazeBaseURL = "http://api.blazepool.com",
[Parameter(Mandatory=$false)]
[Double]$Threshold = 0.1,
[Parameter(Mandatory=$false)]
[Boolean]$SendMoney = $true,
[Parameter(Mandatory=$false)]
[Boolean]$NicehashStat = $false,
[Parameter(Mandatory=$false)]
[String]$Worker = "oohpc",
[Parameter(Mandatory=$false)]
[Int]$NoOfDevices = 3,
[Parameter(Mandatory=$false)]
[Array]$RequiredNicehashWorker = ("ooheth","oohrig1","oohrig2", "oohrig3")
)
[console]::BackgroundColor = "black"
[console]::ForegroundColor = "white"
$lineURI = "https://notify-api.line.me/api/notify"
$header = @{}
$header.Add("Authorization","Bearer $($LineAccessToken)")
$nicehashURI = "http://localhost:38080/api?command%3D"
$count = 0
$AhashMiners = [System.Collections.ArrayList]@()
$PhiPhiMiners = [System.Collections.ArrayList]@()
$ZpoolMiners = [System.Collections.ArrayList]@()
$BlazeMiners = [System.Collections.ArrayList]@()
$NextInform = $false
$Critical = $false
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$AllWallet = $(($NicehashWallet+$AhashWallet+$PhiPhiWallet+$ZpoolWallet) -join ' ') -replace '\s+', ' '
while($true)
{
Clear-Host
Write-Host Utharn Balance Monitor v1.1 -ForegroundColor Magenta
Write-Host ================================================================== -ForegroundColor Magenta
Write-Host "Failed Threshold : $Threshold Mh/s" -ForegroundColor White
Write-Host "Required Workers : $RequiredNicehashWorker" -ForegroundColor White
Write-Host "Wait time to check : $WaitTime second" -ForegroundColor White
Write-Host "Number of loops : $Loop loop" -ForegroundColor White
Write-Host "Wallet address : $AllWallet" -ForegroundColor White
Write-Host "Line access token : $LineAccessToken" -ForegroundColor White
Write-Host "Critical : $Critical" -ForegroundColor White
Write-Host ================================================================== -ForegroundColor Magenta
$RequiredNicehashWorkers = $RequiredNicehashWorker
$Critical = $false
if ($NextInform) {
$Critical = $true
$NextInform = $false
}
$msg = "`r`nWorker: $($Worker)"
If ($SendMoney) {
$BXCurrency = ((Invoke-WebRequest -Uri https://bx.in.th/api/ -UseBasicParsing | ConvertFrom-Json).1 | Select -First 1).last_price;
$Currency = (Invoke-WebRequest "https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=THB" -UseBasicParsing -TimeoutSec 10| ConvertFrom-Json).price_thb;
$CurrencyUSD = (Invoke-WebRequest "https://api.coinmarketcap.com/v1/ticker/bitcoin/" -UseBasicParsing -TimeoutSec 10| ConvertFrom-Json).price_usd;
$Diff = (($BXCurrency - $Currency) / $Currency) * 100;
$Fee = [double](Invoke-WebRequest -Uri https://estimatefee.com/n/6).content * 417 * 1000
$msg = "`r`nBTC USD : $($([double]$CurrencyUSD).ToString("###,###"))`r`n"`
+ "BTC THB : $($([double]$Currency).ToString("###,###"))`r`n"`
+ "BX THB : $($([double]$BXCurrency).ToString("###,###"))`r`n"`
+ "Different : $($([double]$Diff).ToString("##.##"))%`r`n"`
+ "Tx fee : $($Fee.ToString("0.####")) µBTC`r`n"
$msg += "`r`n"
if ($NicehashWallet.Count -gt 0) {
$msg += "Nicehash Stat`r`n"
}
$NicehashWallet | ForEach-Object {
Try
{
if ($_)
{
$CurrentWallet = $_
$msg += "Wallet : $_`r`n"
$NicehashQuery = $NHBaseURL + "/api?method=stats.provider&addr=$_"
$NicehashStatus = (Invoke-WebRequest -Uri $NicehashQuery -UseBasicParsing -TimeoutSec 10 | ConvertFrom-Json)
$NicehashPayRateQuery = "https://api.nicehash.com/api?method=stats.global.current"
$NicehashPayRateStatus = (Invoke-WebRequest -Uri $NicehashPayRateQuery -UseBasicParsing -TimeoutSec 10 | ConvertFrom-Json)
$TotalBalance = 0.0
$msg += "Algorithm/Speed :`r`n"
$msg += "-------------------------------------------"
$NicehashStatus.result.stats | ForEach-Object {
if ([double]$_.balance -gt 0.0000001 -and [double]$_.accepted_speed -gt 0 ) {
$AlgoInt = [int]$_.algo
$currentAlgo = Switch ($AlgoInt) { 20{ "Ethash" } 21{ "Decred" } 30{ "CryptoNightV7" } 8{"NeoScrypt"} 14 {"Lyra2REv2"} 31 {"CryptoNightHeavy"} 32{"Lyra2Z"} 24{"Equihash"} 33{"X16R"} }
$speed = ([double]$_.accepted_speed * 1000).ToString("0") + "Mh/s"
if ($AlgoInt -eq 24) {
$speed = ([double]$_.accepted_speed * 1000000000).ToString("0") + "Sol/s"
}
if ($AlgoInt -eq 30 -or $AlgoInt -eq 31) {
$speed = ([double]$_.accepted_speed * 1000000).ToString("0") + "Kh/s"
}
$balance = $_.balance
$NicehashWorkerQuery = $NHBaseURL + "/api?method=stats.provider.workers&addr=" + $CurrentWallet + "&algo=" + $AlgoInt
$NicehashWorkerStatus = (Invoke-WebRequest -Uri $NicehashWorkerQuery -UseBasicParsing -TimeoutSec 10 | ConvertFrom-Json)
if ($NicehashWorkerStatus.result.workers.Count -ne 0) {
$msg += "`r`n$currentAlgo at $speed`r`n["
$NicehashWorkerStatus.result.workers | Sort-Object | ForEach-Object {
$msg += $_.Item(0) +"("+ ([double]$_.Item(1).a).ToString("0") + "),"
$CurrentWorker = $_.Item(0)
$RequiredNicehashWorkers = [Array]($RequiredNicehashWorkers | Where-Object { $_ -ne $CurrentWorker })
}
$msg = $msg.Substring(0,$msg.Length-1)
$msg += "]`r`n"
$CurrentRate = ($NicehashPayRateStatus.result.stats | ? { $_.algo -eq $AlgoInt }).price
if ($AlgoInt -eq 20) {
$CurrentRate = [double]$CurrentRate
}
$msg += "NowPay : $CurrentRate"
if ($AlgoInt -eq 20) {
$msg += " mBTC/GH"
} elseif ($AlgoInt -eq 24) {
$msg += " mBTC/KSol"
}
elseif ($AlgoInt -eq 30 -or $AlgoInt -eq 31) {
$msg += " mBTC/KH"
} else {
$msg += " mBTC/MH"
}
$msg += "`r`n-------------------------------------------"
}
}
$TotalBalance += [double]$_.balance
}
$TotalBalance *= 1000
$msg += "`r`nBalance : $Totalbalance mBTC`r`n"
}
}
Catch
{
$ErrorMessage = $_.Exception.Message;
$FailedItem = $_.Exception.ItemName;
Write-Host $ErrorMessage $FailedItem;
Write-Host "Nicehash error"
$NextInform = $true
}
}
$msg += "=======================`r`n"
if ($AhashWallet.Count -gt 0) {
$msg += "Ahashpool Stat`r`n"
}
$AhashWallet | ForEach-Object {
Try
{
if ($_)
{
$PoolQuery = $AhashBaseURL + "/api/walletEx?address=$_"
$AhashWalletStatus = (Invoke-WebRequest -Uri $PoolQuery -UseBasicParsing -TimeoutSec 10 | ConvertFrom-Json)
$AhashMiners.Clear()
$Unsold = $AhashWalletStatus.unsold * 1000
$Balance = $AhashWalletStatus.balance * 1000
$Unpaid = $AhashWalletStatus.total_unpaid * 1000
$Paid24h = $AhashWalletStatus.total_paid * 1000
$msg += "Wallet : $_`r`n"`
+ "Unsold : $($Unsold.ToString("0.#####")) mBTC`r`n"`
+ "Balance : $($Balance.ToString("0.#####")) mBTC`r`n"`
+ "Unpaid : $($Unpaid.ToString("0.#####")) mBTC`r`n"`
+ "Paid : $($Paid24h.ToString("0.####")) mBTC`r`n"`
+ "Miners : ";
$AhashWalletStatus.miners | ForEach-Object {
$a =@{}
$a | Add-Member version $_.version
$a | Add-Member Rate ($_.accepted / 1000000).ToString("0.00")
# $a | Add-Member Rate 1.56
$Name = $_.password.Split(",") | ? { $_ -match "ID=" } | Select -First 1
$Name = $Name -replace "ID=",""
$a | Add-Member ID $Name
if ([Double]$a.Rate -gt 0) {
$AhashMiners.Add($a) | Out-Null
$msg += "$($a.ID)($($a.Rate)Mh/s) "
}
}
if ($AhashWalletStatus.miners.Count -eq 0) {
$msg += "(none)"
}
$msg += "`r`n"
}
}
Catch
{
#$ErrorMessage = $_.Exception.Message;
#$FailedItem = $_.Exception.ItemName;
#Write-Host $ErrorMessage $FailedItem;
Write-Host "Ahashpool error"
$NextInform = $true
}
}
$AhashMiners | ForEach-Object {
$RateDigit = [Double]$_.Rate
if (($RateDigit -le $Threshold) -and ($RateDigit -gt 0)) {
$Critical = $true
}
}
if ($PhiPhiWallet.Count -gt 0) {
$msg += "`r`nPhiPhi Stat`r`n"
}
$PhiPhiWallet | ForEach-Object {
Try
{
if ($_)
{
$PoolQuery = $PhiPhiBaseURL + "/api/walletEx?address=$_"
$PhiPhiWalletStatus = (Invoke-WebRequest -Uri $PoolQuery -UseBasicParsing -TimeoutSec 10 | ConvertFrom-Json)
$PhiPhiMiners.Clear()
$Unsold = $PhiPhiWalletStatus.unsold * 1000
$Balance = $PhiPhiWalletStatus.balance * 1000
$Unpaid = $PhiPhiWalletStatus.unpaid * 1000
$Paid24h = $PhiPhiWalletStatus.paid24h * 1000
$msg += "Wallet : $_`r`n"`
+ "Unsold : $($Unsold.ToString("0.#####")) mBTC`r`n"`
+ "Balance : $($Balance.ToString("0.#####")) mBTC`r`n"`
+ "Unpaid : $($Unpaid.ToString("0.#####")) mBTC`r`n"`
+ "Paid24h : $($Paid24h.ToString("0.####")) mBTC`r`n"`
+ "Miners : ";
$PhiPhiWalletStatus.miners | ForEach-Object {
$a =@{}
$a | Add-Member version $_.version
$a | Add-Member Rate ($_.accepted / 1000000).ToString("0.00")
# $a | Add-Member Rate 1.56
$Name = $_.password.Split(",") | ? { $_ -match "ID=" } | Select -First 1
$Name = $Name -replace "ID=",""
$a | Add-Member ID $Name
if ([Double]$a.Rate -gt 0) {
$PhiPhiMiners.Add($a) | Out-Null
$msg += "$($a.ID)($($a.Rate)Mh/s) "
}
}
if ($PhiPhiWalletStatus.miners.Count -eq 0) {
$msg += "(none)"
}
$msg += "`r`n"
}
}
Catch
{
$ErrorMessage = $_.Exception.Message;
$FailedItem = $_.Exception.ItemName;
Write-Host $ErrorMessage $FailedItem;
#Write-Host "PhiPhi error"
$NextInform = $true
}
}
$PhiPhiMiners | ForEach-Object {
$RateDigit = [Double]$_.Rate
if (($RateDigit -le $Threshold) -and ($RateDigit -gt 0)) {
$Critical = $true
}
}
if ($ZpoolWallet.Count -gt 0) {
$msg += "`r`nZpool Stat`r`n"
}
$ZpoolWallet | ForEach-Object {
Try
{
if ($_)
{
$PoolQuery = $ZpoolBaseURL + "/api/walletEx?address=$_"
$AlgoQuery = $ZpoolBaseURL + "/api/status"
$ZpoolWalletStatus = (Invoke-WebRequest -Uri $PoolQuery -UseBasicParsing -TimeoutSec 20 | ConvertFrom-Json)
$ZpoolMiners.Clear()
$AlgoStatus = (Invoke-WebRequest -Uri $AlgoQuery -UseBasicParsing -TimeoutSec 20 | ConvertFrom-Json)
$Unsold = $ZpoolWalletStatus.unsold * 1000
$Balance = $ZpoolWalletStatus.balance * 1000
$Unpaid = $ZpoolWalletStatus.unpaid * 1000
$Paid24h = $ZpoolWalletStatus.paid24h * 1000
$msg += "Wallet : $_`r`n"`
+ "Unsold : $($Unsold.ToString("0.#####")) mBTC`r`n"`
+ "Balance : $($Balance.ToString("0.#####")) mBTC`r`n"`
+ "Unpaid : $($Unpaid.ToString("0.#####")) mBTC`r`n"`
+ "Paid24h : $($Paid24h.ToString("0.####")) mBTC`r`n"`
+ "Miners : ";
$algo =@()
$ZpoolWalletStatus.miners | ForEach-Object {
$a =@{}
$a | Add-Member version $_.version
$a | Add-Member Rate ($_.accepted / 1000000).ToString("0.00")
$algo += $_.algo
$Name = $_.password.Split(",") | ? { $_ -match "ID=" } | Select -First 1
$Name = $Name -replace "ID=",""
$a | Add-Member ID $Name
if ([Double]$a.Rate -gt 0) {
$ZpoolMiners.Add($a) | Out-Null
$msg += "$($a.ID)($($a.Rate)Mh/s) "
}
}
if ($ZpoolWalletStatus.miners.Count -eq 0) {
$msg += "(none)"
}
else
{
$ZpoolMiners | ForEach-Object {
$CurrentWorker = $_.ID
$RequiredNicehashWorkers = [Array]($RequiredNicehashWorkers | Where-Object { $_ -ne $CurrentWorker })
}
}
$msg += "`r`n"
# $AlgoStatus = (Invoke-WebRequest -Uri $AlgoQuery -UseBasicParsing -TimeoutSec 20 | ConvertFrom-Json)
$algo = $algo | Select -Unique | ForEach-Object {
$CurrentAlgo = $AlgoStatus.$_
$AlgoCurrentRate = [double]$CurrentAlgo.estimate_current * 1000
$AlgoActualRate = [double]$CurrentAlgo.actual_last24h
$msg += "Mining Algo: $($_)`r`n"`
+ "CurrentRate : $($AlgoCurrentRate.ToString("0.####")) mBTC/GH/day`r`n"`
+ "ActualRate : $($AlgoActualRate.ToString("0.####")) mBTC/GH/day`r`n"`
}
}
}
Catch
{
$ErrorMessage = $_.Exception.Message;
$FailedItem = $_.Exception.ItemName;
Write-Host $ErrorMessage $FailedItem;
#Write-Host "Zerg error"
$NextInform = $true
}
}
$ZpoolMiners | ForEach-Object {
$RateDigit = [Double]$_.Rate
if (($RateDigit -le $Threshold) -and ($RateDigit -gt 0)) {
$Critical = $true
}
}
if ($BlazeWallet.Count -gt 0) {
$msg += "`r`nBlaze Stat`r`n"
}
$BlazeWallet | ForEach-Object {
Try
{
if ($_)
{
$PoolQuery = $BlazeBaseURL + "/wallet/$_"
$AlgoQuery = $BlazeBaseURL + "/api/status"
$BlazeWalletStatus = (Invoke-WebRequest -Uri $PoolQuery -UseBasicParsing -TimeoutSec 20 | ConvertFrom-Json)
$BlazeMiners.Clear()
$AlgoStatus = (Invoke-WebRequest -Uri $AlgoQuery -UseBasicParsing -TimeoutSec 20 | ConvertFrom-Json)
$Unsold = $BlazeWalletStatus.unsold * 1000
$Balance = $BlazeWalletStatus.balance * 1000
$Unpaid = $BlazeWalletStatus.total_unpaid * 1000
$Paid = $BlazeWalletStatus.total_paid * 1000
$msg += "Wallet : $_`r`n"`
+ "Unsold : $($Unsold.ToString("0.#####")) mBTC`r`n"`
+ "Balance : $($Balance.ToString("0.#####")) mBTC`r`n"`
+ "Unpaid : $($Unpaid.ToString("0.#####")) mBTC`r`n"`
+ "Paid : $($Paid.ToString("0.####")) mBTC`r`n"`
+ "Miners : ";
$algo =@()
$BlazeWalletStatus.miners | ForEach-Object {
$a =@{}
$a | Add-Member version $_.version
$a | Add-Member Rate ($_.accepted / 1000000).ToString("0.00")
$algo += $_.algo
$Name = $_.password.Split(",") | ? { $_ -match "ID=" } | Select -First 1
$Name = $Name -replace "ID=",""
$a | Add-Member ID $Name
if ([Double]$a.Rate -gt 0) {
$BlazeMiners.Add($a) | Out-Null
$msg += "$($a.ID)($($a.Rate)Mh/s) "
}
}
if ($BlazeWalletStatus.miners.Count -eq 0) {
$msg += "(none)"
}
else
{
$BlazeMiners | ForEach-Object {
$CurrentWorker = $_.ID
$RequiredNicehashWorkers = [Array]($RequiredNicehashWorkers | Where-Object { $_ -ne $CurrentWorker })
}
}
$msg += "`r`n"
$algo = $algo | Select -Unique | ForEach-Object {
$CurrentAlgo = $AlgoStatus.$_
$AlgoCurrentRate = [double]$CurrentAlgo.estimate_current * 1000
$AlgoActualRate = [double]$CurrentAlgo.actual_last24h
$msg += "Mining Algo: $($_)`r`n"`
+ "CurrentRate : $($AlgoCurrentRate.ToString("0.####")) mBTC/GH/day`r`n"`
+ "ActualRate : $($AlgoActualRate.ToString("0.####")) mBTC/GH/day`r`n"`
}
}
}
Catch
{
$ErrorMessage = $_.Exception.Message;
$FailedItem = $_.Exception.ItemName;
Write-Host $ErrorMessage $FailedItem;
#Write-Host "Zerg error"
$NextInform = $true
}
}
$BlazeMiners | ForEach-Object {
$RateDigit = [Double]$_.Rate
if (($RateDigit -le $Threshold) -and ($RateDigit -gt 0)) {
$Critical = $true
}
}
if ($RequiredNicehashWorkers.Count -gt 0) {
$msg += "Stopped Workers : $RequiredNicehashWorkers`r`n"
$Critical = $true
$NextInform = $true
}
}
$msg2 = ""
If ($NicehashStat) {
0..$($NoOfDevices-1) | ForEach-Object {
Try
{
$data = Invoke-WebRequest -Uri http://localhost:38080/api?command%3D%7B%22id%22%3A1%2C%22method%22%3A%22device.get%22%2C%22params%22%3A%5B%22$($_)%22%5D%7D -UseBasicParsing | ConvertFrom-Json
$result =@{}
$result | Add-Member -MemberType NoteProperty -Name device_id -Value $data.device_id
$result | Add-Member -MemberType NoteProperty -Name gpu_temp -Value $data.gpu_temp
$result | Add-Member -MemberType NoteProperty -Name power -Value $data.gpu_power_usage
$result | Add-Member -MemberType NoteProperty -Name fan -Value $data.gpu_fan_speed_rpm
$msg2 += "`r`GPU:$($result.device_id) Temp:$($result.gpu_temp)C Pow:$($result.power.ToString("0"))W Fan:$($result.fan)RPM`r`n"
}
Catch
{
#$ErrorMessage = $_.Exception.Message;
#$FailedItem = $_.Exception.ItemName;
#Write-Host $ErrorMessage $FailedItem;
Write-Host "Excavator Error"
}
}
}
Try
{
$body =@{message="$($msg + $msg2)"}
$sending = $count % $Loop -eq 0
Write-Host $(Get-Date -Format "dd/MM/yyyy HH:mm:ss") " " -ForegroundColor Cyan -NoNewline
if ($LineAccessToken -and ($sending -or $Critical)) {
Write-Host PC and Line -ForegroundColor Green
}
else
{
Write-Host PC-Only -ForegroundColor Red
}
If ($SendMoney) {
Write-Host Mining Stats -ForegroundColor Cyan
Write-Host $msg -ForegroundColor Yellow
}
If ($NicehashStat) {
Write-Host Nicehash Excavator Stats -ForegroundColor Cyan
Write-Host $msg2 -ForegroundColor Yellow
}
if ($LineAccessToken -and ($sending -or $Critical)) {
Invoke-WebRequest -Uri $lineURI -Method POST -Headers $header -Body $body -UseBasicParsing -TimeoutSec 10 | Out-Null
}
$count += 1
}
Catch
{
#$ErrorMessage = $_.Exception.Message;
#$FailedItem = $_.Exception.ItemName;
#Write-Host $ErrorMessage $FailedItem;
Write-Host "Line error"
}
Start-Sleep -s $WaitTime
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment