-
Notifications
You must be signed in to change notification settings - Fork 1
/
tron-monitor.ps1
109 lines (83 loc) · 3.48 KB
/
tron-monitor.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Tron Monitor v0.4
# https://github.com/dbriggsie/tron-monitor/
#
# All the lines starting with # Tag are a comment, please read them carefully to configure settings correctly.
# This program will run in an infinite loop, which means you need to stop this script if you don't want to let it run.
#Please Change the Producerkey to your own Witness Address.
$ProducerKey = "TAbzgkG8p3yF5aywKVgq9AaAu6hvF2JrVC"
# Configure this Minute value, so that script can run on this interval, 5 value denotes that script will wait for 5 minute
# to re-check, Change according to the requirement can be any decimal value 1,2,3,4,5 etc...
$CheckAfterEveryMin = 2
#Configure the from email id
$EmailFrom = "user@domain.net"
#Configure email id to whom you want to send email
$EmailTo = "user@domain.net"
#Configure the subject line
$EmailSubject = "[Alert] Witness Node has Stopped Producing Blocks"
#Configure SMTP server either name or IP address
$SMTPServer = "smtphost.domain.net"
#Default SMTP port is 25 but incase SMTP is running on any other port, configure this $smtpport value
$SMTPPort = 25
#Configure the user name who is authorized to send an email
$SMTPAuthUsername = "username"
#Configure password of the user
$SMTPAuthPassword = "password"
#Configure the Settings to use SSL
$UseSSL = $true
#Configure the body text of the email
$emailbody = "[Alert] Witness Node has Stopped Producing Blocks"
$SMTPAuthPassword = $SMTPAuthPassword | Convertto-SecureString -AsPlainText -Force
$credentials = New-Object System.Management.Automation.Pscredential ($SMTPAuthUsername, $SMTPAuthPassword)
#Functions & Variables
$global:ProducerNumber = 0
$global:latestNumber = 0
function send_email {
if ($UseSSL)
{
Send-MailMessage -To $EmailTo -From $EmailFrom -SMTPServer $SMTPServer -UseSsl -Port $SMTPPort -Credential $credentials -Subject $EmailSubject -Body $emailbody
}
else
{
Send-MailMessage -To $EmailTo -From $EmailFrom -SMTPServer $SMTPServer -Port $SMTPPort -Credential $credentials -Subject $EmailSubject -Body $emailbody
}
}
function Get-blockdifference
{
$url = "https://api.tronscan.org/api/block?sort=-number&limit=1&count=true&producer=$ProducerKey"
$txt = Invoke-RestMethod $url
$global:latestNumber = $txt.data[0].number
if ($global:latestNumber -eq $global:ProducerNumber)
{
$blockdifference = $true
}
else
{
$blockdifference = $false
}
return $blockdifference
}
while(1)
{
$blockdifference = get-blockdifference
$waitforSeconds = 60 * $CheckAfterEveryMin
$Time = Get-Date -DisplayHint Time
if ($blockdifference)
{
Write-Host "Tron Monitor is Running - Witness Node has Stopped Producing Blocks" -BackgroundColor Red -ForegroundColor Black
Write-Host "Current Block: $global:latestNumber" -BackgroundColor Blue -ForegroundColor White
Write-Host "Last Block: $global:ProducerNumber" -BackgroundColor Blue -ForegroundColor White
Write-Host "Time $time" -BackgroundColor Blue -ForegroundColor White
Write-Host " "
send_email
}
else
{
Write-Host "Tron Monitor is Running - Witness Node is Operating Normally" -BackgroundColor Green -ForegroundColor Black
Write-Host "Current Block: $global:latestNumber" -BackgroundColor Blue -ForegroundColor White
Write-Host "Last Block: $global:ProducerNumber" -BackgroundColor Blue -ForegroundColor White
Write-Host "Time $time" -BackgroundColor Blue -ForegroundColor White
Write-Host " "
}
$global:ProducerNumber = $global:latestNumber
Start-Sleep -Seconds $waitforSeconds
}