@ -24,6 +24,7 @@ args = parser.parse_args()
spec = '''
spec = '''
log_file = string(default='/var/log/py-i2phosts/master.log')
log_file = string(default='/var/log/py-i2phosts/master.log')
log_level = option('debug', 'info', 'warning', 'error', 'critical', default='info')
log_level = option('debug', 'info', 'warning', 'error', 'critical', default='info')
lookup_retries = integer(1, 20, default=2)
'''
'''
spec = spec.split('\n')
spec = spec.split('\n')
config = configobj.ConfigObj(args.config_file, configspec=spec)
config = configobj.ConfigObj(args.config_file, configspec=spec)
@ -91,17 +92,18 @@ for host in all_hosts:
b32dest = get_b32(dest)
b32dest = get_b32(dest)
# do name lookup query with b32 address
# do name lookup query with b32 address
# it success only if host is alive
# it success only if host is alive
s.send('lookup %s\n' % b32dest)
for i in range(config['lookup_retries']):
data = f.readline().rstrip('\n')
s.send('lookup %s\n' % b32dest)
if data == 'ERROR Address Not found.':
data = f.readline().rstrip('\n')
log.debug('%s: unable to resolve', host.name)
if data == 'ERROR Address Not found.':
continue
log.debug('%s: unable to resolve, try: %s', host.name, i)
elif data == 'OK ' + host.b64hash:
elif data == 'OK ' + host.b64hash:
log.info('alive host: %s', host.name)
log.info('alive host: %s', host.name)
# update lastseen timestamp
# update lastseen timestamp
host.last_seen = datetime.datetime.utcnow()
host.last_seen = datetime.datetime.utcnow()
host.save()
host.save()
else:
break
log.warning('unexpected reply: %s', data)
else:
log.warning('unexpected reply: %s', data)
s.close()
s.close()
log.info('check finished')
log.info('check finished')