Skip to content

Commit 5b765fe

Browse files
authored
PagerDuty incidents plugin (#34)
1 parent bce1fb3 commit 5b765fe

30 files changed

+1468
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: [
7+
"plugin:react/jsx-runtime",
8+
"plugin:react-hooks/recommended",
9+
"standard-with-typescript",
10+
"prettier",
11+
],
12+
overrides: [],
13+
parserOptions: {
14+
ecmaVersion: "latest",
15+
project: "tsconfig.json",
16+
sourceType: "module",
17+
tsconfigRootDir: __dirname,
18+
},
19+
plugins: ["react"],
20+
rules: {
21+
// conflicts with no-extra-boolean-cast
22+
"@typescript-eslint/strict-boolean-expressions": "off",
23+
},
24+
settings: {
25+
react: {
26+
version: "detect",
27+
},
28+
},
29+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# OSX
2+
*.DS_Store
3+
4+
# IDEs
5+
.idea
6+
*.iml
7+
.vscode
8+
9+
# This project
10+
node_modules/
11+
dist/
12+
yarn-error.log
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# PagerDuty Incidents Cortex Plugin
2+
3+
View PagerDuty incidents associated with your services!!
4+
5+
<div align="center"><img src="img/pagerduty-incidents.png" /></div>
6+
7+
The PagerDuty Incidents plugin shows PagerDuty incidents associated with the PagerDuty service specified in the entity's `cortex.yaml`. If the `cortex.yaml` has a PagerDuty service defined in its `x-cortex-oncall` configuration, it will query for incidents in that service. For example:
8+
9+
```yaml
10+
openapi: 3.0.1
11+
info:
12+
title: funrepo
13+
description: Description of funrepo
14+
x-cortex-tag: funrepo
15+
x-cortex-type: service
16+
x-cortex-oncall:
17+
pagerduty:
18+
id: PXXXXXX
19+
type: SERVICE
20+
```
21+
22+
## Setup
23+
24+
This plugin requires a proxy to PagerDuty. To set up:
25+
26+
- In PagerDuty, create an API Token by clicking on Integrations > API Access Keys > Create New API Key
27+
- In Cortex, define a secret whose value is your new token. Name it `pagerduty_secret`.
28+
- Create a plugin proxy in Cortex:
29+
30+
- Navigate to Plugins, then click on the Proxies tab, then click on Create Proxy
31+
- Give the proxy a name, then click on Add URL
32+
- For the URL Prefix, type in `https://api.pagerduty.com`
33+
- Click on Add Header and add a header whose name is `Authorization` and whose value is `Token token={{{secrets.pagerduty_secret}}}` (include the curly braces!)
34+
35+
- Once you are done, the proxy should look like the below:
36+
37+
<div align="center"><img src="img/pagerduty-proxy.png"></div>
38+
39+
Now, you can build and add the plugin.
40+
41+
- Build the plugin:
42+
- Make sure you have npm/yarn
43+
- In your terminal, in the `pagerduty-incidents` directory, type `yarn` or `npm install` to install the dependencies
44+
- Type `npm run build` or `yarn build` to build the plugin
45+
- The compiled plugin will be created in `dist/ui.html`
46+
- In Plugins > All, click **Register Plugin**
47+
- Give the plugin a name, like PagerDuty Incidents. This is the name users will see in the plugin listing.
48+
- Under **Associated Proxy**, choose the proxy you just created.
49+
- Under **Plugin Context**, click on Add another context; choose Selection type: Include, and Entity types: service.
50+
- This plugin does not work in the Global context. Turn off the switch labeled **Include in global context**
51+
- In The **Plugin code** section, upload the `dist/ui.html` file you just built.
52+
- Click on **Save plugin**
53+
54+
Now, when you navigate to a Cortex entity that has a PagerDuty oncall associated with it, you should be able to click on Plugins > PagerDuty Incidents and see the PagerDuty incidents associated with the service that is linked to the entity.
55+
56+
If no PagerDuty oncall is set for the entity, you will see a service chooser that allows you to map the entity to a PagerDuty service.
57+
58+
<div align="center"><img src="img/pagerduty-chooser.png"></div>
59+
60+
If you don't want to see the PagerDuty plugin at all on entities that don't have a PagerDuty oncall, then you can adjust the plugin visibility via CQL to only show in entities where `x-cortex-oncall.pagerduty.type = SERVICE`.
61+
62+
# Setting up your dev environment
63+
64+
PagerDuty Incidents Plugin is a [Cortex](https://www.cortex.io/) plugin. To see how to run the plugin inside of Cortex, see [our docs](https://docs.cortex.io/docs/plugins).
65+
66+
### Prerequisites
67+
68+
Developing and building this plugin requires either [yarn](https://classic.yarnpkg.com/lang/en/docs/install/) or [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
69+
70+
## Getting started
71+
72+
1. Run `yarn` or `npm install` to download all dependencies
73+
2. Run `yarn build` or `npm run build` to compile the plugin code into `./dist/ui.html`
74+
3. Upload `ui.html` into Cortex on a create or edit plugin page
75+
4. Add or update the code and repeat steps 2-3 as necessary
76+
77+
### Notable scripts
78+
79+
The following commands come pre-configured in this repository. You can see all available commands in the `scripts` section of [package.json](./package.json). They can be run with npm via `npm run {script_name}` or with yarn via `yarn {script_name}`, depending on your package manager preference. For instance, the `build` command can be run with `npm run build` or `yarn build`.
80+
81+
- `build` - compiles the plugin. The compiled code root is `./src/index.tsx` (or as defined by [webpack.config.js](webpack.config.js)) and the output is generated into `dist/ui.html`.
82+
- `test` - runs all tests defined in the repository using [jest](https://jestjs.io/)
83+
- `lint` - runs lint and format checking on the repository using [prettier](https://prettier.io/) and [eslint](https://eslint.org/)
84+
- `lintfix` - runs eslint in fix mode to fix any linting errors that can be fixed automatically
85+
- `formatfix` - runs Prettier in fix mode to fix any formatting errors that can be fixed automatically
86+
87+
### Available React components
88+
89+
See available UI components via our [Storybook](https://cortexapps.github.io/plugin-core/).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "test-file-stub";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
plugins: ["@babel/plugin-syntax-jsx"],
3+
presets: [
4+
["@babel/preset-env", { targets: { node: "current" } }],
5+
"@babel/preset-typescript",
6+
["@babel/preset-react", { runtime: "automatic" }],
7+
],
8+
};
57.5 KB
Loading
149 KB
Loading

0 commit comments

Comments
 (0)