diff options
author | Christian Poessinger <christian@poessinger.com> | 2018-07-29 21:36:16 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2018-07-29 21:36:16 +0200 |
commit | 5dd7958c616f186f878bf759ee61cbd6e2eabb06 (patch) | |
tree | 429554a3aba2a7a7641b09e3cfc3dee76da87b7f /src | |
parent | c9eb5229e2bc1e4a74b4256c26932723b7c26986 (diff) | |
download | vyos-1x-5dd7958c616f186f878bf759ee61cbd6e2eabb06.tar.gz vyos-1x-5dd7958c616f186f878bf759ee61cbd6e2eabb06.zip |
T758: add 'show dns dynamic status' op mode command
Diffstat (limited to 'src')
-rwxr-xr-x | src/op_mode/dynamic_dns_status.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/op_mode/dynamic_dns_status.py b/src/op_mode/dynamic_dns_status.py new file mode 100755 index 000000000..bbff01f49 --- /dev/null +++ b/src/op_mode/dynamic_dns_status.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +import jinja2 +import sys +import time + +from vyos.config import Config + +cache_file = r'/var/cache/ddclient/ddclient.cache' + +OUT_TMPL_SRC = """ +{%- for entry in hosts -%} +ip address : {{ entry.ip }} +host-name : {{ entry.host }} +last update : {{ entry.time }} +update-status: {{ entry.status }} + +{% endfor -%} +""" + +if __name__ == '__main__': + # Do nothing if service is not configured + c = Config() + if not c.exists_effective('service dns dynamic'): + print("Dynamic DNS not configured") + sys.exit(0) + + data = { + 'hosts': [] + } + + with open(cache_file, 'r') as f: + for line in f: + if line.startswith('#'): + continue + + outp = { + 'host': '', + 'ip': '', + 'time': '' + } + + if 'host=' in line: + host = line.split('host=')[1] + if host: + outp['host'] = host.split(',')[0] + + if 'ip=' in line: + ip = line.split('ip=')[1] + if ip: + outp['ip'] = ip.split(',')[0] + + if 'atime=' in line: + atime = line.split('atime=')[1] + if atime: + tmp = atime.split(',')[0] + outp['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(int(tmp, base=10))) + + if 'status=' in line: + status = line.split('status=')[1] + if status: + outp['status'] = status.split(',')[0] + + data['hosts'].append(outp) + + tmpl = jinja2.Template(OUT_TMPL_SRC) + print(tmpl.render(data)) |