Closed bitcollector1 closed 1 year ago
Did it work on NetBox v3.5.3 for you?
Could you try making the following changes to /ebay/home/ebay/netbox/venv/lib/python3.8/site-packages/netbox_kea/utilities.py
:
-from collections.abc import Callable
from datetime import datetime
-from typing import Any, Dict, List, Literal, Optional
+from typing import Any, Callable, Dict, List, Literal, Optional
from django.http import HttpResponse
from django.shortcuts import redirect
Your suggestion worked perfectly and so is the plugin! Nice work and thanks for sharing!
one other thing, I think your command is not correct and should be
./manage.py migrate
instead of
./migrate.py migrate
would it also be possible to report on pool info and utilization for a given subnet?
server.dhcp4.statistic_get('subnet[1019156019].total-addresses')
KeaResponse(result=0, text=None, arguments={'subnet[1019156019].total-addresses': [[29, '2023-06-07 12:24:17.224493']]})
server.dhcp4.statistic_get('subnet[1019156019].assigned-addresses')
KeaResponse(result=0, text=None, arguments={'subnet[1019156019].assigned-addresses': [[12, '2023-06-07 12:47:29.204784'], [11, '2023-06-07 12:35:42.945926'], [10, '2023-06-07 12:34:32.895585'], [9, '2023-06-07 12:34:31.810025'], [8, '2023-06-07 12:34:30.858006'], [7, '2023-06-07 12:34:30.410463'], [6, '2023-06-07 12:34:08.498306'], [5, '2023-06-07 12:34:08.120871'], [4, '2023-06-07 12:34:03.850084'], [3, '2023-06-07 12:32:41.549737'], [2, '2023-06-07 12:32:39.650907'], [1, '2023-06-07 12:32:15.823833'], [0, '2023-06-07 12:24:17.224847']]})
pool info seems to be available with this call
test = server.dhcp4.cached_config
print(test['Dhcp4']['shared-networks'][0]['subnet4'][0]['pools'][0]['pool'])
10.254.198.129-10.254.198.177
Your suggestion worked perfectly and so is the plugin! Nice work and thanks for sharing!
Great! I've published v0.1.1 with the change so you can update to that.
one other thing, I think your command is not correct and should be
Fixed.
would it also be possible to report on pool info and utilization for a given subnet?
I think this is a good use case for Stork. I'm hesitant to implement this feature because Kea doesn't have a proper API to get pool/subnet information. Currently this plugin just uses config-get
to get the list of subnets which may be expensive, (I haven't actually confirmed this myself). None the less, getting the configuration just to get the list of configured subnets/pools doesn't seem like a very good approach.
it appears that our company paid for the premium API support so we can make the direct API calls to pull subnet info
network = server.dhcp4.network4_get('sjc-lab-33-ztp-data')
print(network.name)
print(network.subnet4[0].subnet)
print(network.subnet4[0].pools[0].pool)
sjc-lab-33-ztp-data
10.254.142.128/26
10.254.142.160-10.254.142.190
FYI, I'm using this new wrapper https://github.com/BSpendlove/pykeadhcp/blob/main/COMMANDS.md
One last question, I'm not seeing anything for DHCP Subnets.....curious if I'm missing something basic as I'm new to KEA.
The DHCP Leases is working great.
Here you can see the DHCP info is available via the python calls.
subnets_v4 = server.dhcp4.subnet4_list()
for i in subnets_v4:
print(str(i.id).ljust(12), i.subnet )
416769625 10.254.85.128/25
440383492 10.254.141.0/26
593730608 10.254.151.48/28
602504513 10.254.86.0/25
605481152 10.254.151.32/28
830827846 10.254.142.192/26
1019156019 10.254.142.96/27
1818034871 10.254.148.128/25
1986588591 10.254.199.0/27
2086002595 10.254.142.128/26
2149123380 10.254.150.128/26
2192260479 10.254.141.64/26
2419609915 10.254.199.64/26
2444456677 10.254.142.64/27
2494219477 10.254.84.0/25
2541440121 10.254.148.0/25
2554840638 10.254.84.128/25
2910585232 10.254.143.0/26
2940872388 10.254.198.128/26
3013529256 10.254.150.0/26
3035992152 10.254.141.192/26
3179841559 10.254.142.32/27
3185248078 10.254.199.32/27
3436875955 10.254.149.0/25
3452549073 10.254.150.192/26
3473610783 10.254.85.0/25
3591900418 10.254.151.16/28
3784171495 10.254.151.160/27
3794378056 10.254.151.0/28
3801781281 10.254.198.192/26
3972899536 10.254.149.128/25
4030412670 10.254.150.64/26
4144329181 10.254.142.0/27
4179960509 10.254.141.128/26
Stork looks pretty cool but might be overkill for my needs, I already have so many tools setup :)
it appears that our company paid for the premium API support so we can make the direct API calls to pull subnet info.
I don't have access to that hook library so this plugin just pulls the list of subnets from the config.
One last question, I'm not seeing anything for DHCP Subnets.....curious if I'm missing something basic as I'm new to KEA.
Are you using a database to store your subnets? If so, this plugin grabs the lists of subnets from config-get
so the subnets might not be in the configuration. I've only tested this plugin with subnets configured in the JSON config file.
If you run config-get
do you see the subnets?
Here you can see the DHCP info is available via the python calls.
It looks like this command uses the subnet4-list
command (which is from the hook library).
Stork looks pretty cool but might be overkill for my needs, I already have so many tools setup :)
Yeah it does have quite a bit of functionality, mainly around monitoring.
KEA was setup using the databases for config, host and lease information AFAIK, I'm still learning this on the fly and did not set it all up myself, but we don't seem to have a configuration file we can edit like we did with the old DHCP server.
That said, The subnets do show in the configuration, but they were configured in "shared-networks".
'shared-networks': [{'name': 'sjc-ctlab-03-r208-mgmt1',
'option-data': [],
'relay': {'ip-addresses': []},
'subnet4': [{'4o6-interface': '',
'4o6-interface-id': '',
'4o6-subnet': '',
'id': 2940872388,
'next-server': '10.254.141.17',
'option-data': [{'always-send': True,
'code': 28,
'csv-format': True,
'data': '10.254.198.191',
'name': 'broadcast-address',
'never-send': False,
'space': 'dhcp4'},
{'always-send': True,
'code': 1,
'csv-format': True,
'data': '255.255.255.192',
'name': 'subnet-mask',
'never-send': False,
'space': 'dhcp4'},
{'always-send': True,
'code': 3,
'csv-format': True,
'data': '10.254.198.129',
'name': 'routers',
'never-send': False,
'space': 'dhcp4'},
{'always-send': True,
'code': 15,
'csv-format': True,
'data': 'hwe.ebay.com',
'name': 'domain-name',
'never-send': False,
'space': 'dhcp4'},
{'always-send': True,
'code': 119,
'csv-format': True,
'data': 'hwe.ebay.com.,vip.ebay.com.,ebay.com.',
'name': 'domain-search',
'never-send': False,
'space': 'dhcp4'}],
'pools': [{'option-data': [], 'pool': '10.254.198.129-10.254.198.177'}],
'relay': {'ip-addresses': []},
'reservations': [],
'subnet': '10.254.198.128/26'}]},
I might have to setup stork, because who does not love more monitoring and cool grafana dashboards :)
Thanks for the tips and for developing this plugin, it's much appreciated.
I wonder how hard it would be to hack at your plugin to make the subnets and ID's show up for me since I have access to the premium hooks. It looks like it's a super simpler API call to grab this data and print it in NetBox.
This might be a nice way to ease into the plugin universe :)
The subnets do show in the configuration, but they were configured in "shared-networks".
I'll see if I can add support for that.
I wonder how hard it would be to hack at your plugin to make the subnets and ID's show up for me since I have access to the premium hooks.
I think you just need to modify one method.
Thanks again for creating this plugin, it's working really well and much appreciated!
Support for NetBox 3.5.4? I was getting an error when upgrading NetBox today to 3.5.4
It failed 2x, until I removed this from PLUGINS in the configuration.py for NetBox.