Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
122 additions
and
1 deletion.
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
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
Empty file.
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 @@ | ||
from .core import init, run |
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,51 @@ | ||
from argparse import ArgumentParser | ||
from typing import List | ||
|
||
from chroma_feedback import helper, request | ||
from chroma_feedback.typing import Producer | ||
from .normalize import normalize_data | ||
|
||
ARGS = None | ||
|
||
|
||
def init(program : ArgumentParser) -> None: | ||
global ARGS | ||
|
||
if not ARGS: | ||
program.add_argument('--uptimerobot-host', default = 'https://api.uptimerobot.com') | ||
program.add_argument('--uptimerobot-slug', action = 'append') | ||
program.add_argument('--uptimerobot-token', required = True) | ||
ARGS = helper.get_first(program.parse_known_args()) | ||
|
||
|
||
def run() -> List[Producer]: | ||
result = [] | ||
|
||
if ARGS.uptimerobot_slug: | ||
for slug in ARGS.uptimerobot_slug: | ||
result.extend(fetch(ARGS.uptimerobot_host, slug, ARGS.uptimerobot_token)) | ||
else: | ||
result.extend(fetch(ARGS.uptimerobot_host, None, ARGS.uptimerobot_token)) | ||
return result | ||
|
||
|
||
def fetch(host : str, slug : str, token : str) -> List[Producer]: | ||
result = [] | ||
response = None | ||
|
||
if host and slug and token: | ||
response = request.post(host + '/v2/getMonitors?api_key=' + token, | ||
{ | ||
'search': slug | ||
}) | ||
elif host and token: | ||
response = request.post(host + '/v2/getMonitors?api_key=' + token) | ||
|
||
if response and response.status_code == 200: | ||
data = request.parse_json(response) | ||
|
||
if 'monitors' in data: | ||
for monitor in data['monitors']: | ||
if 'friendly_name' in monitor and 'url' in monitor and 'status' in monitor: | ||
result.append(normalize_data(monitor['friendly_name'], monitor['url'], monitor['status'])) | ||
return result |
22 changes: 22 additions & 0 deletions
22
chroma_feedback/producer/uptimerobot/uptimerobot/normalize.py
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,22 @@ | ||
from chroma_feedback import helper | ||
from chroma_feedback.typing import Producer, Status | ||
|
||
|
||
def normalize_data(slug : str, url : str, status : int) -> Producer: | ||
return\ | ||
{ | ||
'name': 'uptimerobot', | ||
'slug': slug, | ||
'url': url, | ||
'status': normalize_status(status) | ||
} | ||
|
||
|
||
def normalize_status(status : int) -> Status: | ||
if status == 0: | ||
return 'skipped' | ||
if status == 1: | ||
return 'started' | ||
if status == 9: | ||
return 'failed' | ||
return 'passed' |
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
'microsoft.github', | ||
'netlify', | ||
'travis', | ||
'uptimerobot' | ||
'vercel' | ||
] | ||
ConsumerName = Literal\ | ||
|
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
Empty file.
Empty file.
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,42 @@ | ||
import pytest | ||
import os | ||
import argparse | ||
from typing import get_args | ||
|
||
from chroma_feedback.producer.uptimerobot import uptimerobot | ||
from chroma_feedback.typing import Status | ||
|
||
|
||
def test_run_one() -> None: | ||
if os.environ.get('UPTIMEROBOT_TOKEN'): | ||
uptimerobot.core.ARGS = argparse.Namespace( | ||
uptimerobot_host = 'https://api.uptimerobot.com', | ||
uptimerobot_slug = | ||
[ | ||
'chrome-feedback-test' | ||
], | ||
uptimerobot_token = os.environ.get('UPTIMEROBOT_TOKEN') | ||
) | ||
result = uptimerobot.core.run() | ||
|
||
assert result[0]['name'] == 'uptimerobot' | ||
assert result[0]['slug'] == 'chrome-feedback-test' | ||
assert result[0]['status'] in get_args(Status) | ||
else: | ||
pytest.skip('UPTIMEROBOT_TOKEN is not defined') | ||
|
||
|
||
def test_run_many() -> None: | ||
if os.environ.get('UPTIMEROBOT_TOKEN'): | ||
uptimerobot.core.ARGS = argparse.Namespace( | ||
uptimerobot_host = 'https://api.uptimerobot.com', | ||
uptimerobot_slug = None, | ||
uptimerobot_token = os.environ.get('UPTIMEROBOT_TOKEN') | ||
) | ||
result = uptimerobot.core.run() | ||
|
||
assert result[0]['name'] == 'uptimerobot' | ||
assert result[0]['slug'] | ||
assert result[0]['status'] in get_args(Status) | ||
else: | ||
pytest.skip('UPTIMEROBOT_TOKEN is not defined') |