martindstone / pagerduty-cli

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

incident:list fails to show all incidents regardless of qualifier arguments #13

Closed notjames closed 3 years ago

notjames commented 3 years ago

First off, this tool is by far the best of any PD client I've used. So kudos!

Today, I needed to grab a list of all incidents I owned since a certain date (about 7 days ago). The problem is that I get the same output regardless of the permutation of arguments and I know we had far more than a few incidents as seen below even given the arguments. I suspect there might be something wrong with how output is filtered using arguments and at the very least, something is not intuitive with respect to either PD or potentially this tool. I'm inclined to think the issue is with PD, but I'm reporting the issue just case.

I tried the following permutations:

pd incident:list -e 'jim.conner' -s 'resolved'                                                                                                                                                                                                          
pd incident:list -e 'jim.conner' -s 'resolved' -s 'closed' -s acknowledged --since '2021-09-05'                                                                                                                                                         
pd incident:list -e 'jim.conner' -s 'resolved' -s 'closed' -s acknowledged -s triggered --since '2021-09-05'                                                                                                                                            
pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open 
pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open -o json                                                                                                                                                     
pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open --since '2021-09-01'                                                                                                                                        
pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open --since '2021-09-01T00:00:00.000Z'                                                                                                                          
pd incident:list -e 'jim.conner' -s 'resolved' -s 'closed' -s acknowleged --since '2021-09-05'                                                                                                                                                          
pd incident:list -e 'jim.conner' -s 'resolved' --since '2021-09-01'                                                                                                                                                                                     
pd incident:list -e 'jim.conner' -s 'resolved' --since '2021-09-05'                                                                                                                                                                                     
pd incident:list -e 'jim.conner' -s 'resolved' --since 'last week'                                                                                                                                                                                      
pd incident:list --me -s resolved -s closed -s acknowledged -s triggered -s open        <<== --me does not work                                                                                                                                                                
pd incident:list -m -s resolved -s closed -s acknowledged -s triggered -s open            <<== --me does not work                                                                                                                   
pd incident:list -n -s resolved -s closed -s acknowledged -s triggered -s open

I'll file a separate issue for --me

All of these fetched the exact same acknowledged alerts. Over the period requested (since Sept 1, 2021), we had over 1000 entries but with the qualifying arguments, I could never get what I expected. Here's some output: (note that for these I was using 0.0.71 but updated and verified the issue persists in the latest version)

✦ at 09:28:28 ❯ pd incident:list -e 'jim.conner'
Getting incidents 1/1 👍, 0/1 👎... done
ID      #     Status       Priority Urgency Title                         Created                Service     Assigned to Teams
XXXXX7W 82715 acknowledged          low     [FIRING:6] THING1 <REDACTED>  9/9/2021, 3:40:38 PM   myservice - other staging environments Jim Conner  Test
XXXXXYV 82782 acknowledged          low     [FIRING:6] THING2 <REDACTED>  9/10/2021, 10:35:15 AM myservice - other staging environments Jim Conner  Test

✦ at 09:28:39 ❯ pd incident:list -e 'jim.conner' -s 'resolved'
Getting incidents 1/1 👍, 0/1 👎... done
 ›   Error: No incidents found

✦ at 09:28:51 ❯ pd incident:list -e 'jim.conner' -s 'resolved' --since 'last week'
Getting incidents 1/1 👍, 0/1 👎... done
 ›   Error: No incidents found

✦ at 09:29:01 ❯ pd incident:list -e 'jim.conner' -s 'resolved' --since '2021-09-05'
Getting incidents 1/1 👍, 0/1 👎... done
 ›   Error: No incidents found

✦ at 09:29:44 ❯ pd incident:list -e 'jim.conner' -s 'resolved' -s 'closed' -s acknowledged --since '2021-09-05'
Getting incidents 1/1 👍, 0/1 👎... done
ID      #     Status       Priority Urgency Title                         Created                Service     Assigned to Teams
XXXXX7W 82715 acknowledged          low     [FIRING:6] THING1 <REDACTED>  9/9/2021, 3:40:38 PM   myservice - other staging environments Jim Conner  Test
XXXXXYV 82782 acknowledged          low     [FIRING:6] THING2 <REDACTED>  9/10/2021, 10:35:15 AM myservice - other staging environments Jim Conner  Test

