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
5 changes: 3 additions & 2 deletions simvue/api/objects/alert/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,19 @@ def new(
token for alternative server, default None

"""
return cls(
_alert = cls(
name=name,
description=description,
notification=notification,
source="user",
enabled=enabled,
server_url=server_url,
server_token=server_token,
_params={"deduplicate": True},
_read_only=False,
_offline=offline,
)
_alert._params = {"deduplicate": True}
return _alert

@override
def _compare_objects(self, other: "AlertBase") -> bool:
Expand Down
39 changes: 0 additions & 39 deletions simvue/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@
except ImportError:
from typing_extensions import Self

if typing.TYPE_CHECKING:
from simvue.api.objects.alert.base import AlertBase


HEARTBEAT_INTERVAL: int = 60
RESOURCES_METRIC_PREFIX: str = "resources"
Expand Down Expand Up @@ -2317,18 +2314,6 @@ def add_alerts(

return True

def _check_if_alert_exists(self, alert: "AlertBase") -> str | None:
"""Check if an existing alert matches definition."""
# If the alert already exists just add the existing one
for _id, _existing_alert in Alert.get(
offline=self.mode == "offline",
server_url=self._user_config.server.url,
server_token=self._user_config.server.token,
):
if _existing_alert == alert:
return _id
return None

@skip_if_failed("_aborted", "_suppress_errors", on_failure_return=None)
@pydantic.validate_call
def create_metric_range_alert(
Expand Down Expand Up @@ -2413,12 +2398,6 @@ def create_metric_range_alert(
server_token=self._user_config.server.token,
)

# If the alert already exists just add the existing one
if _existing_id := self._check_if_alert_exists(_alert):
if attach_to_run:
self.add_alerts(ids=[_existing_id])
return _existing_id

_alert.abort = trigger_abort
_alert.commit()
if attach_to_run:
Expand Down Expand Up @@ -2506,12 +2485,6 @@ def create_metric_threshold_alert(
server_token=self._user_config.server.token,
)

# If the alert already exists just add the existing one
if _existing_id := self._check_if_alert_exists(_alert):
if attach_to_run:
self.add_alerts(ids=[_existing_id])
return _existing_id

_alert.abort = trigger_abort
_alert.commit()
if attach_to_run:
Expand Down Expand Up @@ -2571,12 +2544,6 @@ def create_event_alert(
server_token=self._user_config.server.token,
)

# If the alert already exists just add the existing one
if _existing_id := self._check_if_alert_exists(_alert):
if attach_to_run:
self.add_alerts(ids=[_existing_id])
return _existing_id

_alert.abort = trigger_abort
_alert.commit()

Expand Down Expand Up @@ -2630,12 +2597,6 @@ def create_user_alert(
server_token=self._user_config.server.token,
)

# If the alert already exists just add the existing one
if _existing_id := self._check_if_alert_exists(_alert):
if attach_to_run:
self.add_alerts(ids=[_existing_id])
return _existing_id

_alert.abort = trigger_abort
_alert.commit()
if attach_to_run:
Expand Down
Loading