Skip to content

Commit

Permalink
Python 3.9 and ngrok update (#255)
Browse files Browse the repository at this point in the history
* Update to 3.9 container. Remove unused statuspage integration.

* Update env file and readme

* Update ngrok
  • Loading branch information
mattmachell authored Mar 14, 2024
1 parent c7b7ca8 commit 80ba2ea
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 321 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.response
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim
FROM python:3.9-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
netcat-openbsd \
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To start the application locally, copy `env.dev.example` to `.env` and configure

You will need to configure a Slack app following the instructions below, and can then start the application with `docker-compose up -d`.

Note if you are using ngrok, they have now introduced auth tokens so you'll need to add one to the `ngrok.yml` in the ngrok container
Note if you are using ngrok, they have now introduced auth tokens. You can add an NGROK_AUTHTOKEN to your local .env file and it will be passed down to the container so you don't risk commiting it.

## Versions and Releases

Expand All @@ -20,7 +20,7 @@ By default, any merge to main will be a MINOR release. You can control which ver

In order to avoid polluting our real Slack workspace, and to give you full control over permissions, you should configure your local copy of the app with [your own Slack workspace](#slack-create).

You now need to [create a Slack app](#slack-app-create) and [configure it](#slack-app-config). Note that you'll need your public ngrok URL to configure endpoints for Slack to use, which you can find by running `docker-compose logs ngrok`.
You now need to [create a Slack app](#slack-app-create) and [configure it](#slack-app-config). Note that you'll need your public ngrok URL to configure endpoints for Slack to use, which you can find by visiting the ngrok admin page which is visible on ```localhost:4040``` once you have run ```docker-compose up```.

After you've configured your app, Slack will provide you with bot OAuth token (starting `xoxb-`) and a signing secret, which should be used for the `SLACK_TOKEN` and `SLACK_SIGNING_SECRET` environment variables, respectively. You'll also need to set `SLACK_TEAM_ID` to the team ID of your Slack workspace.

Expand All @@ -36,10 +36,6 @@ GitHub signin is turned off in dev mode, but you can enable it by enabling the `

To connect to GitHub, you'll need to create a GitHub OAuth App and set the environment variables `SOCIAL_AUTH_GITHUB_KEY` and `SOCIAL_AUTH_GITHUB_SECRET` to its the app's key and secret respectively. There is already an app called "opg-response-development" which is set up in the ministryofjustice organization for local development.

#### Statuspage

As with Slack, local development shouldn't interfere with our real Statuspage so you'll need to set up your own account. You should then set `STATUSPAGEIO_API_KEY` to [your API key](#statuspage-api-key) and `STATUSPAGEIO_PAGE_ID` to your team ID.

### Environment variables

| Variable | Real value required? | Details |
Expand All @@ -54,8 +50,6 @@ As with Slack, local development shouldn't interfere with our real Statuspage so
| INCIDENT_BOT_NAME | Yes | The name of your test app |
| INCIDENT_CHANNEL_NAME | Yes | The channel to post new live incidents to |
| INCIDENT_REPORT_CHANNEL_NAME | Yes | The channel to post new incident reports to |
| STATUSPAGEIO_API_KEY | Only if testing Statuspage | Provided by Statuspage |
| STATUSPAGEIO_PAGE_ID | Only if testing Statuspage | Provided by Statuspage |
| PAGERDUTY_API_KEY | Only if testing PagerDuty | Provided by Pagerduty |
| PAGERDUTY_EMAIL | Only if testing PagerDuty | Provided by Pagerduty |
| PAGERDUTY_SERVICE | Only if testing PagerDuty | Provided by Pagerduty |
Expand All @@ -77,7 +71,3 @@ As with Slack, local development shouldn't interfere with our real Statuspage so
### slack-app-config

[https://github.com/monzo/response/blob/master/docs/slack_app_config.md](https://github.com/monzo/response/blob/master/docs/slack_app_config.md)

### statuspage-api-key

[https://support.atlassian.com/statuspage/docs/create-and-manage-api-keys/](https://support.atlassian.com/statuspage/docs/create-and-manage-api-keys/)
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ services:
- postgres_data:/var/lib/postgresql/data/

ngrok:
image: gtriggiano/ngrok-tunnel
image: ngrok/ngrok:latest
restart: unless-stopped
command:
- "http"
- "http://response:8000"
container_name: ngrok
environment:
TARGET_HOST: "response"
TARGET_PORT: 8000
env_file: .env
ports:
- "4040:4040"
depends_on:
Expand Down
3 changes: 0 additions & 3 deletions env.dev.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ INCIDENT_BOT_NAME=<SET_THIS>
INCIDENT_CHANNEL_NAME=incidents
INCIDENT_REPORT_CHANNEL_NAME=incidents

STATUSPAGEIO_API_KEY=<SET_THIS>
STATUSPAGEIO_PAGE_ID=<SET_THIS>

PAGERDUTY_API_KEY=<SET_THIS>
PAGERDUTY_EMAIL=<SET_THIS>
PAGERDUTY_SERVICE=<SET_THIS>
6 changes: 0 additions & 6 deletions opgincidentresponse/actions/keyword_handlers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from response.core.models.incident import Incident
from django.conf import settings
from response.slack.models import CommsChannel
from response.slack.decorators import keyword_handler

@keyword_handler(['status page', 'statuspage'])
def status_page_notification(comms_channel: CommsChannel, user: str, keyword: str, text: str, ts: str):
comms_channel.post_in_channel(f"ℹ️ You mentioned the Status Page - You can find our statuspage here: https://theofficeofthepublicguardian.statuspage.io/")

@keyword_handler(['runbook', 'run book'])
def runbook_notification(comms_channel: CommsChannel, user: str, keyword: str, text: str, ts: str):
comms_channel.post_in_channel(f"ℹ️ You mentioned runbooks - You can find runbooks for our services here: https://ministryofjustice.github.io/opg-technical-guidance/#opg-technical-guidance/")
179 changes: 0 additions & 179 deletions opgincidentresponse/actions/statuspage.py

This file was deleted.

100 changes: 0 additions & 100 deletions opgincidentresponse/models.py
Original file line number Diff line number Diff line change
@@ -1,106 +1,6 @@
import statuspageio

from django.conf import settings
from django.contrib import admin
from django.db import models

from response.core.models import Incident

class StatusPageError(Exception):
pass

__statuspage_client = None

def statuspage_client():
global __statuspage_client
if __statuspage_client == None:
if getattr(settings, "STATUSPAGEIO_API_KEY", None) and getattr(
settings, "STATUSPAGEIO_PAGE_ID", None
):
__statuspage_client = statuspageio.Client(
api_key=settings.STATUSPAGEIO_API_KEY,
page_id=settings.STATUSPAGEIO_PAGE_ID,
)
else:
raise ValueError(
"Statuspage client called but not configured. Check that STATUSPAGEIO_API_KEY and STATUSPAGEIO_PAGE_ID are configured in Django settings."
)
return __statuspage_client

class StatusPage(models.Model):
incident = models.ForeignKey(Incident, on_delete=models.PROTECT)
statuspage_incident_id = models.CharField(max_length=100, unique=True, null=True)

def update_statuspage(self, **kwargs):
if self.statuspage_incident_id:
statuspage_client().incidents.update(
incident_id=self.statuspage_incident_id, **kwargs
)
else:
response = statuspage_client().incidents.create(**kwargs)
self.statuspage_incident_id = response["id"]
self.save()

if 'component_ids' in kwargs and kwargs['component_ids']:
if kwargs['status'] == 'resolved':
status = 'operational'
else:
status = kwargs['component_status']

if status:
statuspage_client().components.update(
component_id=kwargs['component_ids'][0], status=status
)

def get_from_statuspage(self):
if self.statuspage_incident_id:
for incident in statuspage_client().incidents.list():
if incident["id"] == self.statuspage_incident_id:
obj = {
"name": incident["name"],
"status": incident["status"],
"message": incident["incident_updates"][0]["body"],
"impact_override": incident["impact_override"],
}

if len(incident["components"]) > 0:
obj["component_id"] = incident["components"][0]["id"]
obj["component_status"] = incident["components"][0]["status"]

return obj
raise StatusPageError(
f"Statuspage incident with id {self.statuspage_incident_id} not found"
)
return {}

@staticmethod
def get_components():
options = []

components = statuspage_client().components.list()

for component in components:
if component.group:
continue

name = component.name

if component.group_id:
group_name = [c.name for c in components if c.id == component.group_id][0]
name = f"{group_name}{name}"

options.append( (name, component.id) )

return sorted(options, key=lambda t: t[0].lower())

@admin.register(StatusPage)
class StatusPageAdmin(admin.ModelAdmin):
list_display = ("incident_summary", "statuspage_incident_id")

def incident_summary(self, obj):
return obj.incident.report


class PagerDutySpecialist(models.Model):
name = models.CharField(max_length=100, unique=True)
summary = models.TextField(max_length=1000)
Expand Down
5 changes: 0 additions & 5 deletions opgincidentresponse/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ def get_env_var(setting, warn_only=False):
INCIDENT_CHANNEL_ID = SLACK_CLIENT.get_channel_id(INCIDENT_CHANNEL_NAME)
INCIDENT_REPORT_CHANNEL_ID = SLACK_CLIENT.get_channel_id(INCIDENT_REPORT_CHANNEL_NAME)

## Statuspage

STATUSPAGEIO_API_KEY = get_env_var("STATUSPAGEIO_API_KEY")
STATUSPAGEIO_PAGE_ID = get_env_var("STATUSPAGEIO_PAGE_ID")

## PagerDuty

PAGERDUTY_API_KEY = get_env_var("PAGERDUTY_API_KEY")
Expand Down
Loading

0 comments on commit 80ba2ea

Please sign in to comment.