minitriga / axians-netbox-plugin-pdu Goto Github PK
View Code? Open in Web Editor NEWNetbox Plugin to Get PDU Information
License: Other
Netbox Plugin to Get PDU Information
License: Other
On selecting Add:
`<class 'AttributeError'>
'NoneType' object has no attribute 'model'
Python version: 3.8.6
NetBox version: 2.9.10`
On selecting Import:
`<class 'AttributeError'>
'PDUConfig' object has no attribute '_cf'
Python version: 3.8.6
NetBox version: 2.9.10`
Versions:
Netbox 2.9.10
netbox_pdu 0.0.3
Plugin is not supported on netbox version 3.3.5
I can't seem to get this plugin to begin querying my SNMP devices.
I've installed the plugin and setup the worker - I double checked by manually executing python manage.py pduscheduler
.
I also added a PDUConfig via the web interface to an APC PDU device type I have a few instances of, I double checked the OID via snmpwalk as well, that is valid too. It's read community is also 'public', just like the default for the plugin. These instances also all have primary IPs assigned to their network interfaces.
I can see my PDU configs via the api endpoint btw, but i have a count of 0 when read via /api/plugins/pdu/pdu-status/
.
Am I missing anything else? The netbox-pdu
systemd service only outputs 'Registering birth', so it seems to have started fine.
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 575, in update_or_create
obj = self.select_for_update().get(**kwargs)
File "/opt/netbox/venv/lib64/python3.6/site-packages/cacheops/query.py", line 390, in get
return qs._no_monkey.get(qs, *args, **kwargs)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 417, in get
self.model._meta.object_name
axians_netbox_pdu.models.PDUStatus.DoesNotExist: PDUStatus matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/fields/__init__.py", line 1772, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'NOSUCHINSTANCE'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/netbox/venv/lib64/python3.6/site-packages/rq/worker.py", line 883, in perform_job
rv = job.perform()
File "/opt/netbox/venv/lib64/python3.6/site-packages/rq/job.py", line 657, in perform
self._result = self._execute()
File "/opt/netbox/venv/lib64/python3.6/site-packages/rq/job.py", line 663, in _execute
return self.func(*self.args, **self.kwargs)
File "/opt/netbox/venv/lib64/python3.6/site-packages/axians_netbox_pdu/worker.py", line 36, in collect_power_usage_info
pdu_status = PDUStatus.objects.update_or_create(device=device, defaults={"power_usage": power_usage.value})
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 580, in update_or_create
obj, created = self._create_object_from_params(kwargs, params, lock=True)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 596, in _create_object_from_params
obj = self.create(**params)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 433, in create
obj.save(force_insert=True, using=self.db)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/base.py", line 746, in save
force_update=force_update, update_fields=update_fields)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/base.py", line 784, in save_base
force_update, using, update_fields,
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/base.py", line 887, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/base.py", line 926, in _do_insert
using=using, raw=raw,
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/query.py", line 1204, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1391, in execute_sql
for sql, params in self.as_sql():
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1336, in as_sql
for obj in self.query.objs
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1336, in <listcomp>
for obj in self.query.objs
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1335, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/sql/compiler.py", line 1276, in prepare_value
value = field.get_db_prep_save(value, connection=self.connection)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/fields/__init__.py", line 821, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/fields/__init__.py", line 816, in get_db_prep_value
value = self.get_prep_value(value)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/db/models/fields/__init__.py", line 1776, in get_prep_value
) from e
ValueError: Field 'power_usage' expected a number but got 'NOSUCHINSTANCE'.```
Instead of creating a plugin that does the collecting, manages snmp information, device community strings, etc.
I would suggest to implement that the plugin instead manage metrics associated with what should be displayed.
BIG ASSUMPTION: Assume that the information is being collected by Prometheus and its snmp-exporter. Prometheus has become one of the most popular monitoring systems and has an open http API to expose data.
You would simply query the Prometheus API for instant metrics X, Y and Z. The plugin becomes a simple formatting gateway for data that is collected outside Netbox. Plugins could be easily created for multiple functions (is device up, etc.) That would be monitored by Prometheus. The metric model of Prometheus assures consitent naming for collected data, so that is a nice plus.
This way Netbox remains monitoring agnostic. It integrates data that comes from elsewhere (Ansible, Prometheus API, etc.)
As a DCIM, it is very pertinent to be able to integrate some live data to make informed decisions when populating racks and rack groups.
Getting an error:
execute_from_command_line(sys.argv)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/init.py", line 401, in execute_from_command_line
utility.execute()
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/init.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 368, in execute
self.check()
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/utils/functional.py", line 48, in get
res = instance.dict[self.name] = self.func(instance)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/utils/functional.py", line 48, in get
res = instance.dict[self.name] = self.func(instance)
File "/opt/netbox/venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib64/python3.6/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/opt/netbox/netbox/netbox/urls.py", line 8, in
from extras.plugins.urls import plugin_admin_patterns, plugin_patterns, plugin_api_patterns
File "/opt/netbox/netbox/extras/plugins/urls.py", line 28, in
urlpatterns = import_object(f"{plugin_path}.urls.urlpatterns")
File "/opt/netbox/netbox/extras/plugins/utils.py", line 31, in import_object
spec.loader.exec_module(module)
File "/opt/netbox/venv/lib64/python3.6/site-packages/axians_netbox_pdu/urls.py", line 3, in
from .views import (
File "/opt/netbox/venv/lib64/python3.6/site-packages/axians_netbox_pdu/views.py", line 5, in
from utilities.views import BulkDeleteView, BulkImportView, ObjectEditView, ObjectListView
ImportError: cannot import name 'BulkDeleteView'
(venv) [root@testing-netbox netbox]#
So I'm not sure when they added this, could have been in 2.10.0 or even more recently or I just never noticed it before haha, but anyway it seems that you can now connect power feeds directly to PDU's and the powerfeeds themselves can then display utilization, etc.
The flow is power panels
-> power feeds
-> device (pdu)
-> device (switch, server, etc.)
See screenshots:
In the power feed
page, you can connect it then to a single device/power port:
This feed utilization seems to come from manual values that one plugs into the settings for power port
(upstream facing) on a PDU:
Can't we somehow automatically fill those values in from the usage values we're grabbing off the PDU's via SNMP?
We'd just need to manually define the "size" of the Feed/PDU in power terms, right?
I'm not super familiar with power and power calculations, so let me know if this doesn't make any sense at all haha. But if i'm on the right track here, i'd love to have this auto fill as we want to use the power panels / power feeds much more heavily in Netbox and this would be fantastic!
PDUConfig View
PDUConfig Edit
As an FYI here is what changed that could impact or help the plugin:
If you find any issues or have any questions feel free to hit us on the slack or add a bug /issue or add to the umbrella UI issue netbox-community/netbox/issues/6797
Add a few models to store information that will be collected by this plugin:
PDUConfig
PDUStatus
So apparently they changed a good bit about how custom fields are handled in the models, among other things.
See release notes: https://github.com/netbox-community/netbox/releases/tag/v2.10.0
When running manage.py makemigrations
on upgrade, throws the following error:
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/axians_netbox_pdu/views.py", line 7, in <module>
from .filters import PDUConfigFilter
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/axians_netbox_pdu/filters.py", line 10, in <module>
class PDUConfigFilter(NameSlugSearchFilterSet):
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/axians_netbox_pdu/filters.py", line 17, in PDUConfigFilter
queryset=Manufacturer.objects.filter(device_types__poweroutlet_templates__isnull=False).distinct(),
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/django/db/models/query.py", line 942, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/django/db/models/query.py", line 962, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, *args, **kwargs)
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/django/db/models/query.py", line 969, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1358, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1377, in _add_q
child_clause, needed_inner = self.build_filter(
File "/opt/netbox-2.9.1/venv/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1311, in build_filter
raise FieldError('Related Field got invalid lookup: {}'.format(lookups[0]))
django.core.exceptions.FieldError: Related Field got invalid lookup: poweroutlet_templates
So these filter statements:
I tried to find what they changed exactly to break this but wasn't able to figure it out unfortunately.
Here's the 2.9.0 changelog: https://github.com/netbox-community/netbox/releases/tag/v2.9.0
Show Power Usage on PDU Device
Not working in v3.4.0. After installation, loading the site yields this error:
<class 'django.urls.exceptions.NoReverseMatch'>
'axians_netbox_pdu' is not a registered namespace inside 'plugins'
Python version: 3.9.13
NetBox version: 3.4.0
Centos 8. Fresh install.
netbox-pdu scheduler running.
Environment:
Request Method: GET
Request URL: http://192.168.241.129/plugins/pdu/pdu-config/add/
Django Version: 3.1
Python Version: 3.6.8
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'cacheops',
'corsheaders',
'debug_toolbar',
'django_filters',
'django_tables2',
'django_prometheus',
'mptt',
'rest_framework',
'taggit',
'timezone_field',
'circuits',
'dcim',
'ipam',
'extras',
'secrets',
'tenancy',
'users',
'utilities',
'virtualization',
'django_rq',
'drf_yasg',
'axians_netbox_pdu.PDUConfig',
'netbox_qrcode.QRCodeConfig']
Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'utilities.middleware.ExceptionHandlingMiddleware',
'utilities.middleware.RemoteUserMiddleware',
'utilities.middleware.LoginRequiredMiddleware',
'utilities.middleware.APIVersionMiddleware',
'extras.middleware.ObjectChangeMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware']
Traceback (most recent call last):
File "/opt/netbox-2.9.2/venv/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/opt/netbox-2.9.2/venv/lib64/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/netbox-2.9.2/venv/lib64/python3.6/site-packages/django/views/generic/base.py", line 73, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/netbox-2.9.2/venv/lib64/python3.6/site-packages/django/contrib/auth/mixins.py", line 85, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/opt/netbox/netbox/utilities/views.py", line 392, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/opt/netbox/netbox/utilities/views.py", line 123, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/opt/netbox-2.9.2/venv/lib64/python3.6/site-packages/django/views/generic/base.py", line 101, in dispatch
return handler(request, *args, **kwargs)
File "/opt/netbox/netbox/utilities/views.py", line 395, in get
obj = self.alter_obj(self.get_object(kwargs), request, args, kwargs)
File "/opt/netbox/netbox/utilities/views.py", line 381, in get_object
return self.queryset.model()
Exception Type: AttributeError at /plugins/pdu/pdu-config/add/
Exception Value: 'NoneType' object has no attribute 'model'
NetBox 3.2.0 was just released and has a number of extension improvements.
Furthermore, a NetBox 3.2 plugin tutorial was released
Show Power usage on tenant page
I am unable to install this plugin on netbox 3.0
Are there any plans to update it to support the new releases?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.