First working versions.

This commit is contained in:
2021-05-15 17:35:16 +01:00
commit 85efd4312c
2 changed files with 45 additions and 0 deletions

36
netbox-dhcp.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/sh
. ./config.sh
do_curl() {
curl -s -k -H "Authorization: Token ${TOKEN}" -X GET $1
}
cat<<EOF
# generated by $0 at $(date)
option domain-name "home.paler.net";
max-lease-time 600;
default-lease-time 600;
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option domain-name-servers 192.168.1.1;
range 192.168.1.100 192.168.1.200;
EOF
do_curl "https://${NETBOX}/api/ipam/ip-addresses/" | \
jq -r '.results[] | .assigned_object.device.name + .assigned_object.virtual_machine.name + " " + (.address / "/")[0] + " " + .assigned_object.url' |
while read name ip owner
do
mac=$(do_curl $owner | jq -r '.mac_address')
cat<<EOF
host $name {
fixed-address ${ip};
hardware ethernet ${mac};
}
EOF
done
echo "}"

9
netbox-dns.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
. ./config.sh
RPZ_FILE=/var/unbound/db/local.rpz
curl -s -k -H "Authorization: Token ${TOKEN}" -X GET "https://${NETBOX}/api/ipam/ip-addresses/" | \
jq -r '.results[] | (.address / "/")[0] as $addr | (.assigned_object.device.name + .assigned_object.virtual_machine.name + ".home.paler.net") as $name | ($addr | split(".") | reverse | join(".") + ".in-addr.arpa") as $rev | $name + " A " + $addr, $rev + " PTR " + $name + "."' | \
tee ${RPZ_FILE}