Skip to content

Commit 9f66e8e

Browse files
committed
fix:PRComments
1 parent 250804d commit 9f66e8e

14 files changed

+465
-225
lines changed

docs/api_reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ API Reference
88
:caption: Table of Contents
99

1010
api_reference/core
11+
api_reference/alarm
1112
api_reference/tag
1213
api_reference/product
1314
api_reference/testmonitor

docs/api_reference/alarm.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. _api_alarm_page:
2+
3+
nisystemlink.clients.alarm
4+
==========================
5+
6+
.. autoclass:: nisystemlink.clients.alarm.AlarmClient
7+
:exclude-members: __init__
8+
9+
.. automethod:: __init__
10+
.. automethod:: create_or_update_alarm
11+
.. automethod:: get_alarm
12+
.. automethod:: delete_alarm
13+
.. automethod:: delete_instances_by_instance_id
14+
.. automethod:: acknowledge_alarm
15+
.. automethod:: query_alarms
16+
17+
.. automodule:: nisystemlink.clients.alarm.models
18+
:members:
19+
:imported-members:

docs/getting_started.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,55 @@
33
Getting Started
44
===============
55

6+
Alarm API
7+
---------
8+
9+
Overview
10+
~~~~~~~~
11+
12+
The :class:`.AlarmClient` class is the primary entry point of the Alarm API.
13+
14+
When constructing an :class:`.AlarmClient`, you can pass an
15+
:class:`.HttpConfiguration` (like one retrieved from the
16+
:class:`.HttpConfigurationManager`), or let :class:`.AlarmClient` use the
17+
default connection. The default connection depends on your environment.
18+
19+
With an :class:`.AlarmClient` object, you can:
20+
21+
* Create and update alarm instances using :meth:`~.AlarmClient.create_or_update_alarm`
22+
23+
* Alarms have two key identifiers:
24+
25+
* ``alarm_id``: A user-defined identifier for the alarm type
26+
* ``instance_id``: A server-generated unique identifier for each alarm occurrence
27+
28+
* Create alarm transitions (SET, CLEAR) to track alarm state changes
29+
30+
* Query alarms with :meth:`~.AlarmClient.query_alarms`
31+
32+
* Filter alarms using Dynamic LINQ expressions
33+
* Control which transitions are returned (most recent only or all)
34+
* Sort and paginate results
35+
36+
* Get a specific alarm by its instance_id using :meth:`~.AlarmClient.get_alarm`
37+
38+
* Acknowledge alarms with :meth:`~.AlarmClient.acknowledge_alarm`
39+
40+
* Optionally force-clear alarms when acknowledging
41+
42+
* Delete alarms using :meth:`~.AlarmClient.delete_alarm` or
43+
:meth:`~.AlarmClient.delete_instances_by_instance_id`
44+
45+
Examples
46+
~~~~~~~~
47+
48+
Create, query, acknowledge, and delete alarms
49+
50+
.. literalinclude:: ../examples/alarm/alarm.py
51+
:language: python
52+
:linenos:
53+
54+
655
Tag API
756
-------
857

examples/alarm/alarm.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from nisystemlink.clients.alarm import AlarmClient
55
from nisystemlink.clients.alarm.models import (
6-
AcknowledgeByInstanceIdRequest,
76
CreateOrUpdateAlarmRequest,
87
QueryWithFilterRequest,
98
)
@@ -25,6 +24,7 @@
2524
client = AlarmClient(configuration=server_configuration)
2625

2726
# Create a unique alarm ID for this example
27+
# alarm_id is a user-defined identifier for this alarm
2828
alarm_id = f"example_alarm_{uuid.uuid1().hex}"
2929

3030
# Create an alarm with a SET transition
@@ -38,13 +38,13 @@
3838
message="Temperature sensor reading: 85°C",
3939
),
4040
)
41-
create_response = client.create_or_update_alarm(create_request)
42-
instance_id = create_response.instance_id
41+
# Returns instance_id - a server-generated unique identifier for this specific alarm occurrence
42+
id = client.create_or_update_alarm(create_request)
4343

