Skip to content

# Package

## `nautobot_circuit_maintenance`

Init for Circuit Maintenance app.

### `CircuitMaintenanceConfig`

Bases: `NautobotAppConfig`

App configuration for the Circuit Maintenance app.

Source code in `nautobot_circuit_maintenance/__init__.py`

     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    class CircuitMaintenanceConfig(NautobotAppConfig):
        """App configuration for the Circuit Maintenance app."""

        name = "nautobot_circuit_maintenance"
        verbose_name = "Circuit Maintenance Management"
        version = __version__
        author = "Network to Code, LLC"
        author_email = "opensource@networktocode.com"
        description = "Nautobot App that automatically manages network circuit maintenance notifications. Dynamically reads email inboxes (or APIs) and updates Nautobot mapping circuit maintenances to devices."
        base_url = "circuit-maintenance"
        min_version = "2.0.0"
        max_version = "2.99"
        required_settings = []
        default_settings = {
            "raw_notification_initial_days_since": 7,
            "raw_notification_size": 8192,
            "dashboard_n_days": 30,
            "overlap_job_exclude_no_impact": False,
        }
        caching_config = {}
        home_view_name = "plugins:nautobot_circuit_maintenance:circuitmaintenance_overview"

        def ready(self):
            """Perform initialization tasks required once the app is ready."""
            super().ready()
            post_migrate.connect(custom_fields_extension, sender=self)
            post_migrate.connect(import_notification_sources, sender=self)

            # App metrics are disabled by default
            if settings.PLUGINS_CONFIG.get("nautobot_circuit_maintenance", {}).get("metrics", {}).get("enable", False):
                # pylint: disable=import-outside-toplevel
                from nautobot_capacity_metrics import register_metric_func
                from .metrics_app import metric_circuit_operational

                register_metric_func(metric_circuit_operational)

#### `ready()`

Perform initialization tasks required once the app is ready.

Source code in `nautobot_circuit_maintenance/__init__.py`

     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    def ready(self):
        """Perform initialization tasks required once the app is ready."""
        super().ready()
        post_migrate.connect(custom_fields_extension, sender=self)
        post_migrate.connect(import_notification_sources, sender=self)

        # App metrics are disabled by default
        if settings.PLUGINS_CONFIG.get("nautobot_circuit_maintenance", {}).get("metrics", {}).get("enable", False):
            # pylint: disable=import-outside-toplevel
            from nautobot_capacity_metrics import register_metric_func
            from .metrics_app import metric_circuit_operational

            register_metric_func(metric_circuit_operational)

### `custom_fields_extension(sender, *, apps=global_apps, **kwargs)`

Add extended custom fields.

Source code in `nautobot_circuit_maintenance/__init__.py`

    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    def custom_fields_extension(sender, *, apps=global_apps, **kwargs):  # pylint: disable=unused-argument
        """Add extended custom fields."""
        # pylint: disable=invalid-name
        ContentType = apps.get_model("contenttypes", "ContentType")
        Provider = apps.get_model("circuits", "Provider")
        CustomField = apps.get_model("extras", "CustomField")
        # pylint: disable=import-outside-toplevel
        from nautobot.extras.choices import CustomFieldTypeChoices

        for provider_cf_dict in [
            {
                "key": "emails_circuit_maintenances",
                "type": CustomFieldTypeChoices.TYPE_TEXT,
                "label": "Emails for Circuit Maintenance app.",
            },
            {
                "key": "provider_parser_circuit_maintenances",
                "type": CustomFieldTypeChoices.TYPE_TEXT,
                "label": "Provider Parser for Circuit Maintenance app.",
            },
        ]:
            defaults = {**provider_cf_dict}
            key = defaults.pop("key")
            field, _ = CustomField.objects.get_or_create(key=key, defaults=defaults)
            field.content_types.set([ContentType.objects.get_for_model(Provider)])

### `import_notification_sources(sender, *, apps=global_apps, **kwargs)`

Import Notification Sources from Nautobot_configuration.py.

This is a temporary solution until a secrets backend is implemented. For now, we create the Notification Sources in the DB but the secrets are fetched via ENV.

Source code in `nautobot_circuit_maintenance/__init__.py`

    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    def import_notification_sources(sender, *, apps=global_apps, **kwargs):  # pylint: disable=unused-argument
        """Import Notification Sources from Nautobot_configuration.py.

        This is a temporary solution until a secrets backend is implemented.
        For now, we create the Notification Sources in the DB but the secrets are fetched via ENV.
        """
        # pylint: disable=invalid-name
        Provider = apps.get_model("circuits", "Provider")
        NotificationSource = apps.get_model("nautobot_circuit_maintenance", "NotificationSource")

        desired_notification_sources_names = []
        for notification_source in settings.PLUGINS_CONFIG.get("nautobot_circuit_maintenance", {}).get(
            "notification_sources", []
        ):
            instance, _ = NotificationSource.objects.update_or_create(
                name=notification_source["name"],
                defaults={
                    "attach_all_providers": notification_source.get("attach_all_providers", False),
                },
            )

            desired_notification_sources_names.append(notification_source["name"])

            if instance.attach_all_providers:
                for provider in Provider.objects.all():
                    instance.providers.add(provider)

        # We remove old Notification Sources that could be in Nautobot but removed from configuration
        NotificationSource.objects.exclude(name__in=desired_notification_sources_names).delete()