Giter VIP home page Giter VIP logo

pagerduty-cli's Introduction

pagerduty-cli

PagerDuty Command Line Interface

oclif Version Downloads/week License

Usage

See the User Guide!

Command Topics

pagerduty-cli's People

Contributors

alexjurkiewicz avatar codecorbin avatar facundofc avatar jedelson-pagerduty avatar klcodanr avatar martindstone avatar pdt-ayidi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pagerduty-cli's Issues

--me flag not working

Hello there! I've noticed that the --me option to the incident:list doesn't work, giving me the following error:

Error: Request to /users/me failed: Legacy API tokens aren't supported for this operation

I tried with rest:get --endpoint users/me, and it works perfectly returning my own user.

I've poken trough the code and I see there's a function isBearerToken() which checks if the token is 64 characters long. Mine is 20, which according to the code it renders it a legacy token.

What's the reason for the need of the isBearerToken()? As far as PD goes, it does seem an artificial enforcement, given that the API endpoint actually works. I tried digging into the code history but that function was introduced in the initial commit.

I'd be willing to push an MR with the changes necessary, but I wanted first to double check this.

Cheers!

Unable to update pagerduty-cli

I have attempted to update pagerduty-cli a few times, and always end up with the following:
16:07:[email protected] ttys002
Wed Nov 03 ~ >$
pd update
pagerduty-cli: Updating CLI... not updatable
16:07:[email protected] ttys002
Wed Nov 03 ~ >$
sudo pd update
Password:
pagerduty-cli: Updating CLI... not updatable`
I have attempted to do this both with and without sudo access.

I have installed via npm and currently have 0.0.74 installed:
pd -v
› Warning: pagerduty-cli update available from 0.0.74 to 0.0.77.
pagerduty-cli/0.0.74 darwin-x64 node-v16.11.1

Now after I remove, then reinstall pagerduty-cli via npm, pd update still returns "not updateable", but I would expect that unless there was a newer package available.

Missing oclif dependency after v0.1.6

I recently tried to upgrade from v0.1.5 to v0.1.15, however building failed with:

yarn run v1.22.19
$ rm -rf lib && tsc -b && oclif manifest && oclif readme --multi
/bin/sh: oclif: not found
error Command failed with exit code 127.

Manually bisecting, I found that this started breaking after commit 7c4aac3, specifically the removal of @oclif/dev-cli from devDependencies.

Disclaimer: I don't know the first thing about javascript development or packaging.

But what worked for me was to add oclif (the replacement since @oclif/dev-cli has been deprecated) into devDependencies:

diff --git a/package.json b/package.json
index 63d40c4..913f542 100644
--- a/package.json
+++ b/package.json
@@ -30,6 +30,7 @@
     "tslib": "^2.4.0"
   },
   "devDependencies": {
+    "oclif": "^3",
     "@oclif/test": "^2.1.0",
     "@types/chai": "^4",
     "@types/fs-extra": "^9.0.1",

Start web server for auth on another port if 8000 is in use

I often have a local server running on port 8000, which prevents me from using the web auth for the CLI until I stop the server. Please check that port 8000 is not in use before starting the server, and if it is, choose another port instead. Alternatively, you may want to just choose a different port instead of 8000 to use, maybe a random 5 digit port. Even if it's hardcoded, that would be much less likely to cause issues than a frequently used port like 8000.

feat(service-directory): make `service` queries faster

in the UI, when searching for

https://${BASEURL}/service-directory?direction=desc&query=${SERVICENAME}&sort_by=score&team_ids=all

a result comes back fairly quickly

in contrast to

pd service:list --filter "name=${SERVICENAME}"

can the API for service-directory be added to the core api?

fix(incident:open): when no xdg-open exists, show the url

I am using pdcli in a container the doesn't have xdg-open

I would like it to fail on "cannot access url " so I can copy it from there and continue but I get (also with --debug)

(node:1518) UnhandledPromiseRejectionWarning: Error: spawn xdg-open ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1518) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1518) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:1518) UnhandledPromiseRejectionWarning: Error: spawn xdg-open ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
(node:1518) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

pd service enable/disable commands do not respect -b, --useauth?

When default auth token is one account but using -b or --useauth to use another account, service enable/disable commands will result in 404 as they are looking in the default account rather than the alias specified in -b or --useauth.

$ pd update                                                                                                                                                                                                                             
pagerduty-cli: Updating CLI... already on latest version: 0.0.79

$ # Default account selected and `-b` used to switch commands to another account
$ pd auth:list                                                                                                                                                                                                                                   
 Default Alias       Subdomain   Email Type
 ─────── ─────────── ─────────── ───── ───────────────
         accountB  accountB       Legacy (Global)
   ✅    primaryAccount   primaryAccount         Legacy (Global)
         accountA        accountA              Legacy (Global)
$ # Disable using -b for accountA alias
$ pd service:list -p -b accountA | pd service:disable -p -b accountA                                                                                                                                                                                      
Getting services from PD 1/1 👍, 0/1 👎... done
404 Not Found: Not Found  ×9
Setting status = 'disabled' on 9 services 0/9 👍, 9/9 👎... done
Failed to set service PSERVICEID1: 404 Not Found: Not Found
Failed to set service PSERVICEID2: 404 Not Found: Not Found
Failed to set service PSERVICEID3: 404 Not Found: Not Found
Failed to set service PSERVICEID4: 404 Not Found: Not Found
Failed to set service PSERVICEID5: 404 Not Found: Not Found
Failed to set service PSERVICEID6: 404 Not Found: Not Found
Failed to set service PSERVICEID7: 404 Not Found: Not Found
Failed to set service PSERVICEID8: 404 Not Found: Not Found
Failed to set service PSERVICEID9: 404 Not Found: Not Found

$ # Use accountA as the default auth token and it just works
$ pd auth:use -a accountA
$ pd service:list -p | pd service:disable -p                                                                                                                                                                                                      
Getting services from PD 1/1 👍, 0/1 👎... done
Setting status = 'disabled' on 9 services 9/9 👍, 0/9 👎... done

$ # Without switching default from accountA enable then disable a single service on "primaryAccount"
$ pd service:list -b primaryAccount
Getting services from PD 1/1 👍, 0/1 👎... done
 ID      Status   Name                        Escalation policy name             Team names
 ─────── ──────── ─────────────────────────── ────────────────────────────────── ────────────
 SOMEPDSERVICEID disabled ServiceOnPrimaryAccountAsExpected    Test App Default Escalation Policy
$ # Enable using -b for primaryAccount alias
$ pd service:enable -b primaryAccount --ids SOMEPDSERVICEID   
404 Not Found: Not Found
Setting status = 'active' on 1 services 0/1 👍, 1/1 👎... done
Failed to set service SOMEPDSERVICEID: 404 Not Found: Not Found
$ # Switch back to "primaryAccount" as default  and it just works                
$  pd service:enable -b primaryAccount --ids SOMEPDSERVICEID                                                                                                                                                                                                    
Setting status = 'active' on 1 services 1/1 👍, 0/1 👎... done  

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

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

paused_incident_reports/counts

Not able to query the paused_incident_reports. Looks like the query succeeds.

 % pd --version
      pagerduty-cli/0.1.6 darwin-x64 node-v16.15.0
 %  pd rest:fetch -e=paused_incident_reports/counts \
      -P "service_id=XXXXXXX"  -k paused_count -t     
        
Fetching 1/1 👍, 0/1 👎... done
    TypeError: Cannot read properties of undefined (reading 'map')

Output with debug

 %  pd rest:fetch -e=paused_incident_reports/counts \
   -P "service_id=XXXXXX"  -k paused_count -t --debug
[DEBUG] Request: {
... 
[DEBUG] OK Response:
[DEBUG] Response Status: 200
[DEBUG] Response Data: {
 paused_incident_reporting_counts: {
   paused_count: 13,
   resolved_after_pause_count: 11,
   since: '2022-05-11T05:52:36.567964Z',
   triggered_after_pause_count: 2,
   until: '2022-11-09T20:47:12.567993Z'
 }
}

Improve readability and simplify the -k flag

So after learning, -k flag combined with --columns= are the two most useful tools in my arsenal.

The problem is that with --columns= I can do like:

columns=id,name,description,summary,time_zone,html_url

but with the -k flag, I need to do like:

-k description -k summary -k time_zone -k html_url

This means my final command looks like:

pd schedule:list -k description -k summary -k time_zone -k html_url --columns=id,name,description,summary,time_zone,html_url


Can we please have the same functionality so I can just write:

pd schedule:list -k description,summary,time_zone,html_url --columns=id,name,description,summary,time_zone,html_url

or even better just:

pd schedule:list -k description, summary, time_zone, html_url

or just:

pd schedule:list --columns=id,name,description,summary,time_zone,html_url

and still get the output:

ID      Name                                    description                                               summary                                 time_zone       html_url
 ─────── ─────────────────────────────────────── ───────────────────────────────────────────────────────── ─────────────────────────────────────── ─────────────── ─────────────────────────────────────────────────
 P47R7L5 1st Line 7-17                                                                                     1st Line 7-17                           Europe/Helsinki https://company.pagerduty.com/schedules/P47R7L5
 P64JBZZ 24-5                                                                                              24-5                                    Europe/Warsaw   https://company.pagerduty.com/schedules/P64JBZZ
 PDFD16Z Amazon Connect Test                     Temporary schedule for testing Amazon Connect             Amazon Connect Test                     Europe/Warsaw   https://company.pagerduty.com/schedules/PDFD16Z
 PT8KV6J AWS Support                             Default AWS Support Schedule.                             AWS Support                             Europe/Warsaw   https://company.pagerduty.com/schedules/PT8KV6J

Getting TypeError: Cannot read properties of undefined (reading 'status')

I tried running the following commands recommended by Pagerduty support and ended up getting
TypeError: Cannot read properties of undefined (reading 'status')
each time.

pd rest:fetch -e oncalls -P 'since='2022-02-13 'until='2022-05-13 -t --sort escalation_policy.summary,-escalation_level -k start -k end -k escalation_policy.summary -k escalation_policy.id -k escalation_level -k schedule.summary -k schedule.id -k user.summary --output=csv > oncallexport1.csv
Fetching 594/763 👍, 0/763 👎... !
    TypeError: Cannot read properties of undefined (reading 'status')
pd log -O --since '2022-02-13' --until='2022-03-13' -k 'type' -k 'agent.id' -k 'incident.id' --filter 'created= 0[0-5]:' --sort agent.id --output=csv > incidentactivity.csv
400 Bad Request: Offset must be less than 10001.  ×6103
Getting log entries 401/6781 👍, 6103/6781 👎... !
    TypeError: Cannot read properties of undefined (reading 'status')

schedule:render date format

Hello,

I tried to update all schedule spans over a timeslot. I used the schedule:render command to get the spans.

Example:

$> pd schedule:render -i P999999 --since=2022-01-23T10:00:00.000Z --until=2022-02-07T08:00:00.000Z --filter "User name=Doe" --output=csv                       
Getting schedule P999999... done
Start,End,Duration,User id,User name
"24/01/2022, 09:00:00","28/01/2022, 18:00:00","4d 9h  ","PWWWWWW","John Doe"
"31/01/2022, 09:00:00","04/02/2022, 18:00:00","4d 9h  ","PWWWWWW","John Doe"

But as dates contain the comma character, it was a little bit hard to extract start/end values via the command line.

After removing the toLocaleString() call in schedule:render I was able to do this.

for row in `pd schedule:render -i P999999 --since=2022-01-23T10:00:00.000Z --until=2022-02-07T08:00:00.000Z --filter "User name=Doe" --output=csv --no-header`
do
start=$(echo $row | cut -f1 -d,)
end=$(echo $row | cut -f2 -d,)
pd schedule:override:add -i P999999 -u PUUUUUU --start=$start --end=$end
done

Maybe there is a better way to extract the value in bash. But I suppose you can also provide an option to avoid date formatting.

What do you think?

Regards,
Sébastien

User Session List Purpose

Hi Martin

It is more of a question: what is the meaning of the column retrieved when you run "pd user session list" for a specific email id? For instance, one of the columns is in date format and called "Created At"? The pagerduty login can last up to 90 days on your browser, then is the user session the record of the first time log in when you access pagerduty from a browser? If so, all the other logins will not be recorded, correct? Is there a function we can use to extract the last time a user has made a successful login?

Thanks a lot,
Collestech

Incident Counts differ when using limit param on the incidents endpoint

Using the limit query param with the incidents endpoint produces different results.

In hindsight ... I realized pd handles pagination and the limit param is not necessary - but was surprised by the results

start_date=`date +"%Y-%m-%dT%H:%M:%SZ" -d "2022-11-13"`
end_date=`date +"%Y-%m-%dT%H:%M:%SZ" -d "2022-11-14"`

incidents=$(pd rest:fetch -e incidents \
   -k alert_counts.all \
   -k service.summary \
   -P "since=$start_date" \
    -P "until=$end_date" \
    -t \
    --output=csv \
    --no-header 2> /dev/null | wc -l)

incidents_with_limit=$(pd rest:fetch -e incidents \
    -k alert_counts.all \
    -k service.summary \
    -P "since=$start_date" \
    -P "until=$end_date" \
    -P "limit=10000" \
    -t \
    --output=csv \
    --no-header 2> /dev/null | wc -l)

echo "#incidents: $incidents"
echo "#incidents_with_limit": $incidents_with_limit

output:

#incidents: 604
#incidents_with_limit: 2266

Add "team" support

Hi Martin, was working with a customer yesterday and I pointed this to them. They who would like to use "users" with "teams" to be able to join those table. I imagine it's not trivial due to the different objects but it would be great to have it as other customers would also like to be able to have a user list with the teams they belong to.

Default to current user for `pd schedule override`?

I'm wondering if it would make sense to default to your own user for scheduling overrides? That's my most common use case to schedule a short override if I'm doing some work that might trigger an alarm:

pd schedule override add --end="in 15 minutes" --id="123ABCD" -u "ABCD123"

would become:

pd schedule override add --end="in 15 minutes" --id="123ABCD"

But I could still specify it if I was to schedule an override for some other user.

How to view timezones for schedules using cli?

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?

Warning: pagerduty-cli update available from 0.1.6 to 0.1.13.

Great looking tool, thanks!

I'm getting this warning whenever I run a pd command:

Warning: pagerduty-cli update available from 0.1.6 to 0.1.13.

I just installed via the recommended method, and I've tried running pd update but am still getting this:

❯ pd update
pagerduty-cli: Updating CLI from 0.1.6 to 0.1.6-996afd9... done

Any suggestions?

add a `--max-responses` global field

sometimes, our service is a bit bogged with details and I just need the header / the first few items.

 pd incident:list --team ${MYTEAM}
Getting incidents 1/19 👍, 0/19 👎... ⡿

could we add this

pd incident:list --team ${MYTEAM} --max-responses 20
Getting incidents 0/1 👍, 0/1 👎... ⡿

New lines in incident details when creating a new incident

New lines using \n don't seem to be accepted when creating a new incident. However, it works when using the CURL command. Is this the expected outcome? Or should new lines work within pagerduty-cli?

pd incident:create -t "test incident" -u low --service_id=P53ZZH5 -U "[email protected]" -d "A disk is getting full on this machine.\nYou should investigate what is causing the disk to fill, and ensure that there is an automated process in place for ensuring data is rotated (eg. logs should have logrotate around them). If data is expected to stay on this disk forever, you should start planning to scale up to a larger disk."

I was successfully able to create new lines in the incident details when using the CURL command:

curl --request POST   --url https://api.pagerduty.com/incidents   --header 'Accept: application/vnd.pagerduty+json;version=2'   --header 'Authorization: Token token=<TOKEN_REDACTED>'   --header 'Content-Type: application/json'   --header 'From: [email protected]'   --data '{
  "incident": {
    "type": "incident",
    "title": "test incident.",
    "service": {
      "id": "P53ZZH5",
      "type": "service_reference"
    },
    "urgency": "low",
    "incident_key": "baf7cf21b1da41b4b0221008339ff357",
    "body": {
      "type": "incident_body",
      "details": "A disk is getting full on this machine.\nYou should investigate what is causing the disk to fill, and ensure that there is an automated process in place for ensuring data is rotated (eg. logs should have logrotate around them). If data is expected to stay on this disk forever, you should start planning to scale up to a larger disk."
    }
  }
}'

Another issue with `--me` -- failing

The following commands:

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 

errorred with the following errors:

✦ 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

For grins and giggles, I tried adding user: <user.name> in the $HOME/.pagerduty/credentials file but that didn't fix anything.

MS Defender exclusion

Hi. A recent install of the Win x64 version of this app triggered an EDR alert:

"C:\WINDOWS\system32\cmd.exe" /C powershell -ExecutionPolicy Bypass -Command "& {Add-MpPreference -ExclusionPath "C:\Users\USER\AppData\Local\pagerduty-cli"}" -FFFeatureOff

It appears to be trying to exclude itself from MS Defender. Why is that?

Support filtering users by contact country

Problem Statement

Due to variability in SMS deliverability across countries, admins may want to be able to audit contact methods across the user base of their accounts filtering by country.

Proposed Solution

Add a new flag to pd user list which filters to only include users in a given country, identified by its ISO country code. This flag should support multiple values.

E.g.

pd user list --contact_country_code CA -- lists users with a Canadian phone number in either phone or SMS contacts.

Alternatives Considered

Once #57 is fixed, something similar is possible using the --filter flag, e.g. pd user list --filter "Contact sms=\\+351 "

This, however, is less-than-ideal since this doesn't enable differentiation between countries that share a country code, most significantly +1 is ambiguous, and because the filter flag looks for a regex, + has to be escaped.

API token not being accepted

Using PagerDuty-cli I am unable to run any successful commands after authentication.
Here you can see where I DID authenticate:
bash-5.0$ pd login Checking token 63cfdeaf27dba22df31fb3aeea4abcba6ce81ceac51d2f51d22154b9996ca5e4... done Domain added - you are logged in to ecws as [email protected]
Next, when trying any pd command, I get the following error:
bash-5.0$ pd incident:list › Error: No PagerDuty authentication was found › Try this: › * pd auth:set › * pd login

I am using the latest version of pager duty-cli:
bash-5.0$ pd -v pagerduty-cli/0.0.74 linux-x64 node-v16.12.0
My current version of nodes and NPM
bash-5.0$ node -v v16.12.0 bash-5.0$ npm -v 8.1.0
My OS:
NAME=Fedora VERSION="33 (Server Edition)" ID=fedora VERSION_ID=33 VERSION_CODENAME="" PLATFORM_ID="platform:f33"
Linux msi-vm 5.14.13-100.fc33.x86_64 #1 SMP Mon Oct 18 12:36:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Missing C++ Library References

Hi Martin,
Anyone would have an idea how my CLI client stopped working, showing the error below, for any command I try to run?

/home//.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node: /lib64/libm.so.6: version GLIBC_2.27' not found (required by /home/<my-user>/.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node) /home/<my-user>/.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node: /lib64/libc.so.6: version GLIBC_2.25' not found (required by /home//.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node)
/home//.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node: /lib64/libc.so.6: version GLIBC_2.28' not found (required by /home/<my-user>/.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node) /home/<my-user>/.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node: /lib64/libstdc++.so.6: version CXXABI_1.3.9' not found (required by /home//.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node)
/home//.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node: /lib64/libstdc++.so.6: version GLIBCXX_3.4.20' not found (required by /home/<my-user>/.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node) /home/<my-user>/.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node: /lib64/libstdc++.so.6: version GLIBCXX_3.4.21' not found (required by /home//.local/share/pagerduty-cli/client/0.1.16-3ec92e9/bin/node)

If that makes sense, how you would fix it?

Thanks a lot

schedule:render with schedule ID and name

Hello,

I need to use schedule:render then use the result to join escalation policies, teams, or whatever.
I faced an issue because I'm not able to have the schedule ID and/or name. As far as I understand, the schedule:render command restrict data to the schedule.final_schedule.rendered_schedule_entries part.
I didn't find any way to add schedule ID and name to the ouput.

Any idea? Or is it a feature request to implement?

Example:
pd schedule render -i P999999 --since=$PD_SINCE --until=$PD_UNTIL --sort=start --output=csv --delimiter=,
Output:

Start,End,Duration,User id,User name
"27/05/2022, 00:00:00","27/05/2022, 23:59:59","23 hours","PU00000","John Doe"

Expected:

Schedule id,Schedule name,Start,End,Duration,User id,User name
"PSSSSSS",""my schedule","27/05/2022, 00:00:00","27/05/2022, 23:59:59","23 hours","PU00000","John Doe"

Regards,
Sébastien

Feature: Audit API

Audit API is required to monitor pagerduty resources.
Key area of usage is to:

  1. generate compliance reports
  2. Track when users are created/deleted.

Incident list api very slow?

This lookup consistently takes around 2 seconds which is not ideal. Would it be possible to speed that up at all?
Screenshot 2023-09-05 at 15 55 30

Add/Remove Tags from a Resource

It would be great to have the ability to remove a tag from all connected entities or add a tag to an entity. Ideally I would love to be able to pipe a list of team resource ids to set or remove a tag.

Install via Homebrew

Hi Martin,

I'm a MacOS user and find Homebrew useful to manage tools like pagerduty-cli.

It will be great to make it available via Homebrew. I don't know how it can be done, but if it can help see there.
It seems to include a way to publish new release via a Github Action.

Regards,
Sébastien

`incident:assign -u` doesn't work as expected

when looking at pd incident:assign -h you can clearly see two actions using the -u flag.

this stumped me for a while as I thought the userid I was providing was incorrect.

 -u, --assign_to_user_ids=assign_to_user_ids        User ID's to assign incidents to. Specify multiple times for multiple assignees.
  -u, --useauth=useauth                              Use the saved REST API token with this alias

maybe just remove the -u from the userauth? not sure how widely this is used

Unable to authenticate

I have tried to authenticate both ways and it is not working.
pd auth web
Waiting for browser authentication... failed!
› Error: Client request error: self signed certificate in certificate chain
› Try this:
› * Get a token from https://martindstone.github.io/PDOAuth/
› * Then run pd auth:set

pd auth add
Enter a PagerDuty API token: MY_API_TOKEN
Enter a OAuth2 Refresh token (optional):
Checking token... failed!
› Error: Token auth failed

Services:set Intelligent Alert Grouping and Auto Pause

Unable to enable Intelligent Alert Grouping using pd services:set

 % pd service:set -i=PXPW401 -k=alert_grouping_parameters -v="{ type: 'intelligent', config: {} }"        
 ›   Warning: pagerduty-cli update available from 0.1.0 to 0.1.3.
 
500 Internal Server Error
Setting alert_grouping_parameters = '{ type: 'intelligent', config: {} }' on 1 services 0/1 👍, 1/1 👎... done
Failed to set service PXPW401: 500 Internal Server Error

Consider adding support to output into newline delimted JSON

One use I am considering is loading the output of the CLI into BigQuery.

BigQuery allows for import of newline delimited JSON. It would be helpful to add an option (--json-nd).
Easier to have it built into the tool than to add on a post-processing step.

Thanks in advance for considering!

Can we add pipe ability to rest:delete?

Not able to pass a piped list of services to rest:delete. This would be very helpful in cleaning up large swaths of unused services with similar names.

tried: pd service:list --filter name={query string} -p | pd rest:delete -e /services -p

Suggested Dockerfile

Thanks for the handy tool.

Please consider shipping a Dockerfile that can be used to bundle up an unprivileged container image with this tool, so users don't have to trust the sprawl of npm dependencies with access to the rest of their user accounts.

Here's one I wrote which might be useful as a starting point or for others.

FROM node:20-alpine3.16
RUN adduser -D pd
USER pd
RUN mkdir /home/pd/pd-cli
WORKDIR /home/pd/pd-cli
RUN npm install pagerduty-cli
VOLUME /home/pd/.config/pagerduty-cli
RUN mkdir -p /home/pd/.config/pagerduty-cli && chown pd:pd /home/pd/.config/pagerduty-cli
ENTRYPOINT ["npm", "exec", "--", "pd"]

# run with e.g.
#   docker run -it --rm --mount type=volume,source=pd-cli,destination=/home/pd/.config/pagerduty-cli pd-cli
#
# you will need to use the "auth:set" command the first time, and supply an api token
# created with your PD account under My Account -> User Settings -> API Access
# see https://support.pagerduty.com/docs/api-access-keys#section-generate-a-user-token-rest-api-key

Build with docker buildx build -t pd-cli . within an empty directory containing only the Dockerfile.

I then put this wrapper script in $HOME/.local/bin/pd - you can put it anywhere convenient on your PATH:

#!/bin/bash
docker run -it --rm --mount type=volume,source=pd-cli,destination=/home/pd/.config/pagerduty-cli pd-cli "$@"

A bind-mount could be used to bind the configdir for the CLI from the user's own homedir instead of using a docker volume, but using a volume was more convenient from an unprivileged access-control point of view.

On first use, run

pd auth:set

and enter a PD API token created with your PD account under My Account -> User Settings -> API Access. Watch out, the output will be echoed to the terminal.

Subsequent runs will remember it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.