44-
# Get the alarm by instance ID
45-
alarm = client.get_alarm(instance_id)
44+
# Get the alarm by its instance ID (the unique occurrence identifier)
45+
alarm = client.get_alarm(id)
4646

47-
# Update the alarm with a higher severity
47+
# Update the alarm with a higher severity (same alarm_id, updates the same instance)
4848
update_request = CreateOrUpdateAlarmRequest(
4949
alarm_id=alarm_id,
5050
transition=CreateAlarmTransition(
@@ -55,9 +55,9 @@
5555
message="Temperature sensor reading: 95°C",
5656
),
5757
)
58-
update_response = client.create_or_update_alarm(update_request)
58+
client.create_or_update_alarm(update_request)
5959

60-
# Query alarms with a filter
60+
# Query alarms with a filter (can filter by alarm_id to find all instances)
6161
query_request = QueryWithFilterRequest(
6262
filter=f'alarmId="{alarm_id}"',
6363
transition_inclusion_option=TransitionInclusionOption.ALL,
@@ -67,9 +67,8 @@
6767
)
6868
query_response = client.query_alarms(query_request)
6969

70-
# Acknowledge the alarm
71-
ack_request = AcknowledgeByInstanceIdRequest(instance_ids=[instance_id])
72-
ack_response = client.acknowledge_instances_by_instance_id(ack_request)
70+
# Acknowledge the alarm using its instance ID
71+
ack_response = client.acknowledge_alarm([id])
7372

7473
# Clear the alarm
7574
clear_request = CreateOrUpdateAlarmRequest(
@@ -81,7 +80,7 @@
8180
condition="Temperature returned to normal",
8281
),
8382
)
84-
clear_response = client.create_or_update_alarm(clear_request)
83+
client.create_or_update_alarm(clear_request)
8584

86-
# Delete the alarm by instance ID
87-
client.delete_alarm(instance_id)
85+
# Delete the alarm by its instance ID
86+
client.delete_alarm(id)

nisystemlink/clients/alarm/_alarm_client.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from nisystemlink.clients import core
66
from nisystemlink.clients.core._uplink._base_client import BaseClient
77
from nisystemlink.clients.core._uplink._methods import delete, get, post
8-
from uplink import retry
8+
from uplink import Field, retry
99

1010
from . import models
1111

@@ -16,6 +16,7 @@
1616
on_exception=retry.CONNECTION_ERROR,
1717
)
1818
class AlarmClient(BaseClient):
19+
1920
def __init__(self, configuration: Optional[core.HttpConfiguration] = None):
2021
"""Initialize an instance.
2122
@@ -26,92 +27,107 @@ def __init__(self, configuration: Optional[core.HttpConfiguration] = None):
2627
is used to obtain the configuration.
2728
2829
Raises:
29-
ApiException: if unable to communicate with the Alarm Service.
30+
ApiException: if unable to communicate with the `/nialarm` Service.
3031
"""
3132
if configuration is None:
3233
configuration = core.HttpConfigurationManager.get_configuration()
34+
3335
super().__init__(configuration, base_path="/nialarm/v1/")
3436

