Introducing a new PagerDuty CLI

Hi there!

My name is Martin Stone, and I’m a PagerDuty Solution Architect. I want to share a little side project that I’ve been working on for while, because it’s starting to get pretty useful. It’s a new command line interface (CLI) for PagerDuty.

There are lots of ways to interact with PagerDuty programmatically, but I wanted to make something that was user-focused, easy to install, and easy to use for common PagerDuty tasks. Among other things, it’s good at user and admin tasks like “acknowledge and snooze all my incidents,” “put a bunch of services into maintenance mode,” “output a CSV of some or all users,” and so on. It’s super easy to install and get started.

My PagerDuty CLI is open source and it’s implemented in TypeScript using the oclif framework.

I wrote a user guide that covers installation and gives some examples; you can find that here. The source (and a complete listing of available commands) is published here.

I’m sure I don’t need to tell you that this is just third party contributed software, it’s not endorsed or supported by PagerDuty, and you’re using it at your own risk. But I’m telling you anyway because those are the facts :slight_smile:

I hope you check it out and let me know what you think - together we can make something really great!

10 Likes

This is great work, thanks for sharing!

Is this implemented in PagerDuty’s Terraform provider as the underlying client?

Hello Rishav,

This is still a side project and is not endorsed or supported by PagerDuty. So it is not implemented in PagerDuty’s Terraform provider.

I hope that helps.

Regards,

Great.

Hope it will be added to this page to help PagerDuty users to find it more easily: https://developer.pagerduty.com/docs/tools-libraries/client-libraries/

Hello Sebastien,

This is still a side project. As Martin did mention, it is just a third party contributed software and not endorsed or supported by PagerDuty. Once it goes Live, it will sure be placed in a public place for visibility.
Meanwhile, it will sit in the Community space as it is now in order to get feedback on it.

I hope that helps.

Cheers,

Hi @chiedu,

I missed your answer. But as I’m looking again at the PagerDuty CLI, I hope you (or any other Dutonian) will be able to share info for it on a visible place.
You mentioned it’s not supported by the company. Yes, as PHP API library but it’s available (and support clearly mentioned) there: https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTg2-api-client-libraries

Regards,
Sébastien

Hi @martin -

Can you please help me to get the Pagerduty CLI .PY file for below output -

List of Incident

  • Incident Number
  • Incident created date and time
  • Incident Ack by
  • Incident Ack Date and Time
  • Incident Resolve by
  • Incident Resolve Date and time
  • Incident Notes

For Specific Escalation Policy
For Specific Date or duration

Hi Vishal,

It’s a little bit more work because the incident record itself does not have information about the acknowledgers and resolvers, but here’s a Python script that does the work of stitching that information together from the incident log entries:

You would just need to make a couple of trivial changes to add incident number and filter on a specific escalation policy. Let me know if you need any additional help to do that.

Thanks!
Martin

Thanks @martin.

Currently I am using below format to run the script to get the PD report output. Below file I am using as .py but uploaded as .txt format here.

user-tags.txt (1.0 KB)

py path\File_name.py --output_file path\File_name.csv

Can you please share something similar, if possible.

Hi @vishal.garg,

I am not entirely sure what you are asking, but to get script I provided, you can:

In unix/linux/macos, you would then open a terminal in the directory where you saved the file, make the file executable with chmod +x basic_incident_details.py and then run it with some example arguments with ./basic_incident_details.py -o incidents.csv --start "30 days ago" --end now

It looks like you’re using Microsoft Windows; I am not able to advise you on how to run Python scripts on Windows in general, but I do know that it is possible. You would use the same kinds of arguments as I provided above.

Please let me know if I can help any further…

Thanks,
Martin

Thanks @martin, Appreciate your help as always. I will share the results.

Hi @martin - I have tried this but seems like results are not executing.

I am running on windows CMD -

pd auth:get
pd login

After executing below command -

C:\WINDOWS\system32>py C:\Users\gargv\Downloads\pd-cli-scripts\PD_Incidents_Notes.py --output_file C:\Users\gargv\Downloads\pd-cli-scripts\Incident_notes.csv
Getting incidents… didn’t get any

Just FYI - I can execute the below attached User Tags file.

user-tags.txt (1.0 KB)

1 Like

Hi Vishal, I tried this on my mac and it works fine. I bet it’s something to do with the python libraries for windows and was going to try on my windows VM but want to ensure I’m using the same python you are. Let me know which python version you’re using and I’ll test it out on my VM.
Also, I assume you’re using Martins latest version of pd?

Thanks @jcalcada. @vishal.garg, you can check the version of pd that you have by typing:

pd version

But also note that you did not specify a time range in your arguments to the Python script, and the script is saying that it didn’t get any incidents. The default time range for the script is the past one day. Do you have incidents in the past one day? If not, try making a longer time range by supplying the --start argument, for example --start "14 days ago"

If that doesn’t work, please let me know the version of pd you are using, and whether the following command gives you any incidents:

pd incident:list -s open -s closed --since "one day ago" --until "now"

this is the same pd command that is being used inside the Python script to get the list of incidents.

Hi @martin@jcalcada.

Thanks for your response.

I have enclosed the output of the commands that has been asked. I am able to successfully run this command.

pd incident:list -s open -s closed --since “one day ago” --until "now

Please do let me know the next step for me.

"PD incident Notes.txt (37.2 KB)

Hi Martin -
Hope you are doing good.

I have successfully run this command but not the others previously shared and output with successful output have shared in my previous notes.

pd incident:list -s open -s closed --since “one day ago” --until "now

Now Can you please share how to add below -

  • Incident Number
  • Incident created date and time
  • Incident Ack by
  • Incident Ack Date and Time
  • Incident Resolve by
  • Incident Resolve Date and time
  • Incident Notes

Hi @vishal.garg,

Apologies for the delay in responding. I believe the problem is the way that Microsoft Windows handles quotation marks at the command prompt. Could you please try this modified version of the example script:

Just save that file and run it the same way you ran basic_incident_details.py, and let me know what you observe.

Thanks!

Hi @martin - Awesome and you rocks. This time it works. attached is the output file.IncidentNOTES.xlsx (27.3 KB)

C:\WINDOWS\system32>py C:\Users\gargv\Downloads\pd-cli-scripts\Incident-Notes-New.py --output_file C:\Users\gargv\Downloads\pd-cli-scripts\IncidentNOTES.csv --start “1 day ago”

Getting incidents… got 134
Getting incident logs… got 1374 log entries
Wrote 134 incidents to C:\Users\gargv\Downloads\pd-cli-scripts\IncidentNOTES.csv.

Now Can you please do let me know if I need to export the Incidents with specific Service and customized dates, what to add in the command.

Hi @martin,

The modified version of the file has worked last time.

Now can you please share if I need to run this file for specific Escalation Policy and Customized time frame, how can I do that.

For example -
Service Name - Maintenance Alerts
Duration 1 Jan 2023 - 31 Jan 2023

Hi @martin, Good Morning.

As you have provided earlier basic_incident_details.py, this is working fine as expected but need below two parameters to be added to that any customized report can be extracted.

  • Specific to Escalation Policy
  • Customized Date/time

Appreciate your time and efforts.