create account

Hive Engine Witness Monitoring Script by blervin

View this thread on: hive.blogpeakd.comecency.com
· @blervin ·
$1.64
Hive Engine Witness Monitoring Script
### Hive Engine Witness Monitor Script

![monitoring.jpg](https://files.peakd.com/file/peakd-hive/blervin/23w2HG91SYr1Lw1MtFSkw4qVLrc3rg28ZDDWD9Fq798vf3wWxSWa9wbReMUY7xGeXCvur.jpg)

#### Introduction

Over the past month, I've been playing around a TON with my Hive Engine witness, I've probably deployed over 100 instances in testing, and unfortunately I've had a handful of missed blocks. Once you hit 3, your witness is disabled.

Fortunately, I spend nearly every waking moment of my life attached at the hip to my computer, so I did notice that I was down fairly quickly each time. Yet, I had no alert, nothing to tell me of trouble other than my own proactive review.

So, I got to work to hack together a script to let me know if something goes wrong. I have used the word 'hack' appropriately, because I am admittedly no JS dev so there may be HUGE gaps in my code, lol. That said, please share your thoughts, any updates, and I'd be moved to tears to see a pull request!

#### Setup
In short, while I'm *usually* at my desk, I am always near my phone so I wanted to be alerted there. Now, in my 'real' projects, I'll bust out some Twilio and send a text, but that's a bit much here. My workaround, uh hack, is to simply have @ginabot send me a message on Discord.

First of all, [sign up for @ginabot](https://peakd.com/steem/@ginabot/refresher-how-to-sign-up-for-ginabot)

If you already have @ginabot setup, the key that took me a minute to find, is to send this message in Discord `..set`

@ginabot will reply with a URL that allows you to configure your settings. The key thing to set is for Transfers:

![gina_transfer.png](https://files.peakd.com/file/peakd-hive/blervin/23tbH351NVLbcXCvbCPFu9gGpYPRKdogLjidd38DACvoe65B28JcSxMNZwL8MrpRFmJgk.png)

Check the 'others' box and you'll get a notification when any account sends you a transfer.

Once that's setup, we just need to run the script. I use `supervisor` to manage all of my nodejs scripts. I apologize for glossing over that here, I feel like that's well known and documented, but let me know if you'd like me to bang out a post about that.

Basically, the script makes an API call to a Hive Engine witness, and you can hit your own witness if you'd like!

We're just calling a list of active witnesses, then looping it to see if we're in there. If not, we send a small transfer to our account, which will appear as a Discord notification on your phone.

#### Hive Engine Witness Votes
So, I am genuinely humbled by the trust of the community in electing me into the top 10 Hive Engine witnesses! I've been even more thankful to watch my vote count slowly grow each day.

The honestly awesome part is that all of the other witnesses have seen their votes growing too, but that has meant that my rank has been continually dropping, moving from 6th, to 7th, and now hanging in at 8th.

All of this is to say, I would deeply appreciate your vote! I have several other projects that I'm working on and I've been anxious to release, but of course, there's always more work to do!

As always, please let me know if you need any help with this script or frankly anything at all! You can reach me directly on Discord: blervin#9759

#### The Script
I did update my [git repo](https://github.com/blervin/hiveenginewitness) so you can just pull the script directly from there if you'd like.

```
const rp = require('request-promise');
var hive = require('@hiveio/hive-js');
var fs = require('fs');

// let heUrl = "http://my_local_he_witness_ip_address:5000/contracts";
let heUrl = "https://api.hive-engine.com/rpc/contracts";

var fromAccount = 'fromAccount';
var myAccount = 'myAccount';

var config = JSON.parse(fs.readFileSync("/var/nodejs/config_" + fromAccount + ".json"));
const activeKey = config.active_key;
const loopSeconds = 30;

var requestLoop = setInterval(function(){
	rp({
		url : heUrl,
		method : 'POST',
		body: {"jsonrpc": "2.0","method": "find","params": {"contract": "witnesses","table": "witnesses","query": {}},"id": 1},
		json : true
	}).then(function (response){
		var enabled = false;
		var results = response.result;
		var dateNow = new Date(Date.now());
		dateNow = dateNow.toString().split('+')[0];

		for(var results_i = 0; results_i < results.length; results_i++) {
			var result = results[results_i];
			if(result.account == myAccount){
				enabled = result.enabled;
			}
		}
		if(enabled == false){
			console.log('witness is not enabled');
			transfer(activeKey, fromAccount, myAccount, '0.007 HIVE', 'witness is not enabled');
		} else {
			console.log('witness enabled: ' + dateNow);
		}
	});
}, loopSeconds * 1000);

async function transfer(activeKey, from, to, amount, memo) {
	hive.broadcast.transfer(activeKey, from, to, amount, memo, function (err, response) {
		if (err) {
			console.log('Error sending transfer to @' + to + ' for: ' + amount + ', Error: ' + err);
			process.exit();
		} else {
			var trxId = response.id;
			console.log('Transfer to @' + to + ': ' +  amount + '\n' + ' at trx: ' + trxId);
		}
	});
}
```
👍  , , , , , , , , , , , , , , , ,
properties (23)
authorblervin
permlinkhive-engine-witness-monitoring-script
categoryhiveengine
json_metadata"{"app":"peakd/2021.03.5","format":"markdown","description":"Hive Engine Witness Monitoring Script","tags":["hiveengine","witness","hivedev","blockchain","dev","witness-category","tools","hive-engine"],"users":["ginabot","hiveio"],"links":["/@ginabot","/steem/@ginabot/refresher-how-to-sign-up-for-ginabot","/@ginabot","/@ginabot","https://github.com/blervin/hiveenginewitness"],"image":["https://files.peakd.com/file/peakd-hive/blervin/23w2HG91SYr1Lw1MtFSkw4qVLrc3rg28ZDDWD9Fq798vf3wWxSWa9wbReMUY7xGeXCvur.jpg","https://files.peakd.com/file/peakd-hive/blervin/23tbH351NVLbcXCvbCPFu9gGpYPRKdogLjidd38DACvoe65B28JcSxMNZwL8MrpRFmJgk.png"]}"
created2021-03-06 12:19:03
last_update2021-03-06 12:19:03
depth0
children7
last_payout2021-03-13 12:19:03
cashout_time1969-12-31 23:59:59
total_payout_value0.826 HBD
curator_payout_value0.817 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,025
author_reputation3,482,125,919,554
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,210,872
net_rshares3,944,331,668,332
author_curate_reward""
vote details (17)
@blervin ·
First update. Please consider using the [FRIDAY](https://peakd.com/hive-169321/@deathwing/launch-of-friday-brand-new-discord-notification-bot-for-hive-and-hive-engine) Discord notification bot instead!

Just [jump into their Discord](https://discord.gg/4v9JcRZx3r), go to the #commands channel, and type `.register`

And thanks to @deathwing and @rishi556 for building this new notification bot!!!

Second update. The bot will keep sending you transfers forever, lol. I'm working on an update to stop the madness, but I'm guessing anyone using this already threw up a few extra lines of code. Coming shortly...
properties (22)
authorblervin
permlinkre-blervin-qppkfa
categoryhiveengine
json_metadata{"tags":["hiveengine"],"app":"peakd/2021.03.6"}
created2021-03-09 15:30:48
last_update2021-03-09 15:30:48
depth1
children0
last_payout2021-03-16 15:30:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length610
author_reputation3,482,125,919,554
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,270,948
net_rshares0
@forykw ·
Nice.... will keep for future ideas on my witness monitoring script posted at @atexoras.

Cheers
properties (22)
authorforykw
permlinkre-blervin-202137t95931309z
categoryhiveengine
json_metadata{"tags":["hiveengine","witness","hivedev","blockchain","dev","witness-category","tools","hive-engine"],"app":"ecency/3.0.14-vision","format":"markdown+html"}
created2021-03-06 20:59:33
last_update2021-03-06 20:59:33
depth1
children2
last_payout2021-03-13 20:59:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length96
author_reputation71,305,228,064,328
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,218,112
net_rshares0
@blervin ·
Awesome, I hope it's helpful!
properties (22)
authorblervin
permlinkre-forykw-qpksjn
categoryhiveengine
json_metadata{"tags":["hiveengine"],"app":"peakd/2021.03.5"}
created2021-03-07 01:38:15
last_update2021-03-07 01:38:15
depth2
children1
last_payout2021-03-14 01:38:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length29
author_reputation3,482,125,919,554
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,221,324
net_rshares0
@forykw ·
Yes it will, I am planning on integrating some JS with my script since you need node anyway to run a witness node.
properties (22)
authorforykw
permlinkre-blervin-202137t145635346z
categoryhiveengine
json_metadata{"tags":["ecency"],"app":"ecency/3.0.14-mobile","format":"markdown+html"}
created2021-03-07 01:56:36
last_update2021-03-07 01:56:36
depth3
children0
last_payout2021-03-14 01:56:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length114
author_reputation71,305,228,064,328
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,221,452
net_rshares0
@hivebuzz ·
Congratulations @blervin! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@blervin/upvotes.png?202103070414"></td><td>You distributed more than 49000 upvotes.<br>Your next target is to reach 50000 upvotes.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@blervin) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/hivebuzz/@hivebuzz/pud-202103-feedback"><img src="https://images.hive.blog/64x128/https://i.imgur.com/zHjYI1k.jpg"></a></td><td><a href="/hivebuzz/@hivebuzz/pud-202103-feedback">Feedback from the March 1st Hive Power Up Day</a></td></tr></table>
properties (22)
authorhivebuzz
permlinkhivebuzz-notify-blervin-20210307t042347000z
categoryhiveengine
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2021-03-07 04:23:45
last_update2021-03-07 04:23:45
depth1
children0
last_payout2021-03-14 04:23:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length947
author_reputation367,822,555,846,574
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,222,773
net_rshares0
@ismellbacon ·
Nice!!! Thanks for all you do : )
properties (22)
authorismellbacon
permlinkre-blervin-202136t182956656z
categoryhiveengine
json_metadata{"tags":["hiveengine","witness","hivedev","blockchain","dev","witness-category","tools","hive-engine"],"app":"ecency/3.0.14-vision","format":"markdown+html"}
created2021-03-06 23:29:57
last_update2021-03-06 23:29:57
depth1
children1
last_payout2021-03-13 23:29:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation104,426,945,158
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,220,066
net_rshares0
@blervin ·
Thanks, I appreciate the support!
properties (22)
authorblervin
permlinkre-ismellbacon-qpksk1
categoryhiveengine
json_metadata{"tags":["hiveengine"],"app":"peakd/2021.03.5"}
created2021-03-07 01:38:27
last_update2021-03-07 01:38:27
depth2
children0
last_payout2021-03-14 01:38:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation3,482,125,919,554
root_title"Hive Engine Witness Monitoring Script"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,221,327
net_rshares0