|
| 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/). |
0 commit comments