Skip to content
Snippets Groups Projects
Commit 8b8b95d5 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Improve error handling for missing LibreNMS device in router termination

parent 6c55a147
No related branches found
No related tags found
1 merge request!287don't fail router termination if the device doesn't exist in LibreNMS or Kentik
Pipeline #89741 passed
......@@ -8,6 +8,7 @@ from orchestrator.forms import FormPage
from orchestrator.forms.validators import Label
from orchestrator.targets import Target
from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr
from orchestrator.utils.errors import ProcessFailureError
from orchestrator.utils.json import json_dumps
from orchestrator.workflow import StepList, begin, conditional, done, step, workflow
from orchestrator.workflows.steps import (
......@@ -223,13 +224,19 @@ def remove_pe_from_all_p_real(subscription: Router, tt_number: str, process_id:
@step("Remove Device from Librenms")
def remove_device_from_librenms(subscription: Router) -> State | None:
def remove_device_from_librenms(subscription: Router) -> State:
"""Remove the device from LibreNMS."""
try:
LibreNMSClient().remove_device(subscription.router.router_fqdn)
except HTTPError as e:
return {"librenms_error": str(e)}
return None
response = e.response.json()
if response["message"] == f"Device {subscription.router.router_fqdn} not found":
return {
"librenms_error": str(e.response.json()),
"librenms_device": "Device not found, please confirm nothing needs to be removed from LibreNMS",
}
raise ProcessFailureError(message="LibreNMS error", details=response) from None
return {"librenms_device": "Device removed from LibreNMS"}
@step("Apply the archiving license in Kentik")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment