Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fealone committed Sep 6, 2020
1 parent 2cbe11a commit 2d32902
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

node_modules
#!include:.gitignore
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# sentry-alert-to-slack-with-functions
# sentry-alert-to-slack-with-functions

## Deploy

```shell
poetry export -f requirements.txt > requirements.txt
gcloud functions deploy sentry-alert-to-slack-with-functions --runtime python37 --trigger-http --entry-point entry_point --region {region} --set-env-vars SLACK_ENDPOINT={SLACK_WEBHOOK_ENDPOINT}
```

## Example alert

```
An error occurred, for details from the issue below url.
https://sentry.io/organizations/{project_name}/issues/{id}/?referrer=webhooks_plugin
```
29 changes: 29 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json
import os
from typing import Any, Dict

from agraffe import Agraffe

from fastapi import FastAPI, Request

import requests

app = FastAPI()


@app.post("/sentry")
async def printf(request: Request) -> Dict[str, str]:
body = await request.json()
payload = {"text": (f"An error occurred, for details from the issue below url."
f"\r\n{body['url']}")}
res = requests.post(os.environ["SLACK_ENDPOINT"],
data=json.dumps(payload),
headers={"Content-Type": "application/json"})
if res.status_code != 200:
raise Exception(f"Error request to slack. [{res.status_code}]")
return {}


def entry_point(request: Any) -> Agraffe:
agraffe = Agraffe(app)
return agraffe(request)
181 changes: 181 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "sentry-alert-to-slack-with-functions"
version = "0.1.0"
description = ""
authors = ["fealone <fealone@lonesec.com>"]

[tool.poetry.dependencies]
python = "^3.7"
fastapi = "^0.61.1"
agraffe = "^0.1.0"
requests = "^2.24.0"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

0 comments on commit 2d32902

Please sign in to comment.