Package: pdh
PDH - PagerDuty CLI for humansPDHis a new lightweight CLI for pagerduty interaction: uou can handle your incidents triage without leaving your terminal.
It also add some nice tricks to automate the incident triage and easy the on-call burden.Seedocs(TBD)InstallWith dockerdockerrun-ti-v~/.config/pdh.yaml:/root/.config/pdh.yaml--rmpdh:0.3.10inclsWith pippipinstallpdh>=0.3.10From sourcegitclonehttps://github.com/mbovo/pdhcdpdh
tasksetupsource.venv/bin/activate
pdhinclsUsageFirst of all you need to configurepdhto talk with PagerDuty's APIs:pdhconfigThe wizard will prompt you for 3 settings:apikeyis the API key, you can generate it from the user's profile page on pagerduty websiteemailthe email address of your pagerduty profileuidthe userID of your account (you can read it from the browser address bar when clicking on "My Profile")Settings are persisted to~/.config/pdh.yamlin clear.Listing incidentsAssigned to self:pdhinclsAny other incident currently outstanding:pdhincls-eAuto ACK incoming incidentsWatch for new incidents every 10s and automatically set them toAcknowledgedpdhincls--watch--new--ack--timeout10List all HIGH priority incidents periodicallyList incidents asssigned to all users every 5spdhincls--high--everything--watch--timeout5Resolve specific incidentspdhincresolveINCID0001INCID0024INCID0023Resolve all incidents related toBackupspdhincls--resolve--regexp".*Backup.*"RulesPDHsupport custom scripting applied to your incidents list. Theserulesare in fact any type of executable you can run on your machine.pdhincapplyINCID001-s/path/to/my/script.py-s/path/to/binaryTheapplysubcommand will call the listed executable/script passing along a json to stdin with the incident informations. The called script can apply any type of checks/sideffects and output another json to stout to answer the call.Even though rules can be written in any language it's very straightforward using python:Rules: an exampleAn example rule can be written in python with the following lines#!/usr/bin/env python3frompdhimportrules,Filter@rules.ruledefmain(input):return{i["id"]:i["summary"]foriininput}if__name__=="__main__":main()This is the simplest rule you can write, reading the input and simply output a new dictionary with the entries. It will output something like:pdhincapplyQ1LNI5LNM7RZ2CQ1C5KG41H0SZAM-s./a.py
┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃script┃Q1LNI5LNM7RZ2C┃Q1C5KG41H0SZAM┃
┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│./a.py│AWSHealthEvent:us-east-1EC2:AWS_EC2_INSTANCE_STOP_SCHEDULED│AWSHealthEvent:us-east-1EC2:AWS_EC2_INSTANCE_STORE_DRIVE_PERFORMANCE_DEGRADED│
└────────┴────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────┘The default output istablewith one line for each script runned and with one column per each element in the returned objectRules: more examples#!/usr/bin/env python3# Needed importsfrompdhimportrules,Filter# This annotation make the main() method parse stdin as json into the parameter called input# All returned values are converted to json and printed to stdout@rules.ruledefmain(input):# Initialize PagerDuty's APIsapi=rules.api()# From the given input extract only incidents with the word cassandra in titleincs=Filter.objects(input,filters=[Filter.regexp("title",".*EC2.*")])# ackwnoledge all previously filtered incidentsapi.ack(incs)# resolve all previously filtered incidentsapi.resolve(incs)# snooze all previously filtered incidents for 1hapi.snooze(incs,duration=3600)# Chain a given rule, i.e call that rule with the output of this one# chain-loading supports only a single binary, not directoriesc=rules.chain(incs,"rules/test_chaining.sh")# Execute an external program and get the output/err/return codep:rules.ShellResponse=rules.exec('kubectl get nodes -o name')ifp.rc>0:nodes=p.stdout.split("\n")# if you return a dict will be rendered with each item as a column in a table# Othrwise will be converted as stringreturn{i["id"]:i["summary"]foriinincs}if__name__=="__main__":main()RequirementsTaskfilePython >=3.10DockerContributingFirst of all you need to setup the dev environment, using Taskfile:tasksetupThis will create a python virtualenv and installpre-commitandpoetryin your system if you lack them.LicenseThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Seefor more details.