Skip to content
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
12 changes: 11 additions & 1 deletion src/hyperping/_incidents_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from hyperping._protocols import _ClientProtocol
from hyperping._utils import expect_dict, parse_list, unwrap_list, validate_id
from hyperping.endpoints import Endpoint
from hyperping.exceptions import HyperpingAPIError
from hyperping.models import (
AddIncidentUpdateRequest, # canonical name (M18)
Incident,
Expand Down Expand Up @@ -144,7 +145,16 @@ def add_incident_update(
payload = update.model_dump(exclude_none=True, by_alias=True)
url = f"{Endpoint.INCIDENTS}/{incident_id}/updates"
self._request("POST", url, json=payload) # Returns {"message": "..."} — not a full Incident
return self.get_incident(incident_id)
try:
return self.get_incident(incident_id)
except HyperpingAPIError as exc:
raise HyperpingAPIError(
f"Incident update was posted successfully but refreshing "
f"incident {incident_id!r} failed: {exc}",
status_code=exc.status_code,
response_body=exc.response_body,
request_id=exc.request_id,
) from exc

def resolve_incident(self, incident_id: str, message: str | None = None) -> Incident:
"""Resolve an incident.
Expand Down
11 changes: 5 additions & 6 deletions src/hyperping/_maintenance_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@ def update_maintenance(
current = self.get_maintenance(maintenance_id)
partial = update.model_dump(exclude_none=True, by_alias=True, mode="json")

payload: dict[str, object] = {
"name": current.name,
"start_date": current.start_date,
"end_date": current.end_date,
"monitors": current.monitors,
}
payload: dict[str, object] = current.model_dump(
mode="json",
exclude_none=True,
include={"name", "start_date", "end_date", "monitors"},
)
payload.update(partial)

response = expect_dict(
Expand Down
63 changes: 63 additions & 0 deletions src/hyperping/_outages_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,66 @@ def escalate_outage(self, outage_id: str) -> OutageAction:
validate_id(outage_id, "outage_id") # H8
result = self._request("POST", f"{Endpoint.OUTAGES}/{outage_id}/escalate")
return OutageAction.from_raw(expect_dict(result, "outage operation"))

def unacknowledge_outage(self, outage_id: str) -> OutageAction:
"""Unacknowledge an outage.

Args:
outage_id: Outage UUID.

Returns:
:class:`~hyperping.models.OutageAction` with the action result.

Raises:
HyperpingNotFoundError: If outage not found.
"""
validate_id(outage_id, "outage_id") # H8
result = self._request(
"POST", f"{Endpoint.OUTAGES}/{outage_id}/unacknowledge"
)
return OutageAction.from_raw(expect_dict(result, "outage operation"))

def delete_outage(self, outage_id: str) -> None:
"""Delete an outage.

Args:
outage_id: Outage UUID.

Raises:
HyperpingNotFoundError: If outage not found.
"""
validate_id(outage_id, "outage_id") # H8
self._request("DELETE", f"{Endpoint.OUTAGES}/{outage_id}")

def create_outage(self, monitor_uuid: str) -> Outage:
"""Create a manual outage for a monitor.

Args:
monitor_uuid: Monitor UUID to create the outage for.

Returns:
Created :class:`~hyperping.models.Outage` object.

Raises:
HyperpingValidationError: If the payload fails server-side validation.
HyperpingAPIError: On unexpected API errors.
"""
payload = {"monitor_uuid": monitor_uuid}
result = self._request("POST", Endpoint.OUTAGES, json=payload)
return Outage.model_validate(expect_dict(result, "create_outage"))

def get_outage(self, outage_id: str) -> Outage:
"""Get a single outage by ID.

Args:
outage_id: Outage UUID.

Returns:
:class:`~hyperping.models.Outage` object.

Raises:
HyperpingNotFoundError: If outage not found.
"""
validate_id(outage_id, "outage_id") # H8
result = self._request("GET", f"{Endpoint.OUTAGES}/{outage_id}")
return Outage.model_validate(expect_dict(result, "get_outage"))
Loading