-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkmn.php
62 lines (48 loc) · 1.67 KB
/
checkmn.php
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
<?php
require_once __DIR__.'/include/init.inc.php';
$hostname = 'https://www.ariochain.info'; // Report hostname
$reportUri = '/api/v1/public/peers.json'; // Report URI
$notifyEmail = 'dev@ariochain.info'; // Send mail to
$show = true; // Show results in terminal
// Your IP addresses you want to check
$checkNodes = [
'5.5.95.239',
];
// Load report
$apiUrl = $hostname.$reportUri;
$ariochainReport = file_get_contents($apiUrl);
$json = json_decode($ariochainReport, true); // Formated result
// Our nodes
foreach ($checkNodes as $node) {
if ($show) {
echo $node.' ';
}
// Get node's current block
$url = 'http://'.$node.'/peer.php?q=';
$data = peer_post($url.'currentBlock', [], 5);
// Report data
foreach ($json['peers'] as $peer) {
// Our node matching report entry
if ($peer['ip'] == $node) {
if ($data['height'] !== $peer['lastblock']) { // If reporting has wrong number
$peer['lastblock'] == $data['height']; // Display current block
} elseif ($peer['status'] == 'behind') { // If reporting has last block, check if status is behind
// Send notification
$to = $notifyEmail;
$subject = 'Node '.$node.' behind';
$txt = 'Your node '.$node.' is behind.';
$headers = 'From: '.$notifyEmail;
mail($to, $subject, $txt, $headers);
}
if ($show) {
echo $peer['lastblock'].' ';
}
if ($show) {
echo $peer['status'].' ';
}
}
}
if ($show) {
echo "\n";
}
}