martindstone / pagerduty-cli

A command line interface for PagerDuty
MIT License
91 stars 13 forks source link

How to view timezones for schedules using cli? #41

Closed 825i closed 1 year ago

825i commented 1 year ago

Hi,

I am trying to view the timezones for all the schedules that we have via the CLI.

We have about 600+ schedules and have recently discovered some of our timezones are incorrectly set. This means people are missing duties and incidents.

I can't see a way to check this information with the CLI. It's basically not included at all from what I can see. For schedules there is quite a lot of information but TZ (Timezone) is not one of them. I'd obviously like to pull all TZ information and grep/awk through anything which is incorrectly set.

This information is available using the WebUI, see here: Screenshot 2022-11-08 at 13 36 32

So technically it should be possible to get it via the CLI/api somehow.

P.S. I can see that when making a user via the CLI, it's possible to specify the TZ. Can we please have this for dumping schedule information too?

825i commented 1 year ago

So far I can see this information if I do:

pd schedule:show -i <schedule_id>

Screenshot 2022-11-08 at 13 43 25

The problem with this, is that it only works for individual schedules. What if we have hundreds?

Secondly, it doesn't show me the exact UTC, like the above image in my first comment does. What if I am unsure what TZ "Warsaw" is specifically?

825i commented 1 year ago

Alright, well I made myself a solution. It's not perfect and it doesn't make me feel clean, but it works!

pd schedule:list -j | egrep '\"(name|time_zone)\b.*$$' | awk '/name/ {print $0} /time_zone/ {print $0 "\n"}'

results:

pd schedule:list -j | egrep '\"(name|time_zone)\b.*$$' | awk '/name/ {print $0} /time_zone/ {print $0 "\n"}'
Getting schedules from PD 2/2 👍, 0/2 👎... done
    "name": "1st Line 7-17",
    "time_zone": "Europe/Helsinki",

    "name": "24-5",
    "time_zone": "Europe/Warsaw",

    "name": "Amazon Connect Test",
    "time_zone": "Europe/Warsaw",

    "name": "AWS Support",
    "time_zone": "Europe/Warsaw",

    "name": "Backup Squad",
    "time_zone": "Europe/Warsaw",
... etc

gif

Would still like to see this built into the CLI but I hope this helps someone with getting other information out of their .json results.

martindstone commented 1 year ago

Hi @825i sorry for the delay, you can add columns to the output for any field that appears in the JSON that comes from the fetch. To see time zone in the tabular output from schedule list, you can do pd schedule list -k time_zone

Hope this helps, can you let me know if that resolves the issue for you?

martindstone commented 1 year ago

Hi @825i I am going to close this issue since I think the above should resolve the issue for you... let me know if you have any trouble...

825i commented 1 year ago

Nvm I actually put my brain into gear and I see there is a way to filter columns, so:

➜  ~ pd schedule list -k time_zone --columns=id,name,time_zone
Getting schedules from PD 3/3 👍, 0/3 👎... done
 ID      Name                                    time_zone
 ─────── ─────────────────────────────────────── ───────────────
 P47R7L5 1st Line 7-17                           Europe/Helsinki
 P64JBZZ 24-5                                    Europe/Warsaw
 PDFD16Z Amazon Connect Test                     Europe/Warsaw
 PT8KV6J AWS Support                             Europe/Warsaw
 PEQ5E4Z Backup Squad                            Europe/Warsaw

I love you. This is absolutely amazing. No more piping everything through egrep and awk. Oh my g*d 👯

martindstone commented 1 year ago

Great work, and thank you!