datahubio / datahub-v2-pm

Project management (issues only)
8 stars 2 forks source link

Checkout statuspage.io #287

Closed zelima closed 5 years ago

zelima commented 5 years ago

As PM I want to test how statuspage.io works and fits us so that I can compare with others and make a decision

Acceptance Criteria

Tasks

Analysis

I like their API more than startus.io. Simple and straightforward, though their documentation seems wrong or smth. Eg getting "error": "Parameter subscriber is required" when trying to create subscriber

import requests
import json

from .config import statuspage_org_id, statuspage_page_id, statuspage_api_key

statuspage_headers={'Authorization': 'OAuth %s' % statuspage_api_key}

def on_incident(incident, publisher, errors=''):
    component_id = _get_component_id(publisher)
    if component_id is None:
        return
    payload = {
      "incident": {
        "name": incident,
        "body": errors,
        "status": "identified",
        "component_ids": [
          component_id
        ]
      }
    }
    result = requests.post(
        'https://api.statuspage.io/v1/pages/{page_id}/incidents'.format(page_id=statuspage_page_id),
        headers=statuspage_headers,
        data=json.dumps(payload)
    )
    return json.dumps(result.json(), indent=2)

def subscribe_user(user_info={}):
    component_id = _get_component_id(user_info.get('username'))
    if component_id is None:
        return
    payload = json.dumps({
      "email": user_info.get('email'),
      "component_ids": [
        component_id
      ]
    })
    result = requests.post(
        'https://api.statuspage.io/v1/pages/{page_id}/subscribers'.format(page_id=statuspage_page_id),
        headers=statuspage_headers,
        data=payload
    )
    return json.dumps(result.json(), indent=2)

def _get_component_id(component_name):
    components = requests.get(
        'https://api.statuspage.io/v1/pages/{page_id}/components'.format(page_id=statuspage_page_id),
        headers=statuspage_headers
    ).json()
    component_id = None
    for component in components:
        if component.get('name') == component_name:
            component_id = component.get('id')
    return component_id
zelima commented 5 years ago

FIXED