✦ at 09:30:08 ❯ pd incident:list -e 'jim.conner' -s 'resolved' -s 'closed' -s acknowledged -s triggered --since '2021-09-05'
Getting incidents 1/1 👍, 0/1 👎... done
ID      #     Status       Priority Urgency Title                         Created                Service     Assigned to Teams
XXXXX7W 82715 acknowledged          low     [FIRING:6] THING1 <REDACTED>  9/9/2021, 3:40:38 PM   myservice - other staging environments Jim Conner  Test
XXXXXYV 82782 acknowledged          low     [FIRING:6] THING2 <REDACTED>  9/10/2021, 10:35:15 AM myservice - other staging environments Jim Conner  Test

✦ at 09:30:31 ❯ pd incident:list -e 'jim.conner' -s 'resolved' --since '2021-09-01'
Getting incidents 1/1 👍, 0/1 👎... done
 ›   Error: No incidents found

✦ at 09:31:23 ❯ pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open --since '2021-09-01'
Getting incidents 1/1 👍, 0/1 👎... done
ID      #     Status       Priority Urgency Title                         Created                Service     Assigned to Teams
XXXXX7W 82715 acknowledged          low     [FIRING:6] THING1 <REDACTED>  9/9/2021, 3:40:38 PM   myservice - other staging environments Jim Conner  Test
XXXXXYV 82782 acknowledged          low     [FIRING:6] THING2 <REDACTED>  9/10/2021, 10:35:15 AM myservice - other staging environments Jim Conner  Test

✦ at 09:31:55 ❯ pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open --since '2021-09-01T00:00:00.000Z'
Getting incidents 1/1 👍, 0/1 👎... done
ID      #     Status       Priority Urgency Title                         Created                Service     Assigned to Teams
XXXXX7W 82715 acknowledged          low     [FIRING:6] THING1 <REDACTED>  9/9/2021, 3:40:38 PM   myservice - other staging environments Jim Conner  Test
XXXXXYV 82782 acknowledged          low     [FIRING:6] THING2 <REDACTED>  9/10/2021, 10:35:15 AM myservice - other staging environments Jim Conner  Test

✦ at 09:32:14 ❯ pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open
Getting incidents 1/1 👍, 0/1 👎... done
ID      #     Status       Priority Urgency Title                         Created                Service     Assigned to Teams
XXXXX7W 82715 acknowledged          low     [FIRING:6] THING1 <REDACTED>  9/9/2021, 3:40:38 PM   myservice - other staging environments Jim Conner  Test
XXXXXYV 82782 acknowledged          low     [FIRING:6] THING2 <REDACTED>  9/10/2021, 10:35:15 AM myservice - other staging environments Jim Conner  Test

✦ at 09:34:16 ❯ pd incident:list -m -s resolved -s closed -s acknowledged -s triggered -s open
    TypeError: Cannot read property 'user' of null

✦ at 09:34:21 ❯ pd incident:list --me -s resolved -s closed -s acknowledged -s triggered -s open
    TypeError: Cannot read property 'user' of null

✦ at 09:35:12 ❯ pd incident:list -e 'jim.conner' -s resolved -s closed -s acknowledged -s triggered -s open
Getting incidents 1/1 👍, 0/1 👎... done
ID      #     Status       Priority Urgency Title                         Created                Service     Assigned to Teams
XXXXX7W 82715 acknowledged          low     [FIRING:6] THING1 <REDACTED>  9/9/2021, 3:40:38 PM   myservice - other staging environments Jim Conner  Test
XXXXXYV 82782 acknowledged          low     [FIRING:6] THING2 <REDACTED>  9/10/2021, 10:35:15 AM myservice - other staging environments Jim Conner  Test

When I removed all of the qualifiers and just put the --since in there, I got more returned, but nothing that occurred before 9/11 which I know we have a plethora.

