Skip to content

Instantly share code, notes, and snippets.

@zph
Last active July 3, 2023 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zph/790e9259a9afa4ab7741a493994d8fa8 to your computer and use it in GitHub Desktop.
Save zph/790e9259a9afa4ab7741a493994d8fa8 to your computer and use it in GitHub Desktop.
Deno wrapper for pagerduty-cli
#!/usr/bin/env -S deno run --allow-all
// Relies on pd binary which is auto installed with npx https://github.com/martindstone/pagerduty-cli/blob/master/docs/incident.md#pd-incident-create
// for globals and happy editor
import "https://deno.land/x/violet@0.1.0/globals.d.ts";
// For shell like syntax without needing vl shebang
import "https://deno.land/x/violet@0.1.0/globals.ts";
import "https://deno.land/std/log/mod.ts"
import * as log from "https://deno.land/std/log/mod.ts";
import { Checkbox } from "https://deno.land/x/cliffy@v0.25.7/prompt/checkbox.ts";
import { Input } from "https://deno.land/x/cliffy@v0.25.7/prompt/input.ts";
// Ensure dependencies
const PD = ["echo", "npx", "pagerduty-cli"]
await $`${PD} version`
// TODO: authenticate selectively if auth isn't setup
await $`${PD} auth web --default`
interface Teammate {
name: string;
value: string;
}
const teammates: Teammate[] = [
{ name: "Jay", value: "jay@example.com" },
{ name: "Jane", value: "jane@example.com" },
{ name: "Joe", value: "joe@example.com" },
{ name: "Jolene", value: "jolene@example.com" },
{ name: "Jana", value: "jana@example.com" },
]
const people: string[] = await Checkbox.prompt({
message: "Pick teammate(s) to page for help",
info: true,
options: teammates,
});
const title: string = await Input.prompt({
message: "What's the incident title? (choose one or type custom)",
list: true,
info: true,
suggestions: [
"URGENT: Help resolve SEV0",
"URGENT: Help resolve SEV1",
"URGENT: Companywide outage",
"Join to stop SEV2 from escalating",
]
,
});
const details: string = await Input.prompt({
message: "What's the incident details? (choose one or type custom and include google meet link or Slack channel)",
list: true,
info: true,
suggestions: [
"Join me in #storage-operations",
"Ping me on Slack",
]
,
});
log.info(`Creating incident and paging first person ${people[0]}`)
// TODO: remove echos used for testing
const response = await $`echo ${PD} incident create --user=${people[0]} --priority=high --title=${title} --details=${details}`
// TODO: enable once out of testing mode
//const r = JSON.parse(response.stdout)
//const { incident_id } = r;
const incident_id = 1
if(people.length > 1) {
const restOfPeople = people.slice(1).map(p => `--user_emails=${p}`).join(" ")
await $`echo ${PD} incident responder add --ids ${incident_id} ${restOfPeople}`
}
log.info(`Help is on the way from ${people}. Try to mitigate or rally others to help in meantime!`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment