Skip to content

Commit 018d891

Browse files
committed
get statuspage values from env_statuspage
1 parent 7def52f commit 018d891

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

statuspage.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
from datetime import datetime
24
import json
35
import os
@@ -6,16 +8,17 @@
68

79
import requests
810

9-
# the following 4 are the actual values that pertain to your account and this specific metric
1011
api_key = os.environ['STATUSPAGE_API_KEY']
11-
page_id = 'fzcq6v7wcg65'
12-
metric_id = 'rfcg9djxtg6n'
12+
page_id = os.environ['STATUSPAGE_PAGE_ID']
13+
metric_id = os.environ['STATUSPAGE_METRIC_ID']
1314
api_base = 'api.statuspage.io'
1415

1516
github_id = os.environ['GITHUB_OAUTH_KEY']
1617
github_secret = os.environ['GITHUB_OAUTH_SECRET']
1718

19+
1820
def get_rate_limit():
21+
"""Retrieve the current GitHub rate limit for our auth tokens"""
1922
r = requests.get('https://api.github.com/rate_limit',
2023
params={
2124
'client_id': github_id,
@@ -26,7 +29,9 @@ def get_rate_limit():
2629
resp = r.json()
2730
return resp['resources']['core']
2831

29-
def post_data(limit, remaining):
32+
33+
def post_data(limit, remaining, **ignore):
34+
"""Send the percent-remaining GitHub rate limit to statuspage"""
3035
percent = 100 * remaining / limit
3136
now = int(datetime.utcnow().timestamp())
3237
url = "https://api.statuspage.io/v1/pages/{page_id}/metrics/{metric_id}/data.json".format(
@@ -45,11 +50,17 @@ def post_data(limit, remaining):
4550
)
4651
r.raise_for_status()
4752

53+
54+
def get_and_post():
55+
data = get_rate_limit()
56+
print(json.dumps(data))
57+
post_data(limit=data['limit'], remaining=data['remaining'])
58+
59+
4860
while True:
4961
try:
50-
limit = get_rate_limit()
51-
print(json.dumps(limit))
52-
post_data(limit['limit'], limit['remaining'])
62+
get_and_post()
5363
except Exception as e:
5464
print("Error: %s" % e, file=sys.stderr)
65+
# post every two minutes
5566
time.sleep(120)

0 commit comments

Comments
 (0)