def monitor()

in src/monitor.py [0:0]


def monitor(session: Session, config: Dict[str, str], stage: str):
    dynamodb = create_service_resource(session, stage)
    response = send_request(config['SECUREDROP_URL'])
    history = read_from_database(dynamodb, config['TABLE_NAME'])
    healthy = healthcheck(response)

    logger.info(f'Healthcheck outcome: {healthy}')
    logger.debug(history)

    # TODO: perform update once per day regardless and give MOTD
    if state_has_changed(healthy, history):
        upload_website_index(session, config, healthy)
        send_message(config, healthy)
        # we also send an email alert
        if not healthy:
            send_failure_email(session, config)

    # Finally, update the database with the latest result
    item = create_item(int(time.time()), healthy)
    write_to_database(dynamodb, config['TABLE_NAME'], item)