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