Skip to content

Commit

Permalink
add in initial bits
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquelynsmale committed Apr 3, 2024
1 parent 2f12821 commit 21a9203
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/mm_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Weekly ITSLIVE Dead Letter Queue

on:
schedule:
# Run @ 5:00 AM ( 2:00 PM UTC) every Monday
- cron: '0 14 * * 1'
workflow_dispatch:
inputs:
start_time:
description: "Start time of the bullet report"
required: false
sender:
description: "The sender's email address"
required: false
default: [email protected]
recipients:
description: "A SPACE separated list of email address that should receive the bullet report"
required: false
mattermost_channel:
description: "Post report to this ASF MatterMost channel"
required: false

env:
AWS_DEFAULT_REGION: us-west-2
AWS_ACCESS_KEY_ID: ${{ secrets.V2_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.V2_AWS_SECRET_ACCESS_KEY }}
MATTERMOST_PAT: ${{ secrets.MATTERMOST_PAT }}

jobs:
mm-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml

- name: Install
shell: bash -l {0}
run: |
python -m pip install .
- name: Generate report
env:
GITHUB_TOKEN: ${{ secrets.TOOLS_BOT_PAK }}
START_TIME: ${{ github.event.inputs.start_time }}
shell: bash -l {0}
run: |
if [[ -z "${START_TIME}" ]]; then
mm-update
else
mm-update --search-start "${START_TIME}"
fi
- name: Upload report artifact
uses: actions/upload-artifact@v3
with:
name: mm-update
path: 'mm-update.md'

- name: Send scheduled messages
if: github.event_name == 'schedule'
shell: bash -l {0}
run: |
export EMAIL_SUBJECT=$(sed -n 3p report.md)
sendit report.md [email protected] "${EMAIL_SUBJECT}" [email protected] [email protected] [email protected] [email protected] [email protected]
- name: Send dispatched messages
if: github.event_name == 'workflow_dispatch'
env:
SENDER_EMAIL: ${{ github.event.inputs.sender }}
RECIPIENT_EMAILS: ${{ github.event.inputs.recipients }}
MATTERMOST_CHANNEL: ${{ github.event.inputs.mattermost_channel }}
shell: bash -l {0}
run: |
if [[ -z "${RECIPIENT_EMAILS}" ]]; then
echo "Skipping sendit because no recipient email(s) provided"
else
export EMAIL_SUBJECT=$(sed -n 3p report.md)
sendit report.md ${SENDER_EMAIL} "${EMAIL_SUBJECT}" ${RECIPIENT_EMAILS}
fi
if [[ -z "${MATTERMOST_CHANNEL}" ]]; then
echo "Skipping postit because no MatterMost channel provided"
else
postit report.md --channel ${MATTERMOST_CHANNEL}
fi
66 changes: 66 additions & 0 deletions mattermost-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import argparse

Check failure on line 1 in mattermost-update.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (D100)

mattermost-update.py:1:1: D100 Missing docstring in public module
import logging
import os
import sys
from datetime import datetime
from pathlib import Path

import boto3
from mattermostdriver import Driver


def get_itslive_queue():

Check failure on line 12 in mattermost-update.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (ANN201)

mattermost-update.py:12:5: ANN201 Missing return type annotation for public function `get_itslive_queue`

Check failure on line 12 in mattermost-update.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (D103)

mattermost-update.py:12:5: D103 Missing docstring in public function
os.environ['AWS_PROFILE'] = 'hyp3-its-live'
client = boto3.client('sqs')
result = client.get_queue_attributes(
QueueUrl='https://sqs.us-west-2.amazonaws.com/986442313181/its-live-monitoring-prod-DeadLetterQueue'
'-LjzW63l95LAP',
AttributeNames=['All'],
)
return result['Attributes']['ApproximateNumberOfMessages']


def post(markdown_file: Path, channel: str = 'APD'):

Check failure on line 23 in mattermost-update.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (ANN201)

mattermost-update.py:23:5: ANN201 Missing return type annotation for public function `post`

Check failure on line 23 in mattermost-update.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (D103)

mattermost-update.py:23:5: D103 Missing docstring in public function
mattermost = Driver({
'url': 'chat.asf.alaska.edu',
'token': os.environ.get('MATTERMOST_PAT'),
'scheme': 'https',
'port': 443
})
response = mattermost.login()
logging.debug(response)

channel_info = mattermost.channels.get_channel_by_name_and_team_name('asf', channel)

dead_letter_queue_count = get_itslive_queue()
mattermost_message = (f'Dead Letter Queue Count as of {datetime.now()} has '
f'{dead_letter_queue_count} entries')

response = mattermost.posts.create_post(
options={
'channel_id': channel_info['id'],
'message': mattermost_message,
}
)
logging.debug(response)

return response


def main():

Check failure on line 50 in mattermost-update.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (ANN201)

mattermost-update.py:50:5: ANN201 Missing return type annotation for public function `main`

Check failure on line 50 in mattermost-update.py

View workflow job for this annotation

GitHub Actions / call-ruff-workflow / check-with-ruff

Ruff (D103)

mattermost-update.py:50:5: D103 Missing docstring in public function
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)

parser.add_argument('markdown_file', type=Path, help='Markdown file with the post content')
parser.add_argument('--channel', default='tools-team', help='The MatterMost channel to post to')

args = parser.parse_args()

out = logging.StreamHandler(stream=sys.stdout)
out.addFilter(lambda record: record.levelno <= logging.INFO)
err = logging.StreamHandler()
err.setLevel(logging.WARNING)
logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=(out, err))

post(**args.__dict__)
1 change: 1 addition & 0 deletions requirements-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
cfn-lint
ruff
pytest
mattermostdriver

0 comments on commit 21a9203

Please sign in to comment.