Issue: incorrect DeviceConnectionsReport in reports.md #3658

Closed
opened 2025-12-29 18:30:25 +01:00 by adam · 0 comments
Owner

Originally created by @weisdd on GitHub (May 7, 2020).

Change Type

[ ] Addition
[X] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

Area

[ ] Installation instructions
[ ] Configuration parameters
[X] Functionality/features
[ ] REST API
[ ] Administration/development
[ ] Other

Proposed Changes

Since the CONNECTION_STATUS_PLANNED constant is gone from dcim.constants, the DeviceConnectionsReport example in reports.md is no longer correct.

The suggested fix is based on the fact that console_port.connection_status and power_port.connection_status currently have the following set of values:

  • None = A cable is not connected to a Console Server Port or it's connected to a Rear/Front Port;
  • False = A cable is connected to a Console Server Port and marked as Planned;
  • True = A cable is connected to a Console Server Port and marked as Installed.
from dcim.choices import DeviceStatusChoices
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.
        active = DeviceStatusChoices.STATUS_ACTIVE
        for console_port in ConsolePort.objects.prefetch_related('device').filter(device__status=active):
            if console_port.connected_endpoint is None:
                self.log_failure(
                    console_port.device,
                    "No console connection defined for {}".format(console_port.name)
                )
            elif not console_port.connection_status:
                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=DeviceStatusChoices.STATUS_ACTIVE):
            connected_ports = 0
            for power_port in PowerPort.objects.filter(device=device):
                if power_port.connected_endpoint is not None:
                    connected_ports += 1
                    if not power_port.connection_status:
                        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)
Originally created by @weisdd on GitHub (May 7, 2020). ### Change Type [ ] Addition [X] Correction [ ] Deprecation [ ] Cleanup (formatting, typos, etc.) ### Area [ ] Installation instructions [ ] Configuration parameters [X] Functionality/features [ ] REST API [ ] Administration/development [ ] Other <!-- Describe the proposed change(s). --> ### Proposed Changes Since the CONNECTION_STATUS_PLANNED constant is gone from dcim.constants, the [DeviceConnectionsReport example](https://netbox.readthedocs.io/en/stable/additional-features/reports/) in reports.md is no longer correct. The suggested fix is based on the fact that console_port.connection_status and power_port.connection_status currently have the following set of values: * None = A cable is not connected to a Console Server Port or it's connected to a Rear/Front Port; * False = A cable is connected to a Console Server Port and marked as Planned; * True = A cable is connected to a Console Server Port and marked as Installed. ```python from dcim.choices import DeviceStatusChoices 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. active = DeviceStatusChoices.STATUS_ACTIVE for console_port in ConsolePort.objects.prefetch_related('device').filter(device__status=active): if console_port.connected_endpoint is None: self.log_failure( console_port.device, "No console connection defined for {}".format(console_port.name) ) elif not console_port.connection_status: 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=DeviceStatusChoices.STATUS_ACTIVE): connected_ports = 0 for power_port in PowerPort.objects.filter(device=device): if power_port.connected_endpoint is not None: connected_ports += 1 if not power_port.connection_status: 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) ```
adam added the status: acceptedtype: documentation labels 2025-12-29 18:30:25 +01:00
adam closed this issue 2025-12-29 18:30:25 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3658