Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #88 from nautobot/release-v1.1.2
Browse files Browse the repository at this point in the history
Release v1.1.2
  • Loading branch information
pke11y authored May 11, 2022
2 parents f0bf1c6 + 11c536f commit 399b8ba
Show file tree
Hide file tree
Showing 11 changed files with 1,308 additions and 888 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
# E501: Line length is enforced by Black, so flake8 doesn't need to check it
# W503: Black disagrees with this rule, as does PEP 8; Black wins
ignore = E501, W503
ignore = E501, W503, F811, F402
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Default owner(s) of all files in this repository
* @pke11y @chadell @scetron
* @pke11y @chadell @scetron @h4ndzdatm0ld

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
python-version: ["3.7", "3.8", "3.9"]
nautobot-version: ["1.0.1", "1.1.4"]
runs-on: "ubuntu-20.04"
env:
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
- name: "Upload binaries to release"
uses: "svenstaro/upload-release-action@v2"
with:
repo_token: "${{ secrets.NTC_GITHUB_TOKEN }}"
repo_token: "${{ secrets.GH_NAUTOBOT_BOT_TOKEN }}"
file: "dist/*"
tag: "${{ github.ref }}"
overwrite: true
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v1.1.2 - 2022-05-11

### Added

- #87 - Migrate `ipfabric pathlookup` to use the ipfabric-diagrams library. PNG output for IP Fabric 4.3+ only.
- #85 - Update plugin description to Nautobot Plugin Chatops IPFabric.
- #84 - Added Hugo as codeowner.
- #83 - Request permission to send files to Microsoft Teams.


## v1.1.1 - 2022-02-10

### Added
Expand Down
1 change: 1 addition & 0 deletions development/creds.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ NAUTOBOT_SUPERUSER_PASSWORD=admin
IPFABRIC_API_TOKEN=foo
IPFABRIC_HOST=https://ipfabric.myserver.com
IPFABRIC_VERIFY=true
IPFABRIC_TIMEOUT=5
1 change: 1 addition & 0 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def is_truthy(arg):
"IPFABRIC_API_TOKEN": os.environ.get("IPFABRIC_API_TOKEN"),
"IPFABRIC_HOST": os.environ.get("IPFABRIC_HOST"),
"IPFABRIC_VERIFY": is_truthy(os.environ.get("IPFABRIC_VERIFY", True)),
"IPFABRIC_TIMEOUT": os.environ.get("IPFABRIC_TIMEOUT", 15),
},
}