35-
@post("acknowledge-instances-by-instance-id")
36-
def acknowledge_instances_by_instance_id(
37-
self, request: models.AcknowledgeByInstanceIdRequest
37+
@post(
38+
"acknowledge-instances-by-instance-id",
39+
args=[Field("instanceIds"), Field("forceClear")],
40+
)
41+
def acknowledge_alarm(
42+
self, instance_ids: list[str], force_clear: bool = False
3843
) -> models.AcknowledgeByInstanceIdResponse:
3944
"""Acknowledges one or more alarm instances by their instance IDs.
4045
4146
Args:
42-
request: The request containing instance IDs to acknowledge and optional force clear flag.
47+
instance_ids: List of instance IDs (unique occurrence identifiers) of the alarms to acknowledge.
48+
These are the server-generated IDs returned when creating/updating alarms,
49+
not the user-defined alarm_id.
50+
force_clear: Whether or not the affected alarms should have their clear field set to true.
51+
Defaults to False.
4352
4453
Returns:
4554
A response containing the instance IDs that were successfully acknowledged,
4655
the instance IDs that failed, and error details for failures.
4756
4857
Raises:
49-
ApiException: if unable to communicate with the Alarm Service or provided invalid arguments.
58+
ApiException: if unable to communicate with the `/nialarm` Service or provided invalid arguments.
5059
"""
5160
...
5261

53-
@post("instances")
54-
def create_or_update_alarm(
55-
self, request: models.CreateOrUpdateAlarmRequest
56-
) -> models.CreateOrUpdateAlarmResponse:
62+
@post("instances", return_key="instanceId")
63+
def create_or_update_alarm(self, request: models.CreateOrUpdateAlarmRequest) -> str:
5764
"""Creates or updates an instance, or occurrence, of an alarm.
5865
5966
Creates or updates an alarm based on the requested transition and the state
60-
of the current active alarm with the given alarmId.
67+
of the current active alarm with the given alarm_id (specified in the request).
68+
Multiple calls with the same alarm_id will update the same alarm instance.
6169
6270
Args:
63-
request: The request containing alarm information and transition details.
71+
request: The request containing alarm_id (user-defined identifier),
72+
transition details, and other alarm properties.
6473
6574
Returns:
66-
A response containing the ID of the created or modified alarm.
75+
The instance_id (unique occurrence identifier) of the created or modified alarm.
76+
Use this ID for operations like get_alarm(), delete_alarm(), or acknowledge.
6777
6878
Raises:
69-
ApiException: if unable to communicate with the Alarm Service or provided invalid arguments.
79+
ApiException: if unable to communicate with the `/nialarm` Service or provided invalid arguments.
7080
"""
7181
...
7282

7383
@get("instances/{instance_id}")
7484
def get_alarm(self, instance_id: str) -> models.Alarm:
75-
"""Gets an alarm by its instanceId.
85+
"""Gets an alarm by its instance_id.
7686
7787
Args:
78-
instance_id: Unique ID of a particular instance, or occurrence, of an alarm.
88+
instance_id: The unique instance ID (occurrence identifier) of the alarm to retrieve.
89+
This is the server-generated ID returned from create_or_update_alarm(),
90+
not the user-defined alarm_id.
7991
8092
Returns:
81-
The alarm with the specified instance ID.
93+
The alarm with the specified instance_id.
8294
8395
Raises:
84-
ApiException: if unable to communicate with the Alarm Service or provided invalid arguments.
96+
ApiException: if unable to communicate with the `/nialarm` Service or provided invalid arguments.
8597
"""
8698
...
8799

88100
@delete("instances/{instance_id}")
89101
def delete_alarm(self, instance_id: str) -> None:
90-
"""Deletes an alarm by its instanceId.
102+
"""Deletes an alarm by its instance_id.
91103
92104
Args:
93-
instance_id: Unique ID of a particular instance, or occurrence, of an alarm.
105+
instance_id: The unique instance ID (occurrence identifier) of the alarm to delete.
106+
This is the server-generated ID returned from create_or_update_alarm(),
107+
not the user-defined alarm_id.
94108
95109
Raises:
96-
ApiException: if unable to communicate with the Alarm Service or provided invalid arguments.
110+
ApiException: if unable to communicate with the `/nialarm` Service or provided invalid arguments.
97111
"""
98112
...
99113

100-
@post("delete-instances-by-instance-id")
114+
@post("delete-instances-by-instance-id", args=[Field("instanceIds")])
101115
def delete_instances_by_instance_id(
102-
self, request: models.DeleteByInstanceIdRequest
116+
self, instance_ids: list[str]
103117
) -> models.DeleteByInstanceIdResponse:
104-
"""Deletes multiple alarm instances by their instanceIds.
118+
"""Deletes multiple alarm instances by their instance IDs.
105119
106120
Args:
107-
request: Contains the instanceIds of the alarms to delete.
121+
instance_ids: List of instance IDs (unique occurrence identifiers) of the alarms to delete.
122+
These are the server-generated IDs returned when creating/updating alarms,
123+
not the user-defined alarm_id.
108124
109125
Returns:
110-
A response containing lists of successfully deleted and failed instanceIds,
126+
A response containing lists of successfully deleted and failed instance IDs,
111127
along with error information for failures.
112128
113129
Raises:
114-
ApiException: if unable to communicate with the Alarm Service or provided invalid arguments.
130+
ApiException: if unable to communicate with the `/nialarm` Service or provided invalid arguments.
115131
"""
116132
...
117133

@@ -131,6 +147,6 @@ def query_alarms(
131147
optional total count and continuation token for pagination.
132148
133149
Raises:
134-
ApiException: if unable to communicate with the Alarm Service or provided invalid arguments.
150+
ApiException: if unable to communicate with the `/nialarm` Service or provided invalid arguments.
135151
"""
136152
...
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from ._acknowledge_by_instance_id_request import AcknowledgeByInstanceIdRequest
21
from ._acknowledge_by_instance_id_response import AcknowledgeByInstanceIdResponse
3-
from ._alarm import Alarm
4-
from ._create_or_update_alarm_request import CreateOrUpdateAlarmRequest
5-
from ._create_or_update_alarm_response import CreateOrUpdateAlarmResponse
6-
from ._delete_by_instance_id_request import DeleteByInstanceIdRequest
2+
from ._alarm import Alarm, AlarmNote, AlarmTransition, AlarmTransitionType
3+
from ._create_or_update_alarm_request import (
4+
CreateAlarmTransition,
5+
CreateOrUpdateAlarmRequest,
6+
)
77
from ._delete_by_instance_id_response import DeleteByInstanceIdResponse
8-
from ._query_alarms_request import QueryWithFilterRequest
8+
from ._query_alarms_request import (
9+
AlarmOrderBy,
10+
QueryWithFilterRequest,
11+
TransitionInclusionOption,
12+
)
913
from ._query_alarms_response import QueryWithFilterResponse
1014

1115
# flake8: noqa

nisystemlink/clients/alarm/models/_acknowledge_by_instance_id_request.py

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import List
22

33
from nisystemlink.clients.alarm.models._partial_success_response_base import (
4-
PartialSuccessResponseBase,
4+
AlarmInstancesPartialSuccess,
55
)
66

77

8-
class AcknowledgeByInstanceIdResponse(PartialSuccessResponseBase):
8+
class AcknowledgeByInstanceIdResponse(AlarmInstancesPartialSuccess):
99
"""Contains information about which alarms were acknowledged."""
1010

1111
acknowledged: List[str]
12-
"""The instanceIds of the alarms which were successfully acknowledged."""
12+
"""The instanceIds of the alarms that were successfully acknowledged."""

nisystemlink/clients/alarm/models/_create_or_update_alarm_response.py

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from typing import List
22

33
from nisystemlink.clients.alarm.models._partial_success_response_base import (
4-
PartialSuccessResponseBase,
4+
AlarmInstancesPartialSuccess,
55
)
66

77

8-
class DeleteByInstanceIdResponse(PartialSuccessResponseBase):
9-
"""Contains information about which alarms were deleted."""
8+
class DeleteByInstanceIdResponse(AlarmInstancesPartialSuccess):
9+
"""Contains information about alarms that were deleted."""
1010

1111
deleted: List[str]
1212
"""The instanceIds of the alarms that were successfully deleted."""

0 commit comments

Comments
 (0)