Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP Fabric Pydantic v2 #313

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes/313.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Update Pydantic to ^2.0.0.
Update Schema Enforcer to ^1.4.0 to support Pydantic V2
Update IPFabric to ^6.6.2
1 change: 0 additions & 1 deletion development/mattermost/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ x-nautobot: &nautobot
environment:
NAUTOBOT_CHATOPS_ENABLE_MATTERMOST: "True"

version: "3.8"
services:
nautobot:
<<: *nautobot
Expand Down
22 changes: 11 additions & 11 deletions docs/admin/integrations/grafana.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ Create a top-level command named `grafana` in your enabled chat platform. For de

You must define the following values in your `nautobot_config.py` file:

| Configuration Setting | Mandatory? | Default | Notes | Available on Admin Config |
| --------------------- | ---------- | ------- | ----- | ------------------------- |
| `enable_grafana` | **Yes** | False | Enable Grafana integration. | Yes |
| `grafana_url` | **Yes** | | Base url that the Grafana application is hosted at. | No |
| `grafana_api_key` | **Yes** | | Found in `<grafana_url>/org/apikeys`. | No |
| `grafana_default_width` | | 0 | Grafana image width when rendered into the chat client. Default will render width dynamically. | No |
| `grafana_default_height` | | 0 | Grafana image height when rendered into the chat client. Default will render height dynamically. | No |
| `grafana_default_theme` | | dark | Theme color to use when generating rendered Grafana images. Options are [`dark`, `light`]. | No |
| `grafana_default_timespan` | | 0 | Timespan that data is collected on a panel in Grafana. Default action is to use the defined timespan in Grafana. | No |
| `grafana_org_id` | | 1 | Found in `<grafana_url>/admin/orgs`. | No |
| `grafana_default_tz` | | | Timezone in which the renderer will render charts and graphs in. | No |
| Configuration Setting | Mandatory? | Default | Notes | Available on Admin Config |
|----------------------------|------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
| `enable_grafana` | **Yes** | False | Enable Grafana integration. | Yes |
| `grafana_url` | **Yes** | | Base url that the Grafana application is hosted at. | No |
| `grafana_api_key` | **Yes** | | Found in `<grafana_url>/org/apikeys`. | No |
| `grafana_default_width` | | 0 | Grafana image width when rendered into the chat client. Default will render width dynamically. | No |
| `grafana_default_height` | | 0 | Grafana image height when rendered into the chat client. Default will render height dynamically. | No |
| `grafana_default_theme` | | dark | Theme color to use when generating rendered Grafana images. Options are [`dark`, `light`]. | No |
| `grafana_default_timespan` | | 0 | Timespan that data is collected on a panel in Grafana. Default action is to use the defined timespan in Grafana. See [Pydanitc Docs](https://docs.pydantic.dev/2.6/api/standard_library_types/#datetimetimedelta). | No |
| `grafana_org_id` | | 1 | Found in `<grafana_url>/admin/orgs`. | No |
| `grafana_default_tz` | | | Timezone in which the renderer will render charts and graphs in. | No |

!!! note
Grafana API key only needs to have `Viewer` permissions assigned!
Expand Down
9 changes: 5 additions & 4 deletions docs/admin/integrations/ipfabric.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ Here is a compatibility matrix and the minimum versions required to run this app

| IP Fabric | Python | Nautobot | chatops | chatops-ipfabric | [python-ipfabric](https://github.com/community-fabric/python-ipfabric) | [python-ipfabric-diagrams](https://github.com/community-fabric/python-ipfabric-diagrams) |
|-----------|--------|----------|---------|------------------|------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| 4.4 | 3.7.1 | 1.1.0 | 1.1.0 | 1.2.0 | 0.11.0 | 1.2.7 |
| 5.0.1 | 3.7.1 | 1.1.0 | 1.1.0 | 1.3.0 | 5.0.4 | 5.0.2 |
| 6.0 | 3.7.1 | 1.4.0 | 1.1.0 | 3.0.0 | 6.0.9 | 6.0.2
| 6.0 | 3.7.2 | 1.4.0 | 1.3.0 | DISABLE | 6.0.9 | 6.0.2
| 4.4 | 3.7.1 | 1.1.0 | 1.1.0 | 1.2.0 | 0.11.0 | 1.2.7 |
| 5.0.1 | 3.7.1 | 1.1.0 | 1.1.0 | 1.3.0 | 5.0.4 | 5.0.2 |
| 6.0 | 3.7.1 | 1.4.0 | 1.1.0 | 3.0.0 | 6.0.9 | 6.0.2 |
| 6.0 | 3.7.2 | 1.4.0 | 1.3.0 | DISABLE | 6.0.9 | 6.0.2 |
| 6.6 | 3.8 | ? | ? | DISABLE | 6.6.2 | DISABLE |

## Command Setup

Expand Down
8 changes: 7 additions & 1 deletion nautobot_chatops/integrations/grafana/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,19 @@ class GrafanaConfigSettings(BaseModel): # pylint: disable=too-few-public-method


def _get_settings_from_chatops(config: dict) -> GrafanaConfigSettings:
try:
# See: https://docs.pydantic.dev/2.6/api/standard_library_types/#datetimetimedelta
default_timespan = int(config["grafana_default_timespan"])
except ValueError:
default_timespan = config["grafana_default_timespan"]

return GrafanaConfigSettings(
grafana_url=config["grafana_url"],
grafana_api_key=config["grafana_api_key"],
default_width=config["grafana_default_width"],
default_height=config["grafana_default_height"],
default_theme=config["grafana_default_theme"],
default_timespan=config["grafana_default_timespan"],
default_timespan=default_timespan,
grafana_org_id=config["grafana_org_id"],
default_tz=config["grafana_default_tz"],
)
Expand Down
2 changes: 1 addition & 1 deletion nautobot_chatops/integrations/grafana/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from isodate import ISO8601Error, parse_duration
from jinja2 import Template
from nautobot.core.models.querysets import RestrictedQuerySet
from pydantic.error_wrappers import ValidationError # pylint: disable=no-name-in-module
from pydantic import ValidationError

from nautobot_chatops.dispatchers import Dispatcher
from nautobot_chatops.integrations.grafana.exceptions import DefaultArgsError, MultipleOptionsError, PanelError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging

from ipfabric import IPFClient
from ipfabric_diagrams import IPFDiagram

logger = logging.getLogger("nautobot")

Expand Down Expand Up @@ -442,13 +441,7 @@ def __init__(self, base_url, token, verify=False, timeout=10):
"""
self.client = IPFClient(
base_url=base_url,
token=token,
verify=verify,
timeout=timeout,
)
self.diagram = IPFDiagram(
base_url=base_url,
token=token,
auth=token,
verify=verify,
timeout=timeout,
)
Expand Down
Loading