Expand Down
36 changes: 0 additions & 36 deletions nautobot_chatops_ipfabric/ipfabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,42 +194,6 @@ def get_path_simulation(
payload = {}
return self.get_response_json("GET", "/api/v1/graph/end-to-end-path", payload, params)

def get_pathlookup(
self, src_ip, dst_ip, src_port, dst_port, protocol, snapshot_id
): # pylint: disable=too-many-arguments
"""Return pathlookup simulation as PNG output. Requires v4 IP Fabric server."""
no_png_flags = ["no-dgw", "no-receiver", "no-source"] # a path with these flags results in any empty PNG
payload = {
"snapshot": snapshot_id,
"parameters": {
"type": "pathLookup",
"pathLookupType": "unicast",
"protocol": protocol,
"startingPoint": src_ip,
"startingPort": src_port,
"destinationPoint": dst_ip,
"destinationPort": dst_port,
"groupBy": "siteName",
"networkMode": "true",
"securedPath": "false",
},
}
logger.debug( # pylint: disable=logging-too-many-args
"Received end-to-end PNG path simulation request: ", payload
)

# no params required
params = {}

json_response = self.get_response_json("POST", "/api/v1/graphs", payload, params=params)
pathlookup = json_response.get("pathlookup", {})
png_response = self.get_response_raw("POST", "/api/v1/graphs/png", payload, params=params)

for flag in pathlookup.get("eventsSummary", {}).get("flags"):
if flag in no_png_flags:
return None
return png_response.content

def get_interfaces_errors_info(self, device, snapshot_id=LAST, limit=DEFAULT_PAGE_LIMIT):
"""Return bi-directional interface errors info."""
logger.debug("Received interface error counters request")
Expand Down
57 changes: 45 additions & 12 deletions nautobot_chatops_ipfabric/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from nautobot_chatops.workers import subcommand_of, handle_subcommands
from netutils.ip import is_ip
from netutils.mac import is_valid_mac
from ipfabric_diagrams import IPFDiagram, Unicast
from ipfabric import IPFClient

from .ipfabric import IpFabric, LAST
from .context import get_context, set_context

Expand All @@ -21,12 +24,26 @@

logger = logging.getLogger("rq.worker")

# TODO: us of the IpFabric class is temporary until we complete migration to python-ipfabric library
ipfabric_api = IpFabric(
host_url=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_HOST"),
token=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_API_TOKEN"),
verify=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_VERIFY"),
)

ipfabric_client = IPFClient(
base_url=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_HOST"),
token=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_API_TOKEN"),
verify=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_VERIFY"),
)

ipfabric_diagram_client = IPFDiagram(
base_url=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_HOST"),
token=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_API_TOKEN"),
verify=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_VERIFY"),
timeout=settings.PLUGINS_CONFIG["nautobot_chatops_ipfabric"].get("IPFABRIC_TIMEOUT"),
)

inventory_field_mapping = {
"site": "siteName",
"model": "model",
Expand Down Expand Up @@ -464,22 +481,22 @@ def pathlookup(
"type": "text",
"label": "Destination IP",
},
{
"type": "select",
"label": "Protocol",
"choices": protocols,
"default": protocols[0],
},
{
"type": "text",
"label": "Source Port",
"label": "Source Ports",
"default": "1000",
},
{
"type": "text",
"label": "Destination Port",
"label": "Destination Ports",
"default": "22",
},
{
"type": "select",
"label": "Protocol",
"choices": protocols,
"default": protocols[0],
},
]

if not all([src_ip, dst_ip, src_port, dst_port, protocol]):
Expand Down Expand Up @@ -513,10 +530,18 @@ def pathlookup(
]
)

# only supported in IP Fabric OS version 4.0+
# diagrams for 4.0 - 4.2 are not supported due to attribute changes in 4.3+
try:
if ipfabric_api.validate_version(ge, 4.0):
raw_png = ipfabric_api.get_pathlookup(src_ip, dst_ip, src_port, dst_port, protocol, snapshot_id)
os_version = ipfabric_client.os_version
if os_version and ge(os_version, "4.3"):
unicast = Unicast(
startingPoint=src_ip,
destinationPoint=dst_ip,
protocol=protocol,
srcPorts=src_port,
dstPorts=dst_port,
)
raw_png = ipfabric_diagram_client.diagram_png(unicast, snapshot_id)
if not raw_png:
raise RuntimeError(
"An error occurred while retrieving the path lookup. Please verify the path using the link above."
Expand All @@ -525,12 +550,20 @@ def pathlookup(
# Note: Microsoft Teams will silently fail if we have ":" in our filename, so the timestamp has to skip them.
time_str = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
img_path = os.path.join(tempdir, f"{sub_cmd}_{time_str}.png")
# MS Teams requires permission to upload files.
if dispatcher.needs_permission_to_send_image():
dispatcher.ask_permission_to_send_image(
f"{sub_cmd}_{time_str}.png",
f"{BASE_CMD} {sub_cmd} {src_ip} {dst_ip} {src_port} {dst_port} {protocol}",
)
return False

with open(img_path, "wb") as img_file:
img_file.write(raw_png)
dispatcher.send_image(img_path)
else:
raise RuntimeError(
"Your IP Fabric OS version does not support PNG output. Please try the end-to-end-path command."
"PNG output for this chatbot is only supported on IP Fabric version 4.3 and above. Please try the end-to-end-path command."
)
except (RuntimeError, OSError) as error:
dispatcher.send_error(error)
Expand Down
Loading

0 comments on commit 399b8ba

Please sign in to comment.