-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
2f12821
commit 21a9203
Showing
3 changed files
with
154 additions
and
0 deletions.
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
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 |
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,66 @@ | ||
import argparse | ||
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 GitHub Actions / call-ruff-workflow / check-with-ruffRuff (ANN201)
|
||
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 GitHub Actions / call-ruff-workflow / check-with-ruffRuff (ANN201)
|
||
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 GitHub Actions / call-ruff-workflow / check-with-ruffRuff (ANN201)
|
||
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__) |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
cfn-lint | ||
ruff | ||
pytest | ||
mattermostdriver |