11import click
2+ import json
23from utils import display_paginated_results , handle_api_error , format_item_details
34
45@click .group ()
@@ -17,7 +18,7 @@ def alerts():
1718def create_alert_cmd (ctx , title , description , team_ids , urgency , tags , alias ):
1819 """Create a new alert in PagerTree."""
1920 try :
20- client = ctx .obj # Get PagerTreeClient from context
21+ client = ctx .obj . client # Get PagerTreeClient from context
2122 result = client .create_alert (
2223 title = title ,
2324 description = description ,
@@ -39,15 +40,19 @@ def create_alert_cmd(ctx, title, description, team_ids, urgency, tags, alias):
3940def list_alerts_cmd (ctx , limit , offset , status , search ):
4041 """List alerts in PagerTree with pagination."""
4142 try :
42- client = ctx .obj # Get PagerTreeClient from context
43+ client = ctx .obj .client # Get PagerTreeClient from context
44+ logger = ctx .obj .logger # Get logger from context
45+ logger .debug (f"Listing alerts with limit={ limit } , offset={ offset } , status={ status } , search={ search } " )
4346 result = client .list_alerts (limit = limit , offset = offset , status = status , search = search )
47+ logger .debug (f"Full response: { json .dumps (result , indent = 2 )} " )
4448 alerts_list = result ["data" ]
4549 total = result ["total" ]
4650 # Prepare table data
4751 headers = ["ID" , "Title" , "Status" ]
4852 table_data = [[alert .get ("id" ), alert .get ("title" ), alert .get ("status" )] for alert in alerts_list ]
4953 display_paginated_results (alerts_list , total , limit , offset , "alert" , headers , table_data )
5054 except Exception as e :
55+ logger .error (f"Error listing alerts: { str (e )} " )
5156 handle_api_error (e , action = "listing alerts" )
5257
5358@alerts .command (name = "show" )
@@ -56,7 +61,7 @@ def list_alerts_cmd(ctx, limit, offset, status, search):
5661def show_alert_cmd (ctx , alert_id ):
5762 """Show details of a specific alert in PagerTree."""
5863 try :
59- client = ctx .obj # Get PagerTreeClient from context
64+ client = ctx .obj . client # Get PagerTreeClient from context
6065 alert = client .show_alert (alert_id )
6166 fields = {
6267 "id" : "ID" ,
@@ -85,7 +90,7 @@ def delete_alert_cmd(ctx, alert_id, force):
8590 click .echo ("Deletion cancelled." )
8691 return
8792 try :
88- client = ctx .obj # Get PagerTreeClient from context
93+ client = ctx .obj . client # Get PagerTreeClient from context
8994 result = client .delete_alert (alert_id )
9095 click .echo (f"Alert deleted successfully: { alert_id } " )
9196 except Exception as e :
@@ -98,7 +103,7 @@ def delete_alert_cmd(ctx, alert_id, force):
98103def acknowledge_alert_cmd (ctx , alert_id , alias ):
99104 """Acknowledge an alert in PagerTree."""
100105 try :
101- client = ctx .obj # Get PagerTreeClient from context
106+ client = ctx .obj . client # Get PagerTreeClient from context
102107
103108 # Ensure at least one of alert_id or alias is provided
104109 if not alert_id and not alias :
@@ -130,7 +135,7 @@ def acknowledge_alert_cmd(ctx, alert_id, alias):
130135def reject_alert_cmd (ctx , alert_id , alias ):
131136 """Reject an alert in PagerTree."""
132137 try :
133- client = ctx .obj # Get PagerTreeClient from context
138+ client = ctx .obj . client # Get PagerTreeClient from context
134139
135140 # Ensure at least one of alert_id or alias is provided
136141 if not alert_id and not alias :
@@ -162,7 +167,7 @@ def reject_alert_cmd(ctx, alert_id, alias):
162167def resolve_alert_cmd (ctx , alert_id , alias ):
163168 """Resolve an alert in PagerTree."""
164169 try :
165- client = ctx .obj # Get PagerTreeClient from context
170+ client = ctx .obj . client # Get PagerTreeClient from context
166171
167172 # Ensure at least one of alert_id or alias is provided
168173 if not alert_id and not alias :
@@ -196,7 +201,7 @@ def resolve_alert_cmd(ctx, alert_id, alias):
196201def list_alert_comment_cmd (ctx , alert_id , alias , limit , offset ):
197202 """List an alert's comments in PagerTree."""
198203 try :
199- client = ctx .obj # Get PagerTreeClient from context
204+ client = ctx .obj . client # Get PagerTreeClient from context
200205
201206 # Ensure at least one of alert_id or alias is provided
202207 if not alert_id and not alias :
@@ -234,7 +239,7 @@ def list_alert_comment_cmd(ctx, alert_id, alias, limit, offset):
234239def create_alert_comment_cmd (ctx , alert_id , alias , comment ):
235240 """Add a comment to an alert in PagerTree."""
236241 try :
237- client = ctx .obj # Get PagerTreeClient from context
242+ client = ctx .obj . client # Get PagerTreeClient from context
238243
239244 # Ensure at least one of alert_id or alias is provided
240245 if not alert_id and not alias :
0 commit comments