Skip to content

Commit

Permalink
IP Fabric Pydantic v2 (#313)
Browse files Browse the repository at this point in the history
* Updated ipfabric to 6.6.2
Fixed lints for ipfabric

* Change to auth instead of token

* Ruff and Poetry Lock

* Add Change Fragments

* Update change fragment

---------

Co-authored-by: Stephen Kiely <[email protected]>
  • Loading branch information
jjeff07 and smk4664 authored Sep 30, 2024
1 parent 42f578e commit a1e8f37
Show file tree
Hide file tree
Showing 10 changed files with 1,007 additions and 875 deletions.
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
9 changes: 1 addition & 8 deletions nautobot_chatops/integrations/ipfabric/ipfabric_wrapper.py
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

0 comments on commit a1e8f37

Please sign in to comment.