CODERsp
Active member
I wrote masternodes monitoring script for myself and decided to post it here, because it can be useful for somebody. The idea is to get notifications about masternode payments and problems using drk.mn, cron, php and mysql. I used Yii Framework as environment.
Code:
CREATE TABLE IF NOT EXISTS `refMasternodes` (
`IPPort` varchar(255) NOT NULL,
`Balance` decimal(16,8) NOT NULL,
`IsActive` tinyint(1) NOT NULL,
PRIMARY KEY (`IPPort`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `refMasternodes` (`IPPort`, `Balance`, `IsActive`) VALUES
('000.000.000.000:9999', '1000.00000000', 0);
PHP:
$masternodes = refMasternodes::model()->findAll();
foreach ($masternodes as $masternode) {
$json = file_get_contents('https://drk.mn/api/masternodes?testnet=0&portcheck=1&balance=1&ips=["' . $masternode->IPPort . '"]');
if ($json !== false && ($data = json_decode($json, true)) !== null && $data['status'] == 'OK') {
if (($row = reset($data['data'])) !== false) {
$mnBalance = (float)$masternode->Balance;
$rowBalance = (float)$row['Balance']['Value'];
if ($mnBalance != $rowBalance) {
$this->sendSMS($masternode->IPPort . ': ' . (float)bcsub($rowBalance, $mnBalance, 8) . ' DRK');
$masternode->Balance = $rowBalance;
$masternode->update();
}
if ($masternode->IsActive == 0 && $row['Portcheck']['Result'] == 'open') {
$this->sendSMS($masternode->IPPort . ': OPEN');
$masternode->IsActive = 1;
$masternode->update();
} elseif ($masternode->IsActive == 1 && $row['Portcheck']['Result'] == 'closed') {
$this->sendSMS($masternode->IPPort . ': CLOSED');
$masternode->IsActive = 0;
$masternode->update();
}
} elseif ($masternode->IsActive == 1) {
$this->sendSMS($masternode->IPPort . ': UNLISTED');
$masternode->IsActive = 0;
$masternode->update();
}
}
}
Last edited by a moderator: