Skip to content

Commit

Permalink
Merge pull request #262 from smk4664/grafana-fix-navigation
Browse files Browse the repository at this point in the history
Remove Grafana urls and navigation if disabled.
  • Loading branch information
smk4664 authored Sep 22, 2023
2 parents 87f8b6c + 0d7060a commit e500705
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions changes/241.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove Grafana Navigation and urls if disabled.
12 changes: 6 additions & 6 deletions nautobot_chatops/integrations/grafana/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Django urlpatterns declaration for nautobot_chatops.integrations.grafana plugin."""

# from django.urls import path
from django.conf import settings

from nautobot.core.api import OrderedDefaultRouter
from nautobot_chatops.integrations.grafana.api.views.generic import NautobotPluginChatopsGrafanaRootView


urlpatterns = []
if settings.PLUGINS_CONFIG["nautobot_chatops"]["enable_grafana"]:
router = OrderedDefaultRouter()
router.APIRootView = NautobotPluginChatopsGrafanaRootView

router = OrderedDefaultRouter()
router.APIRootView = NautobotPluginChatopsGrafanaRootView
app_name = "nautobot_chatops.grafana-api"

app_name = "nautobot_chatops.grafana-api"

urlpatterns += router.urls
urlpatterns += router.urls
6 changes: 5 additions & 1 deletion nautobot_chatops/navigation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Plugin additions to the Nautobot navigation menu."""

from django.conf import settings
from nautobot.extras.plugins import PluginMenuItem, PluginMenuButton
from nautobot.utilities.choices import ButtonColorChoices

from .integrations.grafana.navigation import menu_items as grafana_menu_items
if settings.PLUGINS_CONFIG["nautobot_chatops"]["enable_grafana"]:
from .integrations.grafana.navigation import menu_items as grafana_menu_items
else:
grafana_menu_items = ()

menu_items = (
PluginMenuItem(
Expand Down
15 changes: 10 additions & 5 deletions nautobot_chatops/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Django urlpatterns declaration for nautobot_chatops plugin."""
import logging

from django.conf import settings
from django.urls import path

from nautobot.extras.views import ObjectChangeLogView
Expand All @@ -18,15 +19,19 @@
AccessGrantBulkDeleteView,
)

try:
from nautobot_chatops.integrations.grafana.urls import urlpatterns as grafana_urlpatterns
# pylint: disable-next=broad-except
except Exception:
if settings.PLUGINS_CONFIG["nautobot_chatops"]["enable_grafana"]:
try:
from nautobot_chatops.integrations.grafana.urls import urlpatterns as grafana_urlpatterns
# pylint: disable-next=broad-except
except Exception:
grafana_urlpatterns = []
logger = logging.getLogger(__name__)
logger.warning("Grafana ChatOps integration is not available.", exc_info=True)
else:
grafana_urlpatterns = []
logger = logging.getLogger(__name__)
logger.warning("Grafana ChatOps integration is not available.", exc_info=True)


urlpatterns = [
path("", NautobotHomeView.as_view(), name="home"),
path("access/", AccessGrantListView.as_view(), name="accessgrant_list"),
Expand Down

0 comments on commit e500705

Please sign in to comment.