Skip to content

Monitoring

ptnad.api.monitoring.Status

Bases: str, Enum

ptnad.api.monitoring.TriggerType

Bases: str, Enum

ptnad.api.monitoring.Problem

Problem(status: str, template: str, vars: Dict[str, Any])
Source code in src/ptnad/api/monitoring.py
def __init__(self, status: str, template: str, vars: Dict[str, Any]) -> None:
    self.status = Status(status)
    self.template = template
    self.vars = vars
    self.message = self.template.format(**self.vars)

ptnad.api.monitoring.MonitoringStatus

MonitoringStatus(status: str, problems: List[Dict[str, Any]])
Source code in src/ptnad/api/monitoring.py
def __init__(self, status: str, problems: List[Dict[str, Any]]) -> None:
    self._status = Status(status)
    self.problems_raw = problems
    self.problems = [Problem(**prob) for prob in problems]

ptnad.api.monitoring.Trigger

Trigger(id: str, type: str, status: str, template: str, vars: Dict[str, Any], updated: str)
Source code in src/ptnad/api/monitoring.py
def __init__(self, id: str, type: str, status: str, template: str, vars: Dict[str, Any], updated: str) -> None:
    self.id = id
    self.type = TriggerType(type)
    self.status = Status(status)
    self.template = template
    self.vars = vars
    self.updated = updated

ptnad.api.monitoring.MonitoringAPI

MonitoringAPI(client)

Methods:

Name Description
get_active_triggers

Get all active triggers (triggers with status other than 'green').

get_status

Get the current status.

get_trigger_by_id

Get a specific trigger by its ID.

get_triggers

Get the list of triggers.

get_triggers_by_type

Get all triggers of a specific type.

Source code in src/ptnad/api/monitoring.py
def __init__(self, client) -> None:
    self.client = client

get_active_triggers

get_active_triggers() -> List[Trigger]

Get all active triggers (triggers with status other than 'green').

Returns: List[Trigger]: A list of active Trigger objects.

Raises: PTNADAPIError: If there's an error retrieving the triggers.

Source code in src/ptnad/api/monitoring.py
def get_active_triggers(self) -> List[Trigger]:
    """
    Get all active triggers (triggers with status other than 'green').

    Returns:
        List[Trigger]: A list of active Trigger objects.

    Raises:
        PTNADAPIError: If there's an error retrieving the triggers.

    """
    triggers = self.get_triggers()
    return [trigger for trigger in triggers if trigger.status != "green"]

get_status

get_status() -> MonitoringStatus

Get the current status.

Returns: MonitoringStatus: An object containing the current status and any problems.

Raises: PTNADAPIError: If there's an error retrieving the status.

Source code in src/ptnad/api/monitoring.py
def get_status(self) -> MonitoringStatus:
    """
    Get the current status.

    Returns:
        MonitoringStatus: An object containing the current status and any problems.

    Raises:
        PTNADAPIError: If there's an error retrieving the status.

    """
    try:
        response = self.client.get("/monitoring/status").json()
        return MonitoringStatus(**response)
    except PTNADAPIError as e:
        e.operation = "get monitoring status"
        raise
    except Exception as e:
        raise PTNADAPIError(f"Failed to get monitoring status: {str(e)}")

get_trigger_by_id

get_trigger_by_id(trigger_id: str) -> Trigger | None

Get a specific trigger by its ID.

Args: trigger_id (str): The ID of the trigger to retrieve.

Returns: Optional[Trigger]: The Trigger object if found, None otherwise.

Raises: PTNADAPIError: If there's an error retrieving the trigger.

Source code in src/ptnad/api/monitoring.py
def get_trigger_by_id(self, trigger_id: str) -> Trigger | None:
    """
    Get a specific trigger by its ID.

    Args:
        trigger_id (str): The ID of the trigger to retrieve.

    Returns:
        Optional[Trigger]: The Trigger object if found, None otherwise.

    Raises:
        PTNADAPIError: If there's an error retrieving the trigger.

    """
    triggers = self.get_triggers()
    return next((trigger for trigger in triggers if trigger.id == trigger_id), None)

get_triggers

get_triggers() -> List[Trigger]

Get the list of triggers.

Returns: List[Trigger]: A list of Trigger objects.

Raises: PTNADAPIError: If there's an error retrieving the triggers.

Source code in src/ptnad/api/monitoring.py
def get_triggers(self) -> List[Trigger]:
    """
    Get the list of triggers.

    Returns:
        List[Trigger]: A list of Trigger objects.

    Raises:
        PTNADAPIError: If there's an error retrieving the triggers.

    """
    try:
        response = self.client.get("/monitoring/triggers").json()
        return [Trigger(**trigger) for trigger in response.get("results", [])]
    except PTNADAPIError as e:
        e.operation = "get triggers"
        raise
    except Exception as e:
        raise PTNADAPIError(f"Failed to get triggers: {str(e)}")

get_triggers_by_type

get_triggers_by_type(trigger_type: str) -> List[Trigger]

Get all triggers of a specific type.

Args: trigger_type (str): The type of triggers to retrieve.

Returns: List[Trigger]: A list of Trigger objects of the specified type.

Raises: PTNADAPIError: If there's an error retrieving the triggers.

Source code in src/ptnad/api/monitoring.py
def get_triggers_by_type(self, trigger_type: str) -> List[Trigger]:
    """
    Get all triggers of a specific type.

    Args:
        trigger_type (str): The type of triggers to retrieve.

    Returns:
        List[Trigger]: A list of Trigger objects of the specified type.

    Raises:
        PTNADAPIError: If there's an error retrieving the triggers.

    """
    triggers = self.get_triggers()
    return [trigger for trigger in triggers if trigger.type == trigger_type]