Upgrades Alert System
1. Scan for new Upgrade proposals once every 30 minutes
Code is in PHP
This code scans for new upgrade proposals once every 30 minutes and outputs the data to a .json file (example - proposals.json)
<?php
$jsonFilePath = '/var/www/html/proposals.json';
$jsonContents = file_get_contents($jsonFilePath);
$existingProposals = json_decode($jsonContents, true);
$final = $existingProposals;
$chains = [
"cosmoshub",
"archway",
"axelar",
"canto",
"evmos",
"kava",
"kujira",
"mars",
"meme",
"migaloo",
"oraichain",
"planq",
"provenance",
"stride",
"tenet",
"terra2"
];
foreach ($chains as $chain) {
$api = "https://rest.cosmos.directory/". $chain . "/cosmos/gov/v1beta1/proposals";
$rpc = "https://rpc.cosmos.directory/". $chain;
$ch = curl_init($api . '?proposal_status=2');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($ch);
curl_close($ch);
$result = json_decode($resp, true);
foreach ($result['proposals'] as $proposal) {
$pid = $proposal['proposal_id'];
$type = $proposal['content']['@type'];
if (strpos($type, 'SoftwareUpgradeProposal') !== false) {
$newProposal = [
"chain" => ucfirst($chain),
"pid" => $pid,
"rpc" => $rpc,
"api" => $api . '/' . $pid,
];
$exists = false;
foreach ($existingProposals as $existingProposal) {
if ($existingProposal['chain'] === $newProposal['chain'] && $existingProposal['pid'] === $newProposal['pid']) {
$exists = true;
break;
}
}
if (!$exists) {
$final[] = $newProposal;
}
}
}
}
echo json_encode($final, JSON_UNESCAPED_SLASHES);
?>Create a .sh file called ``proposals.sh``
Setup a cronjob to run the above code once every 30 mins.
Now, proposals.json will contain the following:
2. Update Status & Current Block number once every 5 Minutes
Read the proposals.json file once every 5 minutes, update the status of the proposal, and update current block number of the blockchain.
Code is in PHP.
Setup a cronjob to run the above code once every 30 mins.
Now, upgrades.json will contain the following:
3. NodeJs file to run every 5 Minutes for PagerDuty alerts
The following NodeJs code is executed every 5 minutes to send an alert using PagerDuty when the remaining blocks to upgrade reaches below 1000 blocks, then, again when the blocks remaining reaches below 500, and one more when the blocks remaining reaches below 100.
In this example, we do this for Cosmos Hub blockchain.
Last updated