def letter_raise_alert_if_no_ack_file_for_zip(): # get a list of zip files since yesterday zip_file_set = set() for key in s3.get_list_of_files_by_suffix( bucket_name=current_app.config['LETTERS_PDF_BUCKET_NAME'], subfolder=datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent', suffix='.TXT'): subname = key.split('/')[-1] # strip subfolder in name zip_file_set.add(subname.upper().rstrip('.TXT')) # get acknowledgement file ack_file_set = set() yesterday = datetime.now(tz=pytz.utc) - timedelta( days=1) # AWS datetime format for key in s3.get_list_of_files_by_suffix( bucket_name=current_app.config['DVLA_RESPONSE_BUCKET_NAME'], subfolder='root/dispatch', suffix='.ACK.txt', last_modified=yesterday): ack_file_set.add(key) today_str = datetime.utcnow().strftime('%Y%m%d') ack_content_set = set() for key in ack_file_set: if today_str in key: content = s3.get_s3_file( current_app.config['DVLA_RESPONSE_BUCKET_NAME'], key) for zip_file in content.split('\n'): # each line s = zip_file.split('|') ack_content_set.add(s[0].upper()) deskpro_message = "Letter ack file does not contains all zip files sent. " \ "Missing ack for zip files: {}, " \ "pdf bucket: {}, subfolder: {}, " \ "ack bucket: {}".format(str(sorted(zip_file_set - ack_content_set)), current_app.config['LETTERS_PDF_BUCKET_NAME'], datetime.utcnow().strftime('%Y-%m-%d') + '/zips_sent', current_app.config['DVLA_RESPONSE_BUCKET_NAME']) # strip empty element before comparison ack_content_set.discard('') zip_file_set.discard('') if len(zip_file_set - ack_content_set) > 0: if current_app.config['NOTIFY_ENVIRONMENT'] in [ 'live', 'production', 'test' ]: deskpro_client.create_ticket(subject="Letter acknowledge error", message=deskpro_message, ticket_type='alert') current_app.logger.error(deskpro_message) if len(ack_content_set - zip_file_set) > 0: current_app.logger.info( "letter ack contains zip that is not for today: {}".format( ack_content_set - zip_file_set))
def raise_alert_if_letter_notifications_still_sending(): today = datetime.utcnow().date() # Do nothing on the weekend if today.isoweekday() in [6, 7]: return if today.isoweekday() == 1: offset_days = 3 else: offset_days = 1 still_sending = Notification.query.filter( Notification.notification_type == LETTER_TYPE, Notification.status == NOTIFICATION_SENDING, Notification.sent_at >= today - timedelta(days=offset_days), Notification.sent_at < today).count() if still_sending: message = "There are {} letters in the 'sending' state from {}".format( still_sending, (today - timedelta(days=offset_days)).strftime('%A %d %B')) # Only send alerts in production if current_app.config['NOTIFY_ENVIRONMENT'] in [ 'live', 'production', 'test' ]: deskpro_client.create_ticket( subject="[{}] Letters still sending".format( current_app.config['NOTIFY_ENVIRONMENT']), message=message, ticket_type="alert") else: current_app.logger.info(message)
def submit_request_to_go_live(service_id): form = RequestToGoLiveForm() if form.validate_on_submit(): try: deskpro_client.create_ticket( subject='Request to go live - {}'.format(current_service['name']), message=( 'On behalf of {} ({})\n' '\n---' '\nOrganisation type: {}' '\nAgreement signed: {}' '\nChannel: {}\nStart date: {}\nStart volume: {}' '\nPeak volume: {}' '\nFeatures: {}' ).format( current_service['name'], url_for('main.service_dashboard', service_id=current_service['id'], _external=True), current_service['organisation_type'], AgreementInfo.from_current_user().as_human_readable, formatted_list(filter(None, ( 'email' if form.channel_email.data else None, 'text messages' if form.channel_sms.data else None, 'letters' if form.channel_letter.data else None, )), before_each='', after_each=''), form.start_date.data, form.start_volume.data, form.peak_volume.data, formatted_list(filter(None, ( 'one off' if form.method_one_off.data else None, 'file upload' if form.method_upload.data else None, 'API' if form.method_api.data else None, )), before_each='', after_each='') ), user_email=current_user.email_address, user_name=current_user.name ) except DeskproError: abort(500, "Request to go live submission failed") flash('We’ve received your request to go live', 'default') return redirect(url_for('.service_settings', service_id=service_id)) return render_template('views/service-settings/submit-request-to-go-live.html', form=form)
def feedback(ticket_type): try: form = { QUESTION_TICKET_TYPE: Feedback, PROBLEM_TICKET_TYPE: Problem, }[ticket_type]() except KeyError: abort(404) if not form.feedback.data: form.feedback.data = session.pop('feedback_message', '') if request.args.get('severe') in ['yes', 'no']: severe = convert_to_boolean(request.args.get('severe')) else: severe = None urgent = ( in_business_hours() or (ticket_type == PROBLEM_TICKET_TYPE and severe) ) anonymous = ( (not form.email_address.data) and (not current_user.is_authenticated) ) if needs_triage(ticket_type, severe): session['feedback_message'] = form.feedback.data return redirect(url_for('.triage')) if needs_escalation(ticket_type, severe): return redirect(url_for('.bat_phone')) if current_user.is_authenticated: form.email_address.data = current_user.email_address form.name.data = current_user.name if form.validate_on_submit(): user_email = form.email_address.data user_name = form.name.data or None if current_service: service_string = 'Service "{name}": {url}\n'.format( name=current_service['name'], url=url_for('main.service_dashboard', service_id=current_service['id'], _external=True) ) else: service_string = '' feedback_msg = 'Environment: {}\n{}{}\n{}'.format( url_for('main.index', _external=True), service_string, '' if user_email else '{} (no email address supplied)'.format(form.name.data), form.feedback.data ) try: deskpro_client.create_ticket( subject='Notify feedback {}'.format(user_name), message=feedback_msg, ticket_type=ticket_type, urgency=10 if urgent else 1, user_email=user_email, user_name=user_name ) except DeskproError: abort(500, "Feedback submission failed") return redirect(url_for('.thanks', urgent=urgent, anonymous=anonymous)) if not form.feedback.data: form.feedback.data = get_prefilled_message() return render_template( 'views/support/{}.html'.format(ticket_type), form=form, ticket_type=ticket_type, )