Reports error: cannot import name 'STATUS_ACTIVE' #1745

Closed
opened 2025-12-29 16:34:56 +01:00 by adam · 2 comments
Owner

Originally created by @ponasromas on GitHub (May 25, 2018).

Issue type

[ ] Feature request
[X] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.3
  • NetBox version: 2.3.3

Description

Testing reports with given example at https://netbox.readthedocs.io/en/latest/miscellaneous/reports/

After creating devices.py in /opt/netbox/netbox/reports and pasting example code:

from extras.reports import Report

class DeviceConnectionsReport(Report):
    description = "Validate the minimum physical connections for each device"

class DeviceIPsReport(Report):
    description = "Check that every device has a primary IP address assigned"

from dcim.constants import CONNECTION_STATUS_PLANNED, STATUS_ACTIVE
from dcim.models import ConsolePort, Device, PowerPort
from extras.reports import Report


class DeviceConnectionsReport(Report):
    description = "Validate the minimum physical connections for each device"

    def test_console_connection(self):

        # Check that every console port for every active device has a connection defined.
        for console_port in ConsolePort.objects.select_related('device').filter(device__status=STATUS_ACTIVE):
            if console_port.cs_port is None:
                self.log_failure(
                    console_port.device,
                    "No console connection defined for {}".format(console_port.name)
                )
            elif console_port.connection_status == CONNECTION_STATUS_PLANNED:
                self.log_warning(
                    console_port.device,
                    "Console connection for {} marked as planned".format(console_port.name)
                )
            else:
                self.log_success(console_port.device)

    def test_power_connections(self):

        # Check that every active device has at least two connected power supplies.
        for device in Device.objects.filter(status=STATUS_ACTIVE):
            connected_ports = 0
            for power_port in PowerPort.objects.filter(device=device):
                if power_port.power_outlet is not None:
                    connected_ports += 1
                    if power_port.connection_status == CONNECTION_STATUS_PLANNED:
                        self.log_warning(
                            device,
                            "Power connection for {} marked as planned".format(power_port.name)
                        )
            if connected_ports < 2:
                self.log_failure(
                    device,
                    "{} connected power supplies found (2 needed)".format(connected_ports)
                )
            else:
                self.log_success(device)

I receive nicely formated error:

<class 'ImportError'>
cannot import name 'STATUS_ACTIVE'

Supervisor is restarted if it's changing something.
requirements.txt is satisfied, triple checked that.

Originally created by @ponasromas on GitHub (May 25, 2018). <!-- Before opening a new issue, please search through the existing issues to see if your topic has already been addressed. Note that you may need to remove the "is:open" filter from the search bar to include closed issues. Check the appropriate type for your issue below by placing an x between the brackets. For assistance with installation issues, or for any other issues other than those listed below, please raise your topic for discussion on our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please note that issues which do not fall under any of the below categories will be closed. Due to an excessive backlog of feature requests, we are not currently accepting any proposals which extend NetBox's feature scope. Do not prepend any sort of tag to your issue's title. An administrator will review your issue and assign labels as appropriate. ---> ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [X] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) If you are submitting a bug report and have made any changes to the code base, please first validate that your bug can be recreated while running an official release. --> ### Environment * Python version: 3.5.3<!-- Example: 3.5.4 --> * NetBox version: 2.3.3<!-- Example: 2.1.3 --> <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description Testing reports with given example at https://netbox.readthedocs.io/en/latest/miscellaneous/reports/ After creating devices.py in /opt/netbox/netbox/reports and pasting example code: ``` from extras.reports import Report class DeviceConnectionsReport(Report): description = "Validate the minimum physical connections for each device" class DeviceIPsReport(Report): description = "Check that every device has a primary IP address assigned" from dcim.constants import CONNECTION_STATUS_PLANNED, STATUS_ACTIVE from dcim.models import ConsolePort, Device, PowerPort from extras.reports import Report class DeviceConnectionsReport(Report): description = "Validate the minimum physical connections for each device" def test_console_connection(self): # Check that every console port for every active device has a connection defined. for console_port in ConsolePort.objects.select_related('device').filter(device__status=STATUS_ACTIVE): if console_port.cs_port is None: self.log_failure( console_port.device, "No console connection defined for {}".format(console_port.name) ) elif console_port.connection_status == CONNECTION_STATUS_PLANNED: self.log_warning( console_port.device, "Console connection for {} marked as planned".format(console_port.name) ) else: self.log_success(console_port.device) def test_power_connections(self): # Check that every active device has at least two connected power supplies. for device in Device.objects.filter(status=STATUS_ACTIVE): connected_ports = 0 for power_port in PowerPort.objects.filter(device=device): if power_port.power_outlet is not None: connected_ports += 1 if power_port.connection_status == CONNECTION_STATUS_PLANNED: self.log_warning( device, "Power connection for {} marked as planned".format(power_port.name) ) if connected_ports < 2: self.log_failure( device, "{} connected power supplies found (2 needed)".format(connected_ports) ) else: self.log_success(device) ``` I receive nicely formated error: ``` <class 'ImportError'> cannot import name 'STATUS_ACTIVE' ``` Supervisor is restarted if it's changing something. requirements.txt is satisfied, triple checked that.
adam closed this issue 2025-12-29 16:34:57 +01:00
Author
Owner

@monrad commented on GitHub (May 25, 2018):

I ran into this recently, I think STATUS_ACTIVE has changed to DEVICE_STATUS_ACTIVE.

@monrad commented on GitHub (May 25, 2018): I ran into this recently, I think STATUS_ACTIVE has changed to DEVICE_STATUS_ACTIVE.
Author
Owner

@ponasromas commented on GitHub (May 25, 2018):

Thank you. Issue resolved. Very outdated and uninformative documentation for reports. Sad.

@ponasromas commented on GitHub (May 25, 2018): Thank you. Issue resolved. Very outdated and uninformative documentation for reports. Sad.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1745