generated from rochacbruno/python-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#55: Create an endpoint for grafana alerts
- Loading branch information
Showing
12 changed files
with
192 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,10 +58,11 @@ jobs: | |
env: | ||
WS_URL_ALL_USERS: ${{ secrets.WS_URL_ALL_USERS }} | ||
WS_URL_POST_COMMENT: ${{ secrets.WS_URL_POST_COMMENT }} | ||
WS_ADMIN_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_URL_POST_TASK: ${{ secrets.WS_URL_POST_TASK }} | ||
WS_ADMIN_EMAIL: ${{ secrets.WS_ADMIN_EMAIL }} | ||
WS_ADMIN_USER_ID: ${{ secrets.WS_ADMIN_USER_ID }} | ||
WS_PRJ_223728_HASH: ${{ secrets.WS_PRJ_223728_HASH }} | ||
WS_PRJ_1010_HASH: ${{ secrets.WS_PRJ_1010_HASH }} | ||
WS_PRJ_223728_POST_TASK_HASH: ${{ secrets.WS_PRJ_223728_POST_TASK_HASH }} | ||
WS_PRJ_223728_POST_COMMENT_HASH: ${{ secrets.WS_PRJ_223728_POST_COMMENT_HASH }} | ||
- name: "Upload coverage to Codecov" | ||
uses: codecov/[email protected] | ||
# with: | ||
|
@@ -85,10 +86,6 @@ jobs: | |
- name: Run tests | ||
run: make test | ||
env: | ||
WS_URL_ALL_USERS: ${{ secrets.WS_URL_ALL_USERS }} | ||
WS_URL_POST_COMMENT: ${{ secrets.WS_URL_POST_COMMENT }} | ||
WS_ADMIN_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_USER_ID: ${{ secrets.WS_ADMIN_USER_ID }} | ||
WS_INT_TESTS_DISABLED: true | ||
|
||
tests_win: | ||
|
@@ -111,10 +108,6 @@ jobs: | |
- name: run tests | ||
run: pytest -s -vvvv -l --tb=long tests | ||
env: | ||
WS_URL_ALL_USERS: ${{ secrets.WS_URL_ALL_USERS }} | ||
WS_URL_POST_COMMENT: ${{ secrets.WS_URL_POST_COMMENT }} | ||
WS_ADMIN_EMAIL: ${{ secrets.WS_EMAIL }} | ||
WS_ADMIN_USER_ID: ${{ secrets.WS_ADMIN_USER_ID }} | ||
WS_INT_TESTS_DISABLED: true | ||
|
||
docker: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ services: | |
environment: | ||
WS_URL_ALL_USERS: "https://xxx.worksection.com/xxxx" | ||
WS_URL_POST_COMMENT: "https://xxx.worksection.com/xxxx" | ||
WS_URL_POST_TASK: "https://xxx.worksection.com/xxxx" | ||
WS_ADMIN_EMAIL: "[email protected]" | ||
WS_ADMIN_USER_ID: "370080" | ||
WS_PRJ_223728_HASH: "xxx" | ||
WS_PRJ_223728_POST_TASK_HASH: "23e1sdfj2323" | ||
WS_PRJ_223728_POST_COMMENT_HASH: "2312jsafajsdf" | ||
build: | ||
dockerfile: Containerfile | ||
context: . | ||
entrypoint: g2w --log=DEBUG | ||
entrypoint: g2w | ||
ports: | ||
- "8080:8080" | ||
restart: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .push import Push | ||
from .gitlab import Push | ||
from .ws import Ws | ||
from .api import LoggableRoute | ||
from .grafana import Alert | ||
|
||
__all__ = ["Push", "Ws", "LoggableRoute"] | ||
__all__ = ["Push", "Ws", "LoggableRoute", "Alert"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import urllib.parse | ||
|
||
import airspeed | ||
from pydantic import BaseModel | ||
|
||
|
||
class Alert(BaseModel): | ||
""" | ||
Alert event details from Grafana. | ||
""" | ||
|
||
def desc(self, json) -> str: | ||
""" | ||
Allows to transform Gitlab push event about multiple commits into HTML | ||
comment for worksection. | ||
""" | ||
return self.encode( | ||
airspeed.Template( | ||
"""<pre><code class="code_init hljs json">$json | ||
</code></pre>""" | ||
).merge(locals()) | ||
) | ||
|
||
def subject(self): | ||
return self.encode("Monitoring alert") | ||
|
||
# @todo #/DEV Move encode function to generic place as it will be used for | ||
# all future Worksection requests: | ||
# https://stackoverflow.com/a/30045261/6916890 | ||
def encode(self, text: str) -> str: | ||
return urllib.parse.quote_plus(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,9 +56,11 @@ Please note, that `GitLab` commit messages must have the following format: `#WS- | |
# Mandatory environment variables (docker, podman, etc.) | ||
WS_URL_ALL_USERS: "https://xxx.worksection.com/xxxx" # https://worksection.com/faq/api-user.html#q1572 | ||
WS_URL_POST_COMMENT: "https://xxx.worksection.com/xxxx" # https://worksection.com/faq/api-comments.html#q1575 | ||
WS_URL_POST_TASK: "https://xxx.worksection.com/xxxx" # https://worksection.com/faq/api-task.html#q1577 | ||
WS_ADMIN_EMAIL: "[email protected]" # plain worksection user email | ||
WS_ADMIN_USER_ID: "370080" # plain worksection user id | ||
WS_PRJ_223728_HASH: "xxx" # HASH generated for a particular Worksection project | ||
WS_PRJ_223728_POST_TASK_HASH: "23e1sdfj2323" # HASH generated for new task action for a particular project | ||
WS_PRJ_223728_POST_COMMENT_HASH: "2312jsafajsdf" # HASH generated for new comment action for a particular project | ||
build: | ||
dockerfile: Containerfile | ||
context: . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from g2w import Alert | ||
|
||
|
||
# @todo #/DEV Create fake grafana alert event object based on | ||
# https://grafana.com/docs/grafana/latest/alerting/unified-alerting/contact-points/#webhook # noqa: E501 | ||
|
||
|
||
def test_comment(): | ||
assert Alert().desc('{"user":"Tom"}').find("user%22%3A%22Tom") > 0 |
Oops, something went wrong.
0c1ee1e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: