Exemplo n.º 1
0
def setup():
    start_time = timer()
    config_service.set_mode_to('server')
    data_files.setup_logging('app')
    information.refresh_all()
    metrics_service.setup()
    loggy.log_time('Mothership App Setup', start_time, timer())
Exemplo n.º 2
0
        if remaining_time > 0:
            time.sleep(remaining_time)

        if measurement_counter == 1 and last_picture != EMPTY:
            email_sender_service.send_picture(last_picture, measurement_counter)

        if app_timer.is_time_to_run_every_15_minutes(email_cooldown) and last_picture != EMPTY:
            email_sender_service.send_picture(last_picture, measurement_counter)
            email_cooldown = datetime.now()
        if measurement_counter % 2 == 0:
            local_data_gateway.post_healthcheck_beat('other', 'cctv')


if __name__ == '__main__':
    config_service.set_mode_to('cctv')
    data_files.setup_logging('cctv')
    logging.info('Starting application ...')
    email_sender_service.send_ip_email('CCTV APP')
    try:
        if config_service.is_sky_camera_on():
            main()
        else:
            logger.warning('Camera disabled.')
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!', exc_info=True)
    except Exception as exception:
        print(f'Whoops. {exception}')
        logger.error('Something went badly wrong. {}'.format(exception), exc_info=True)
        email_sender_service.send_error_log_email("CCTV APP", "Application crashed due to {}.".format(exception))
    except BaseException as disaster:
Exemplo n.º 3
0
        if remaining_of_five_s > 0:
            time.sleep(remaining_of_five_s
                       )  # it should be 5 seconds between measurements


def cleanup_before_exit():
    two_led_service.on()
    led_matrix_service.set_red()
    sys.exit(0)


if __name__ == '__main__':
    global points
    config_service.set_mode_to('denva')
    data_files.setup_logging('app')
    logging.info('Starting application ... \n Press Ctrl+C to shutdown')
    email_sender_service.send_ip_email('denva')
    try:
        logging.info('Mounting network drives')
        commands.mount_all_drives()

        logging.info("Sensor warming up, please wait...")
        air_quality_service.start_measurement()
        motion_service.sample()
        logging.info('Sensor needed {} seconds to warm up'.format(counter))
        two_led_service.off()
        main()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
Exemplo n.º 4
0
    if measurement_is_older_than_5_minutes():
        is_ok = False
        reasons.append("Getting measurement is not working")

    if not is_ok:
        logger.warning("FAILED ( {} )".format(response))

    return is_ok


def send_email_on_fail(problem: str):
    email_sender_service.send_error_log_email("healthcheck", problem)


if __name__ == '__main__':
    try:
        config_service.set_mode_to('hc')
        data_files.setup_logging('hc')
        healthcheck_test_runner()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!',
                     exc_info=True)
    except BaseException as disaster:
        msg = 'Shit hit the fan and application died badly because {}'.format(
            disaster)
        print(msg)
        traceback.print_exc()
        logger.fatal(msg, exc_info=True)
Exemplo n.º 5
0
    stop = datetime.datetime.now()

    delta = stop - start
    time = int(delta.total_seconds() * 1000)
    logger.info(f'It took {time} ms.')
    return render_template('hq.html', message=all_data)


@app.route("/")
def welcome():
    return hq()  # redirect


if __name__ == '__main__':
    config_service.set_mode_to('server')
    data_files.setup_logging('ui')
    logger.info('Starting web server')

    try:
        app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
        app.config['JSON_AS_ASCII'] = False
        app.run(host='0.0.0.0',
                debug=True)  # host added so it can be visible on local network
        healthcheck()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!',
                     exc_info=True)
    except Exception as exception:
        logger.error('Something went badly wrong\n{}'.format(exception),
Exemplo n.º 6
0
        if is_in_override(mode):
            set_manual_mode(mode)
        else:
            if is_night_mode():
                mote_lighting.night_mode()
            elif is_stand_up():
                mote_lighting.party_random_color_mode()
            elif is_busy_at_work():
                mote_lighting.red_alert()
            else:
                mote_lighting.daydream()


if __name__ == '__main__':
    config_service.set_mode_to(APP_NAME)
    data_files.setup_logging(APP_NAME)
    logger.info('Starting application ... \n Press Ctrl+C to shutdown')
    try:
        app_loop()
    except KeyboardInterrupt as keyboard_exception:
        print('Received request application to shut down.. goodbye. {}'.format(
            keyboard_exception))
        logging.info('Received request application to shut down.. goodbye!',
                     exc_info=True)
        sys.exit(0)
    except Exception as exception:
        logger.error('Something went badly wrong\n{}'.format(exception),
                     exc_info=True)
        email_sender_service.send_error_log_email(
            APP_NAME, '{} crashes due to {}'.format(APP_NAME, exception))
    except BaseException as disaster:
Exemplo n.º 7
0
        if counter % 2 == 0:
            local_data_gateway.post_healthcheck_beat('other', 'digest')
        display_stats()
        measurement_message = 'Measurement no. {} It took {} milliseconds to process. Errors: {}. Warnings: {}'.format(
            counter, measurement_time, errors, warnings)
        logger.info(measurement_message)
        remaining_time = refresh_rate_in_seconds - (float(measurement_time) /
                                                    1000)

        if remaining_time > 0:
            time.sleep(remaining_time)


if __name__ == '__main__':
    config_service.set_mode_to('ddd')
    data_files.setup_logging('ddd')
    try:
        digest()
    except KeyboardInterrupt as keyboard_exception:
        logger.warning('Requesting shutdown: {}'.format(keyboard_exception),
                       exc_info=True)
    except Exception as exception:
        logger.error('Something went badly wrong: {}'.format(exception),
                     exc_info=True)
    except BaseException as disaster:
        disaster_error_message = 'Shit hit the fan and application died badly because {}'.format(
            disaster)
        print(disaster_error_message)
        traceback.print_exc()
        logger.fatal(disaster_error_message, exc_info=True)