ID      #     Status       Priority Urgency Title                      Created                Service   Assigned to      Teams
PXXXX1W 82897 acknowledged          low     [FIRING:4] <REDACTED>      9/11/2021, 5:00:47 PM  OTHER -   OP NAME          TEAM1
PXXXX5B 82934 acknowledged          low     [FIRING:4] <REDACTED>      9/13/2021, 1:44:11 AM  OTHER -   OP NAME          TEAM1
PXXXXD8 82947 acknowledged          low     [FIRING:1] <REDACTED>      9/13/2021, 5:16:37 AM  OTHER -   OP NAME          TEAM1
PXXXX07 82948 acknowledged          low     [FIRING:1] <REDACTED>      9/13/2021, 5:27:37 AM  OTHER -   OP NAME          TEAM1
PXXXXE8 82953 acknowledged          low     Alert                      9/13/2021, 7:08:38 AM  THING-Clo OP NAME          TEAM1
PXXXX2Q 83007 triggered             low     [FIRING:1] <REDACTED>      9/13/2021, 12:54:38 PM OTHER - p OP NAME          TEAM1
PXXXX06 83014 triggered             low     [FIRING:2] <REDACTED>      9/13/2021, 1:28:30 PM  QA Servi  OP NAME          TEAM2
PXXXX4C 83016 triggered             low     [FIRING:6] <REDACTED>      9/13/2021, 1:37:17 PM  OTHER -   OP NAME          Test
martindstone commented 3 years ago

Hi @notjames , thanks for reporting this. I think there may be a bug in PD CLI in here somewhere, but one thing that I should make more clear about the way that PD works is that incidents that are not open are not considered to have any assignees, which means that neither --me nor -e will ever show any resolved incidents -- so -s closed --me and -s closed -e someone will always return an empty list. This is perhaps not intuitive given the context within which the CLI is exposing this functionality, so I will definitely change the doc, online help and flags validation to reflect this fact.

One potential issue is that when specifying only --since or only --until will cause the CLI to rely on whatever default until or since the API assigns, which ya know what I am not sure what that is in all cases. I can either make it require that both be specified, or I can try to assign some sensible defaults. But I am leaning toward making it so that if one is specified the other must also be specified, just to avoid confusion.

Apart from these items, what else are you seeing that is incorrect or inconsistent?

Thank you!!

georgettica commented 3 years ago

I can concur that adding --since or --until without the other returns no results to me as well, so the sensible default returned be the PD api is non-existent.

notjames commented 3 years ago

I'll do some testing without the -e and with --since and --until to see if I get expected results. I'll let you know what my results are.

notjames commented 3 years ago

OK, I've confirmed that using -e definitely causes the empty-set problems for me. As for --since without --until, I don't think it's necessary to require both, but it would be nice that whatever the API asserts in the absence of one or the other is at least documented. It seems to me that the time frame asserted is from 0000 HRS Zulu, though I could be wrong on the TZ.

martindstone commented 3 years ago

OK so I should definitely document this or give some online help for this, but the way PD works is that an incident that is in a resolved state doesn't have anyone currently assigned -- and --me and -e search incidents currently assigned to a user. So anything with only -s closed or -s resolved plus -e or -m will always return empty. This should probably be handled by flags validation, where if the user is asking for 'resolved incidents assigned to some user' then we already know we are not going to get anything.

Is the goal to get incidents that were once assigned to a user, or incidents that were first assigned to a user? If so, that is a little bit tricky in PD, because the incident itself doesn't have that information after it's resolved. You have to get the incident log entries and look for assign_log_entry with the User ID you are looking for... You could get close by doing something like this:

USER_ID=$(pd user:list -E martin@pagerduty.com -p)
pd incident:list --since 1/1/2021 --until 1/2/2021 -s closed -p | pd incident:log -p -k 'assignees[*].id' --filter 'log entry type=assign' | grep $USER_ID

Another alternative is to write a small Python script that calls pd user:list, pd incident:list, etc. with -j and does the correlation that you want directly...

martindstone commented 3 years ago

So in 0.0.72, I added an explicit message letting you know when the combination of -s and -e/-m makes it so that you will never get anything back...

martindstone commented 3 years ago

Hi @notjames , I am going to close this now as it looks like there's nothing more that we can do currently. Let me know if there's anything else...