diff --git a/.github/slack_oncall_reminder.py b/.github/slack_oncall_reminder.py deleted file mode 100644 index f62707077..000000000 --- a/.github/slack_oncall_reminder.py +++ /dev/null @@ -1,70 +0,0 @@ -import argparse - -import requests -from slack_sdk import WebClient -from slack_sdk.errors import SlackApiError - - -def save_users(users_array): - users = {} - for user in users_array: - # NOTE: some apps, slackbots do not have emails to map to - profile = user["profile"] - if "email" in profile.keys(): - user_email = profile["email"] - username = user_email.split("@")[0] - users[username] = user - return users - - -def grab_whos_on_call(OPS_GENIE_API_TOKEN, ROTATION_SCHEDULE_ID): - url = f"https://api.opsgenie.com/v2/schedules/{ROTATION_SCHEDULE_ID}/on-calls" - headers = {"Authorization": f"GenieKey {OPS_GENIE_API_TOKEN}"} - response = requests.get(url, headers=headers) - if response.status_code == 200: - data = response.json() - else: - print(f"Request failed with status code {response.status_code}") - print("Response content:") - print(response.content.decode("utf-8")) - return data["data"]["onCallParticipants"][0]["name"].split("@")[0] - - -def postSlackMessage(client, CHANNEL_ID, OPS_GENIE_API_TOKEN, ROTATION_SCHEDULE_ID): - try: - result = client.users_list() - users = save_users(result["members"]) - on_call = grab_whos_on_call(OPS_GENIE_API_TOKEN, ROTATION_SCHEDULE_ID) - slack_id = users[on_call]["id"] - - result = client.chat_postMessage( - channel=CHANNEL_ID, - text=f"""๐Ÿ› ๏ธMaintenance On-Call: <@{slack_id}>, you will be on-call for the next week. Resources:\n - ๐Ÿ“– - ๐Ÿ” - ๐Ÿ“Š - ๐Ÿ“‹ - ๐Ÿ”ง - """, - ) - except SlackApiError as e: - print(f"SlackAPIError: {e}") - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="Script that notifies on-call rotation daily" - ) - parser.add_argument("--slack_api_token", required=True, type=str) - parser.add_argument("--ops_genie_api_token", required=True, type=str) - args = parser.parse_args() - - SLACK_API_TOKEN = args.slack_api_token - OPS_GENIE_API_TOKEN = args.ops_genie_api_token - # NOTE: Feel free to grab the relevant channel ID to post the message to but ensure the App is installed within the channel - CHANNEL_ID = "C06N9KJHN2J" - # NOTE: Rotation schedule is grabbed directly from within the OpsGenie site - ROTATION_SCHEDULE_ID = "904cd122-f269-418d-8c29-3e6751716bae" - - client = WebClient(token=SLACK_API_TOKEN) - postSlackMessage(client, CHANNEL_ID, OPS_GENIE_API_TOKEN, ROTATION_SCHEDULE_ID) diff --git a/.github/workflows/on-call-reminder.yml b/.github/workflows/on-call-reminder.yml deleted file mode 100644 index 54a7a6e3e..000000000 --- a/.github/workflows/on-call-reminder.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: on_call_reminder - -on: - schedule: - - cron: '0 17 * * 3' # Runs every Wednesday at 9am PST (17:00 UTC) - workflow_dispatch: # Allows manual triggering of the workflow - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - persist-credentials: false - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.12' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install requests slack_sdk argparse - - - name: Run Python script - env: - SLACK_API_TOKEN: ${{ secrets.SLACK_API_TOKEN }} - OPS_GENIE_API_TOKEN: ${{ secrets.OPS_GENIE_API_TOKEN }} - run: python .github/slack_oncall_reminder.py --slack_api_token $SLACK_API_TOKEN --ops_genie_api_token $OPS_GENIE_API_TOKEN