Use new debug logger for DNS Aggregator
This commit is contained in:
parent
9b3ef6d610
commit
24fda8a73f
|
@ -357,7 +357,7 @@ class AXFRDaemonInstance(object):
|
|||
records_raw = [z[n].to_text(n) for n in z.nodes.keys()]
|
||||
except Exception as e:
|
||||
if self.config['debug']:
|
||||
print('{} {} ({})'.format(e, dnsmasq_ip, domain))
|
||||
self.logger.out('{} {} ({})'.format(e, dnsmasq_ip, domain), state='d', prefix='dns-aggregator')
|
||||
continue
|
||||
|
||||
# Fix the formatting because it's useless
|
||||
|
@ -392,7 +392,7 @@ class AXFRDaemonInstance(object):
|
|||
)
|
||||
results = list(sql_curs.fetchall())
|
||||
if self.config['debug']:
|
||||
print('SQL query results: {}'.format(results))
|
||||
self.logger.out('SQL query results: {}'.format(results), state='d', prefix='dns-aggregator')
|
||||
except Exception as e:
|
||||
self.logger.out('ERROR: Failed to obtain DNS records from database: {}'.format(e))
|
||||
|
||||
|
@ -402,7 +402,7 @@ class AXFRDaemonInstance(object):
|
|||
records_old_ids = list()
|
||||
if not results:
|
||||
if self.config['debug']:
|
||||
print('No results found, skipping.')
|
||||
self.logger.out('No results found, skipping.', state='d', prefix='dns-aggregator')
|
||||
continue
|
||||
for record in results:
|
||||
# Skip the non-A
|
||||
|
@ -414,12 +414,12 @@ class AXFRDaemonInstance(object):
|
|||
# Assemble a list element in the same format as the AXFR data
|
||||
entry = '{} {} IN {} {}'.format(r_name, r_ttl, r_type, r_data)
|
||||
if self.config['debug']:
|
||||
print('Found record: {}'.format(entry))
|
||||
self.logger.out('Found record: {}'.format(entry), state='d', prefix='dns-aggregator')
|
||||
|
||||
# Skip non-A or AAAA records
|
||||
if r_type != 'A' and r_type != 'AAAA':
|
||||
if self.config['debug']:
|
||||
print('Skipping record {}, not A or AAAA: "{}"'.format(entry, r_type))
|
||||
self.logger.out('Skipping record {}, not A or AAAA: "{}"'.format(entry, r_type), state='d', prefix='dns-aggregator')
|
||||
continue
|
||||
|
||||
records_old.append(entry)
|
||||
|
@ -429,8 +429,8 @@ class AXFRDaemonInstance(object):
|
|||
records_old.sort()
|
||||
|
||||
if self.config['debug']:
|
||||
print('New: {}'.format(records_new))
|
||||
print('Old: {}'.format(records_old))
|
||||
self.logger.out('New: {}'.format(records_new), state='d', prefix='dns-aggregator')
|
||||
self.logger.out('Old: {}'.format(records_old), state='d', prefix='dns-aggregator')
|
||||
|
||||
# Find the differences between the lists
|
||||
# Basic check one: are they completely equal
|
||||
|
@ -442,8 +442,8 @@ class AXFRDaemonInstance(object):
|
|||
in_old_not_in_new = in_old - in_new
|
||||
|
||||
if self.config['debug']:
|
||||
print('New but not old: {}'.format(in_new_not_in_old))
|
||||
print('Old but not new: {}'.format(in_old_not_in_new))
|
||||
self.logger.out('New but not old: {}'.format(in_new_not_in_old), state='d', prefix='dns-aggregator')
|
||||
self.logger.out('Old but not new: {}'.format(in_old_not_in_new), state='d', prefix='dns-aggregator')
|
||||
|
||||
# Go through the old list
|
||||
remove_records = list() # list of database IDs
|
||||
|
@ -468,7 +468,7 @@ class AXFRDaemonInstance(object):
|
|||
# Remove the invalid old records
|
||||
for record_id in remove_records:
|
||||
if self.config['debug']:
|
||||
print('Removing record: {}'.format(record_id))
|
||||
self.logger.out('Removing record: {}'.format(record_id), state='d', prefix='dns-aggregator')
|
||||
sql_curs.execute(
|
||||
"DELETE FROM records WHERE id=%s",
|
||||
(record_id,)
|
||||
|
@ -485,7 +485,7 @@ class AXFRDaemonInstance(object):
|
|||
r_type = record[3]
|
||||
r_data = record[4]
|
||||
if self.config['debug']:
|
||||
print('Add record: {}'.format(name))
|
||||
self.logger.out('Add record: {}'.format(name), state='d', prefix='dns-aggregator')
|
||||
try:
|
||||
sql_curs.execute(
|
||||
"INSERT INTO records (domain_id, name, ttl, type, prio, content) VALUES (%s, %s, %s, %s, %s, %s)",
|
||||
|
@ -494,7 +494,7 @@ class AXFRDaemonInstance(object):
|
|||
changed = True
|
||||
except psycopg2.IntegrityError as e:
|
||||
if self.config['debug']:
|
||||
print('Failed to add record due to {}: {}'.format(e, name))
|
||||
self.logger.out('Failed to add record due to {}: {}'.format(e, name), state='d', prefix='dns-aggregator')
|
||||
|
||||
if changed:
|
||||
# Increase SOA serial
|
||||
|
@ -507,7 +507,7 @@ class AXFRDaemonInstance(object):
|
|||
new_serial = current_serial + 1
|
||||
soa_record[2] = str(new_serial)
|
||||
if self.config['debug']:
|
||||
print('Records changed; bumping SOA: {}'.format(new_serial))
|
||||
self.logger.out('Records changed; bumping SOA: {}'.format(new_serial), state='d', prefix='dns-aggregator')
|
||||
sql_curs.execute(
|
||||
"UPDATE records SET content=%s WHERE domain_id=%s AND type='SOA'",
|
||||
(' '.join(soa_record), domain_id)
|
||||
|
@ -515,7 +515,7 @@ class AXFRDaemonInstance(object):
|
|||
|
||||
# Commit all the previous changes
|
||||
if self.config['debug']:
|
||||
print('Committing database changes and reloading PDNS')
|
||||
self.logger.out('Committing database changes and reloading PDNS', state='d', prefix='dns-aggregator')
|
||||
try:
|
||||
self.sql_conn.commit()
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue