From f21537d9b5526486d4885e9ffe549b28a5fc6bbd Mon Sep 17 00:00:00 2001 From: Pavel Nestsiarovich <895548+pnest@users.noreply.github.com> Date: Thu, 21 Dec 2023 18:10:39 +0300 Subject: [PATCH] Show alert timezone (#37) Show alert timezone along with time. Before: ![image](https://github.com/lyft/opsreview/assets/895548/efad48e0-849e-4bdd-8da7-bd4908768edd) After: ![image](https://github.com/lyft/opsreview/assets/895548/ae75cbe7-491f-426d-b2e6-6c4a1a817eb4) --- README.md | 12 +++++++++--- pull_alerts.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 184ef3c..91ff96d 100644 --- a/README.md +++ b/README.md @@ -12,21 +12,21 @@ Using the opsreview tool, you can quickly compile a report on recent alerts for ``` > python pull_alerts.py -Time: Tuesday, January 19 - 9:19 AM +Time: Tuesday, January 19 - 9:19 AM +0000 Service: api Description: Failing API alarm: CRON failure URL: https://subdomain.pagerduty.com/incidents/ABC123 Notes: ['bob@lyft.com: #a - Re-ran CRON'] -Time: Tuesday, January 19 - 12:03 PM +Time: Tuesday, January 19 - 12:03 PM +0000 Service: api Description: Failing API alarm: CPU percent > 10 URL: https://subdomain.pagerduty.com/incidents/ABC124 Notes: ['bob@lyft.com: #na - Temporary spike in CPU, no action taken. Alert is too sensitive.'] -Time: Tuesday, January 19 - 1:35 PM +Time: Tuesday, January 19 - 1:35 PM +0000 Service: www Description: Failing WWW alarm: 5XX percent > 5 URL: https://subdomain.pagerduty.com/incidents/ABC125 @@ -57,3 +57,9 @@ Run the script. ```bash python pull_alerts.py ``` + +## Timezone +By default, local timezone is used to print alert time. To change default timezone use `TZ` environment variable: +```bash +TZ=UTC python pull_alerts.py +``` \ No newline at end of file diff --git a/pull_alerts.py b/pull_alerts.py index 61a9ce2..b773b8b 100644 --- a/pull_alerts.py +++ b/pull_alerts.py @@ -36,7 +36,7 @@ class FormattedIncident(object): def pretty_output(self): return u'Time: {}\nService: {}\nDescription: {}\nURL: {}\nNotes:\n{}\n'.format( - self.created_on.strftime('%A, %B %-d - %-I:%M %p'), + self.created_on.strftime('%A, %B %-d - %-I:%M %p %z'), self.service, self.description, self.url,