Skip to content

Commit

Permalink
Merge branch 'handle_off_nadir_scenes' of github.com:ASFHyP3/its-live…
Browse files Browse the repository at this point in the history
…-monitoring into handle_off_nadir_scenes
  • Loading branch information
cirrusasf committed Apr 11, 2024
2 parents 34e74cc + cb91ae4 commit 9bc3bfd
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0]
## [0.4.0]

### Fixed
- Off-naider scenes will now be processed and will only be paired with other off-nadir scenes.

## [0.3.0]

### Added
- A CLI wrapper for `status_messages.py` so that it can more easily be run locally.

### Fixed
- Status messages can now be posted to mattermost with a bot account.

## [0.2.0]

### Added
Expand Down
1 change: 1 addition & 0 deletions cloudformation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ Resources:
QueueURL: !Ref DeadLetterQueue
QueueName: !GetAtt DeadLetterQueue.QueueName
MattermostPAT: !Ref MattermostPAT
LambdaLoggingLevel: !Ref LambdaLoggingLevel
TemplateURL: status-messages/cloudformation.yml
9 changes: 5 additions & 4 deletions landsat/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
password=EARTHDATA_PASSWORD,
)

log = logging.getLogger()
log = logging.getLogger(__name__)
log.setLevel(os.environ.get('LOGGING_LEVEL', 'INFO'))


Expand Down Expand Up @@ -258,10 +258,11 @@ def main() -> None:
parser.add_argument('-v', '--verbose', action='store_true', help='Turn on verbose logging')
args = parser.parse_args()

level = logging.DEBUG if args.verbose else logging.INFO
logging.basicConfig(stream=sys.stdout, format='%(asctime)s - %(levelname)s - %(message)s', level=level)
log.debug(' '.join(sys.argv))
logging.basicConfig(stream=sys.stdout, format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)
if args.verbose:
log.setLevel(logging.DEBUG)

log.debug(' '.join(sys.argv))
_ = process_scene(args.reference, timedelta(days=args.max_pair_separation), args.max_cloud_cover, args.submit)


Expand Down
8 changes: 8 additions & 0 deletions status-messages/cloudformation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ Parameters:
Type: String
NoEcho: true

LambdaLoggingLevel:
Type: String
Default: INFO
AllowedValues:
- INFO
- DEBUG

Resources:
LogGroup:
Type: AWS::Logs::LogGroup
Expand Down Expand Up @@ -53,6 +60,7 @@ Resources:
Variables:
MATTERMOST_PAT: !Ref MattermostPAT
QUEUE_URL: !Ref QueueURL
LOGGING_LEVEL: !Ref LambdaLoggingLevel
Code: src/
Handler: status_messages.lambda_handler
Role: !GetAtt Role.Arn
Expand Down
50 changes: 43 additions & 7 deletions status-messages/src/status_messages.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
"""Lambda function to trigger Mattermost updates for Dead Letter Queue."""

import argparse
import logging
import os
import sys
from datetime import datetime, timezone
from pathlib import Path

import boto3
from mattermostdriver import Driver


CHANNEL = 'measures-its_live'
QUEUE_URL = os.environ['QUEUE_URL']
MATTERMOST_PAT = os.environ['MATTERMOST_PAT']

# You can find the ID for a channel by looking in the channel info
MATTERMOST_CHANNEL_ID = 'mmffdcqsafdg8xyr747scyuqnw' # ~measures-its_live

log = logging.getLogger(__name__)
log.setLevel(os.environ.get('LOGGING_LEVEL', 'INFO'))


def get_queue_count() -> str:
"""Retrieve the message count of the Dead Letter Queue.
Expand Down Expand Up @@ -38,18 +47,45 @@ def lambda_handler(event: dict, context: dict) -> None:
"""
mattermost = Driver({'url': 'chat.asf.alaska.edu', 'token': MATTERMOST_PAT, 'scheme': 'https', 'port': 443})
response = mattermost.login()
print(response)
log.debug(response)

dead_letter_queue_count = int(get_queue_count())

queue_name = Path(QUEUE_URL).name
if 'test' in queue_name:
status_emoji = ':heavy_multiplication_x:' if dead_letter_queue_count != 0 else ':heavy_check_mark:'
else:
status_emoji = ':alert:' if dead_letter_queue_count != 0 else ':large_green_circle:'

channel_info = mattermost.channels.get_channel_by_name_and_team_name('asf', CHANNEL)
dead_letter_queue_count = get_queue_count()
mattermost_message = (
f'Dead Letter Queue Count for ITS_LIVE has '
f'{status_emoji} Dead Letter Queue Count for `{queue_name}` has '
f'{dead_letter_queue_count} entries on {datetime.now(tz=timezone.utc).isoformat()}'
)

log.info(f'Posting: "{mattermost_message}" to {MATTERMOST_CHANNEL_ID}')
response = mattermost.posts.create_post(
options={
'channel_id': channel_info['id'],
'channel_id': MATTERMOST_CHANNEL_ID,
'message': mattermost_message,
}
)
print(response)
log.debug(response)


def main() -> None:
"""Command Line wrapper around `lambda_handler`."""
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-v', '--verbose', action='store_true', help='Turn on verbose logging')
args = parser.parse_args()

logging.basicConfig(stream=sys.stdout, format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)

if args.verbose:
log.setLevel(logging.DEBUG)

log.debug(' '.join(sys.argv))
lambda_handler({}, {})


if __name__ == '__main__':
main()

0 comments on commit 9bc3bfd

Please sign in to comment.