Saturday evening hack
Somebody was asking if dashman could check the status of all the masternodes in
masternode.conf, so I built a quick python script for checking if your
masternodes are listed in the output of 'masternode list full'
Just change the top two lines to match your dash-cli and masternode.conf
locations. NOTE: You can run this from any wallet (no funds required), just
copy your masternode.conf over to the host.
Enjoy!
https://gist.github.com/moocowmoo/4da0a42f72c1760f05f5#!/usr/bin/python
""" simple 'masternode list full' health check """
my_dash_cli = "/home/ubuntu/.dash/dash-cli"
my_mn_conf = "/home/ubuntu/.dash/masternode.conf"
from subprocess import check_output
def run_command(cmd):
return check_output(cmd, shell=True)
def skip_comments_and_blank(file):
for line in file:
line = line.rstrip("\n")
if line.startswith("#") or not line:
continue
yield line
def get_masternodes_from_conf():
nodes = {}
with open(my_mn_conf, "r") as f:
for line in skip_comments_and_blank(f):
(alias, ip, privkey, vin, n) = line.rstrip("\n").split()
nodes[vin + '-' + n] = {
'alias': alias,
'ip': ip,
'privkey': privkey,
'vin': vin,
'n': n
}
return nodes
def get_masternodes_from_dashd():
nodes = {}
cmd = " ".join([my_dash_cli, 'masternode list full'])
node_list = run_command(cmd)
for line in node_list.split("\n"):
line = line.translate(None, ''.join('"{}'))
if not line:
continue
(ftx, nop, status, protocol, address, ip,
last_seen, active, last_paid) = line.split()
(vin, n) = ftx.split('-')
nodes[ftx] = {
'vin': vin,
'n': n,
'status': status,
'protocol': protocol,
'address': address,
'ip': ip,
'last_seen': last_seen,
'active': active,
'last_paid': last_paid
}
return nodes
def main():
my_masternodes = get_masternodes_from_conf()
masternode_list = get_masternodes_from_dashd()
for my_node in sorted(my_masternodes,
key=lambda k: my_masternodes[k]['alias']):
if my_node in masternode_list:
if masternode_list[my_node]['status'] == 'ENABLED':
print (my_masternodes[my_node]['alias'] +
" ONLINE - in masternode list")
else:
print (my_masternodes[my_node]['alias'] +
" OFFLINE -- NOT ENABLED")
else:
print (my_masternodes[my_node]['alias'] +
" OFFLINE -- NOT IN MASTERNODE LIST")
if __name__ == "__main__":
main()
thanks moocowmoo
I will change to your python file to monitor masternode.
I used shell file using txid.
echo mn01
~/.dash/dash-cli masternodelist rank 004c9
echo mn02
~/.dash/dash-cli masternodelist rank 00acc
I want to have monitoring "dashd" every 5 minute.
And if dashd killed, run dashd automatically.
save following code "actmn"
#!/bin/sh
#=======================================================#
# while
#=======================================================#
while true
do
ps_exist_cnt=`ps -ea | grep "dashd" | grep -v grep | wc -l`
if [ $ps_exist_cnt -eq 0 ];then
/home/ubuntu/.dash/dashd &
fi
sleep 300
done
-----------------------
backgroud run
chmod +x actmn
nohup ./actmn &
Is this proper solution?