mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-01-22 04:24:15 +00:00
py-i2phosts-checker: implement multiple lookup tries
Many hosts are not resolved with first lookup b32->b64, but if we query 2nd time, host can be resolved. Because of this, some registered hosts may be never seen while they actually up!
This commit is contained in:
parent
b18b3af1bf
commit
ca831b2d45
@ -24,6 +24,7 @@ args = parser.parse_args()
|
||||
spec = '''
|
||||
log_file = string(default='/var/log/py-i2phosts/master.log')
|
||||
log_level = option('debug', 'info', 'warning', 'error', 'critical', default='info')
|
||||
lookup_retries = integer(1, 20, default=2)
|
||||
'''
|
||||
spec = spec.split('\n')
|
||||
config = configobj.ConfigObj(args.config_file, configspec=spec)
|
||||
@ -91,17 +92,18 @@ for host in all_hosts:
|
||||
b32dest = get_b32(dest)
|
||||
# do name lookup query with b32 address
|
||||
# it success only if host is alive
|
||||
s.send('lookup %s\n' % b32dest)
|
||||
data = f.readline().rstrip('\n')
|
||||
if data == 'ERROR Address Not found.':
|
||||
log.debug('%s: unable to resolve', host.name)
|
||||
continue
|
||||
elif data == 'OK ' + host.b64hash:
|
||||
log.info('alive host: %s', host.name)
|
||||
# update lastseen timestamp
|
||||
host.last_seen = datetime.datetime.utcnow()
|
||||
host.save()
|
||||
else:
|
||||
log.warning('unexpected reply: %s', data)
|
||||
for i in range(config['lookup_retries']):
|
||||
s.send('lookup %s\n' % b32dest)
|
||||
data = f.readline().rstrip('\n')
|
||||
if data == 'ERROR Address Not found.':
|
||||
log.debug('%s: unable to resolve, try: %s', host.name, i)
|
||||
elif data == 'OK ' + host.b64hash:
|
||||
log.info('alive host: %s', host.name)
|
||||
# update lastseen timestamp
|
||||
host.last_seen = datetime.datetime.utcnow()
|
||||
host.save()
|
||||
break
|
||||
else:
|
||||
log.warning('unexpected reply: %s', data)
|
||||
s.close()
|
||||
log.info('check finished')
|
||||
|
@ -4,3 +4,5 @@ log_level = info # debug, info, warning, error, critical
|
||||
log_file = /var/log/py-i2phosts/checker.log
|
||||
|
||||
bob_addr = 127.0.0.1:2827
|
||||
|
||||
lookup_retries = 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user