|
6 | 6 | from opsgenie.swagger_client import configuration
|
7 | 7 | from opsgenie.swagger_client.models import *
|
8 | 8 | from opsgenie.swagger_client.rest import ApiException
|
| 9 | +import time |
9 | 10 |
|
10 | 11 | REQUEST_ID = "YOUR_REQUEST_ID"
|
11 | 12 | API_KEY = "YOUR_API_KEY"
|
@@ -177,6 +178,49 @@ def list_alerts():
|
177 | 178 | print("Exception when calling AlertApi->list_alerts: %s\n" % err)
|
178 | 179 |
|
179 | 180 |
|
| 181 | +def list_open_alerts_since_one_week(): |
| 182 | + setup_opsgenie_client() |
| 183 | + |
| 184 | + try: |
| 185 | + current_time_in_seconds = int(round(time.time())) |
| 186 | + one_week_in_seconds = 7 * 24 * 60 * 60 |
| 187 | + |
| 188 | + # Default identifier_type is id |
| 189 | + response = AlertApi().list_alerts( |
| 190 | + limit=25, |
| 191 | + query='createdAt<%d AND createdAt>%d AND status: open' |
| 192 | + % (current_time_in_seconds, (current_time_in_seconds - one_week_in_seconds)), |
| 193 | + order='desc', |
| 194 | + sort='createdAt') |
| 195 | + |
| 196 | + # Refer to ListAlertsResponse for more detailed data |
| 197 | + print('request id: {}'.format(response.request_id)) |
| 198 | + print('took: {}'.format(response.took)) |
| 199 | + for alert_response in response.data: |
| 200 | + print('alert_response.id: {}'.format(alert_response.id)) |
| 201 | + print('alert_response.tiny_id: {}'.format(alert_response.tiny_id)) |
| 202 | + print('alert_response.alias: {}'.format(alert_response.alias)) |
| 203 | + print('alert_response.message: {}'.format(alert_response.message)) |
| 204 | + print('alert_response.status: {}'.format(alert_response.status)) |
| 205 | + print('alert_response.acknowledged: {}'.format(alert_response.acknowledged)) |
| 206 | + print('alert_response.is_seen: {}'.format(alert_response.is_seen)) |
| 207 | + print('alert_response.tags: {}'.format(alert_response.tags)) |
| 208 | + print('alert_response.snoozed: {}'.format(alert_response.snoozed)) |
| 209 | + print('alert_response.snoozed_until: {}'.format(alert_response.snoozed_until)) |
| 210 | + print('alert_response.count: {}'.format(alert_response.count)) |
| 211 | + print('alert_response.last_occurred_at: {}'.format(alert_response.last_occurred_at)) |
| 212 | + print('alert_response.created_at: {}'.format(alert_response.created_at)) |
| 213 | + print('alert_response.updated_at: {}'.format(alert_response.updated_at)) |
| 214 | + print('alert_response.source: {}'.format(alert_response.source)) |
| 215 | + print('alert_response.owner: {}'.format(alert_response.owner)) |
| 216 | + print('alert_response.priority: {}'.format(alert_response.priority)) |
| 217 | + print('alert_response.teams: {}'.format(alert_response.teams)) |
| 218 | + print('alert_response.integration: {}'.format(alert_response.integration)) |
| 219 | + print('alert_response.report: {}'.format(alert_response.report)) |
| 220 | + except ApiException as err: |
| 221 | + print("Exception when calling AlertApi->list_alerts: %s\n" % err) |
| 222 | + |
| 223 | + |
180 | 224 | def acknowledge_alert():
|
181 | 225 | setup_opsgenie_client()
|
182 | 226 |
|
|
0 commit comments