bundles/pppd: refactor check_dyndns_update
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit

We don't care about what the DNS provider said when updating the ip
address. The only thing we care about is wether the current external ip
of the system matches the resolved ip address.
This commit is contained in:
Franzi 2021-08-14 07:55:01 +02:00
parent 1d8733d0c2
commit bd10dc578f
Signed by: kunsi
GPG key ID: 12E3D2136B818350
5 changed files with 30 additions and 35 deletions

View file

@ -1,28 +1,20 @@
#!/bin/bash
statusfile="/var/tmp/dyndns.monitoring"
if ! [[ -f "$statusfile" ]]
then
echo "Status file not found"
exit 3
fi
[[ -n "$DEBUG" ]] && set -x
mtime=$(stat -c %Y $statusfile)
now=$(date +%s)
if (( $now - $mtime > 60*60*24*8 ))
then
echo "Status file is older than 8 days!"
exit 3
fi
interface="$(ip link show | awk '/ ppp/ {print substr($2, 1, length($2)-1)}')"
addr="$(ip addr show dev "$interface" | awk '/inet / {print $2}')"
resolved="$(dig +short "${domain}" A)"
statuscode=$(cat $statusfile)
case "$statuscode" in
200)
echo "OK"
exit 0
;;
*)
echo "Last statuscode was $statuscode"
exit 2
;;
esac
if [[ -z "$addr" ]] || [[ -z "$resolved" ]]
then
echo "Address on '$interface' is '$addr' - resolved '$resolved'"
exit 3
elif [[ "$addr" == "$resolved" ]]
then
echo "Resolved IP for ${domain} matches current ip on $interface"
exit 0
else
echo "Resolved $resolved for ${domain}, but got $addr on $interface!"
exit 2
fi

View file

@ -20,5 +20,4 @@ r = requests.get(
)
)
with open('/var/tmp/dyndns.monitoring', 'w') as s:
s.write(str(r.status_code))
print('got status {} when updating dns'.format(r.status_code))

View file

@ -38,7 +38,7 @@ files = {
'/etc/ppp/chap-secrets': {
'source': 'secrets',
'content_type': 'mako',
'context': node.metadata['pppd'],
'context': node.metadata.get('pppd'),
'mode': '0400',
'triggers': {
'svc_systemd:pppoe:restart',
@ -47,7 +47,7 @@ files = {
'/etc/ppp/pap-secrets': {
'source': 'secrets',
'content_type': 'mako',
'context': node.metadata['pppd'],
'context': node.metadata.get('pppd'),
'mode': '0400',
'triggers': {
'svc_systemd:pppoe:restart',
@ -63,7 +63,7 @@ files = {
},
'/etc/ppp/peers/provider': {
'content_type': 'mako',
'context': node.metadata['pppd'],
'context': node.metadata.get('pppd'),
'triggers': {
'svc_systemd:pppoe:restart',
},
@ -87,15 +87,17 @@ files = {
'/usr/local/bin/restart-pppoe-if-no-public-ip': {
'mode': '0755',
},
'/usr/local/share/icinga/plugins/check_dyndns_update': {
'mode': '0755',
},
}
if 'dyndns' in node.metadata['pppd']:
if node.metadata.get('pppd/dyndns', {}):
files['/etc/ppp/ip-up.d/dyndns'] = {
'content_type': 'mako',
'context': node.metadata['pppd']['dyndns'],
'context': node.metadata.get('pppd/dyndns'),
'mode': '0755',
}
files['/usr/local/share/icinga/plugins/check_dyndns_update'] = {
'content_type': 'mako',
'context': node.metadata.get('pppd/dyndns'),
'mode': '0755',
}

View file

@ -30,7 +30,7 @@ defaults = {
'icinga2_api/pppd/services',
)
def icinga_dyndns(metadata):
if 'dyndns' not in metadata.get('pppd'):
if not metadata.get('pppd/dyndns', {}):
return {}
return {
@ -39,6 +39,7 @@ def icinga_dyndns(metadata):
'services': {
'DYNDNS UPDATE': {
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_dyndns_update',
'vars.notification.mail': True,
},
},
},

View file

@ -148,6 +148,7 @@ nodes['home.router'] = {
'password': vault.decrypt('encrypt$gAAAAABfruaXEDkaFksFMU8g97ydWyJF8p2KcSDJJBlzaOLDsLL6oCDYjG1kMPVESOzqjn8ThtSht1uZDuMCstA-sATmLS-EWQ=='),
'interface': 'enp1s0.100',
'dyndns': {
'domain': 'franzi-home.kunbox.net',
'url': 'https://ns-1.kunbox.net/nic/update?hostname=franzi-home.kunbox.net&myip={ip}',
'username': vault.decrypt('encrypt$gAAAAABfr8DLAJhmUIhdxLq83I8MnRRvkRgDZcO8Brvw1KpvplC3K8ZGj0jIIWD3Us33vIP6t0ybd_mgD8slpRUk78Kqd3BMoQ=='),
'password': vault.decrypt('encrypt$gAAAAABfr8Cq5M1hweeJTQAl0dLhFntdlw-QnkIYUQpY-_ycODVWOpyeAwjwOgWLSdsdXIUvqcoiXPZPV-BE12p5C42NGnj9r7sKYpoGz8xfuGIk6haMa2g='),