Closed cpressland closed 1 year ago
Can't find original repo, but here is all associated code:
import argparse import datetime import os import apscheduler.schedulers.blocking import apscheduler.triggers.cron import requests BARC_PERC = os.environ["BARC_PERC"] PROMETHEUS_URL = os.getenv("PROMETHEUS_URL", "http://prometheus:9090") def run(): now = int(datetime.datetime.now().timestamp()) minus_10 = int((datetime.datetime.now() - datetime.timedelta(minutes=10)).timestamp()) num_users_req = requests.get( f"{PROMETHEUS_URL}/api/v1/query_range?query=hermes_current_users_total%7Bkubernetes_cluster%3D%22prod0%22%2C%20client_app%3D%22Barclays%20Mobile%20Banking%22%7D&start={minus_10}&end={now}&step=15" ) result_num_of_users = num_users_req.json()["data"]["result"][0]["values"][-1][1] num_pcard_req = requests.get( f"{PROMETHEUS_URL}/api/v1/query_range?query=hermes_current_payment_cards_total%7Bkubernetes_cluster%3D%22prod0%22%2C%20client_app%3D%22Barclays%20Mobile%20Banking%22%7D&start={minus_10}&end={now}&step=15" ) result_num_of_payment_cards = num_pcard_req.json()["data"]["result"][0]["values"][-1][1] num_mcard_req = requests.get( f"{PROMETHEUS_URL}/api/v1/query_range?query=hermes_current_membership_cards_total%7Bkubernetes_cluster%3D%22prod0%22%2C%20client_app%3D%22Barclays%20Mobile%20Banking%22%7D&start={minus_10}&end={now}&step=15" ) result_num_of_membershipcards = num_mcard_req.json()["data"]["result"][0]["values"][-1][1] msg = { "@type": "MessageCard", "@context": "http://schema.org/extensions", "themeColor": "00aeef", "summary": "Barclays Stats", "Sections": [ { "activityTitle": "Barclays Stats", "facts": [ {"name": "App Percentage", "value": BARC_PERC + "%"}, {"name": "Users", "value": str(result_num_of_users)}, {"name": "Payment Cards", "value": str(result_num_of_payment_cards)}, {"name": "Membership Cards", "value": str(result_num_of_membershipcards)}, ], "markdown": False, } ], "potentialAction": [ { "@type": "OpenUri", "name": "Open Dashboard", "targets": [ { "os": "default", "uri": "https://grafana.tools.bink.sh/d/MKHW27xMk/barclays-stats?orgId=1", } ], } ], } requests.post( "https://hellobink.webhook.office.com/webhookb2/66f08760-f657-42af-bf88-4f7e4c009af1@a6e2367a-92ea-4e5a-b565-723830bcc095/IncomingWebhook/445323b803034d8aa489e688f58fc8c7/f7c46488-2054-46de-9673-e0c6e94b232c", json=msg, ) parser = argparse.ArgumentParser() parser.add_argument("--now", action="store_true", default=False) args = parser.parse_args() if args.now: run() else: a = apscheduler.schedulers.blocking.BlockingScheduler() a.add_job(run, apscheduler.triggers.cron.CronTrigger.from_crontab("0 10 * * 1")) a.start()
RIP Barclays.
Can't find original repo, but here is all associated code: