1
1
from __future__ import annotations
2
2
3
3
import logging
4
- from collections .abc import Sequence
5
- from typing import cast
4
+ from collections .abc import Generator , Sequence
5
+ from typing import Any , TypedDict , cast
6
6
7
7
import sentry_sdk
8
8
16
16
from sentry .integrations .types import IntegrationProviderSlug
17
17
from sentry .models .rule import Rule
18
18
from sentry .rules .actions import IntegrationEventAction
19
+ from sentry .rules .base import CallbackFuture
20
+ from sentry .services .eventstore .models import GroupEvent
19
21
from sentry .shared_integrations .exceptions import ApiError
22
+ from sentry .types .rules import RuleFuture
20
23
from sentry .utils .strings import truncatechars
21
24
22
25
logger = logging .getLogger ("sentry.integrations.pagerduty" )
23
26
24
27
28
+ class PagerDutyService (TypedDict ):
29
+ id : int
30
+ integration_key : str
31
+ service_name : str
32
+ integration_id : int
33
+
34
+
25
35
class PagerDutyNotifyServiceAction (IntegrationEventAction ):
26
36
id = "sentry.integrations.pagerduty.notify_action.PagerDutyNotifyServiceAction"
27
37
label = "Send a notification to PagerDuty account {account} and service {service} with {severity} severity"
28
38
prompt = "Send a PagerDuty notification"
29
39
provider = IntegrationProviderSlug .PAGERDUTY .value
30
40
integration_key = "account"
31
41
32
- def __init__ (self , * args , ** kwargs ) :
42
+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
33
43
super ().__init__ (* args , ** kwargs )
34
44
self .form_fields = {
35
45
"account" : {
@@ -49,7 +59,7 @@ def __init__(self, *args, **kwargs):
49
59
},
50
60
}
51
61
52
- def _get_service (self ):
62
+ def _get_service (self ) -> PagerDutyService | None :
53
63
oi = self .get_organization_integration ()
54
64
if not oi :
55
65
return None
@@ -58,7 +68,9 @@ def _get_service(self):
58
68
return pds
59
69
return None
60
70
61
- def after (self , event , notification_uuid : str | None = None ):
71
+ def after (
72
+ self , event : GroupEvent , notification_uuid : str | None = None
73
+ ) -> Generator [CallbackFuture ]:
62
74
integration = self .get_integration ()
63
75
log_context = {
64
76
"organization_id" : self .project .organization_id ,
@@ -79,7 +91,7 @@ def after(self, event, notification_uuid: str | None = None):
79
91
PagerdutySeverity , self .get_option ("severity" , default = PAGERDUTY_DEFAULT_SEVERITY )
80
92
)
81
93
82
- def send_notification (event , futures ) :
94
+ def send_notification (event : GroupEvent , futures : Sequence [ RuleFuture ]) -> None :
83
95
installation = integration .get_installation (self .project .organization_id )
84
96
try :
85
97
client = installation .get_keyring_client (self .get_option ("service" ))
@@ -147,7 +159,7 @@ def get_services(self) -> Sequence[tuple[int, str]]:
147
159
for v in oi .config .get ("pagerduty_services" , [])
148
160
]
149
161
150
- def render_label (self ):
162
+ def render_label (self ) -> str :
151
163
s = self ._get_service ()
152
164
if s :
153
165
service_name = s ["service_name" ]
0 commit comments