def run_tests(): app_text_output.enable() app_text_output.value = "Running Tests, Please wait..." app_textbox_address.disable() app_button_test_sensor.disable() app_text_output.disable() rm_cached_variables.http_login = app_textbox_user.value rm_cached_variables.http_password = app_textbox_password.value sensor_address = app_textbox_address.value test_http_server.sensor_address = sensor_address print("Sensor: " + str(sensor_address) + "\n\n") if get_http_sensor_reading(sensor_address, timeout=5) == "OK": if get_http_sensor_reading(sensor_address, http_command=sg_commands.check_portal_login, timeout=5) == "OK": temp_version = get_http_sensor_reading( sensor_address, http_command=sg_commands.program_version, timeout=5) remote_sensor_version.load_from_string(temp_version) if remote_sensor_version.major_version == refined_compatible_version.major_version and \ remote_sensor_version.feature_version == refined_compatible_version.feature_version and \ remote_sensor_version.minor_version >= refined_compatible_version.minor_version: print(" ------ Starting Tests ------") print(" " + strftime("%B %d, %Y %H:%M:%S") + "\n") print(" Configuration Tests\n") suite = unittest.TestLoader().loadTestsFromTestCase( test_http_server.TestApp) suite.run(unittest.TestResult()) print("\n\n Display & Sensor Reading Tests\n") suite2 = unittest.TestLoader().loadTestsFromTestCase( test_http_server.TestApp2) suite2.run(unittest.TestResult()) else: print("-- Incompatible Version Detected --\n") print_msg = "-- Compatible Version: " + refined_compatible_version.get_version_string( ) print(print_msg + " (" + str(refined_compatible_version.minor_version) + " or higher) --") print("-- Remote Version: " + remote_sensor_version.get_version_string() + " --") else: print("-- Incorrect Sensor Login --") else: print("-- Sensor Offline --\n\n") if sensor_address == "localhost": print("Local Primary Log\n" + logger.get_sensor_log(file_locations.primary_log)) print("\n\n ------ End of Tests ------") print(" " + strftime("%B %d, %Y %H:%M:%S") + "\n") app_text_output.enable() app_text_output.value = redirect_string.getvalue() app_button_test_sensor.enable() app_textbox_address.enable() redirect_string.truncate(0) redirect_string.seek(0)
def _get_zipped_logs(): utc_now = datetime.utcnow().strftime("%Y-%m-%d_%H:%M_") try: return_names = [ utc_now + os.path.basename(file_locations.primary_log), utc_now + os.path.basename(file_locations.network_log), utc_now + os.path.basename(file_locations.sensors_log) ] return_files = [ logger.get_sensor_log(file_locations.primary_log), logger.get_sensor_log(file_locations.network_log), logger.get_sensor_log(file_locations.sensors_log) ] blob_data = zip_files(return_names, return_files).read() return blob_data except Exception as error: logger.primary_logger.error("* Unable to Zip Logs: " + str(error)) return None
def _get_sensors_log(): if app_config_access.checkin_config.send_sensors_log: global previous_sensors_logs max_log_lines = app_config_access.checkin_config.max_log_lines_to_send sensors_logs = logger.get_sensor_log(file_locations.sensors_log, max_lines=max_log_lines) if sensors_logs == previous_sensors_logs: return "" previous_sensors_logs = sensors_logs return sensors_logs return ""
def _get_network_log(): if app_config_access.checkin_config.send_network_log: global previous_network_logs max_log_lines = app_config_access.checkin_config.max_log_lines_to_send network_logs = logger.get_sensor_log(file_locations.network_log, max_lines=max_log_lines) if network_logs == previous_network_logs: return "" previous_network_logs = network_logs return network_logs return ""
def _get_about_system_tabs(): remote_ip_and_port = current_config.remote_tester_ip + ":" + str(app_variables.flask_http_port) remote_ip = current_config.remote_tester_ip remote_port = app_variables.flask_http_port remote_data_command = "http://" + remote_ip + ":" + str(remote_port) + "/Version" remote_version = str(app_generic_functions.get_remote_data(remote_data_command))[2:-1] if 3 > len(remote_version) or len(remote_version) > 14: remote_version = "NA" displayed_log_lines = get_number_of_log_entries() if displayed_log_lines > max_log_lines_return: displayed_log_lines = str(max_log_lines_return) return render_template("about_system_tabs.html", KootnetVersion=current_config.app_version, OSVersion=app_generic_functions.get_os_name_version(), InternetIPAddress=get_ip_from_socket(), FreeDiskSpace=app_generic_functions.get_disk_free_percent(), RemoteVersion=remote_version, RemoteIPandPort=remote_ip_and_port, NumberOfLogLines=displayed_log_lines, TotalLogLines=str(get_number_of_log_entries()), LogEntries=get_sensor_log())
def html_atpro_mqtt_subscriber_data_stream_view(): mqtt_subscriber_log = file_locations.mqtt_subscriber_log max_entries = app_config_access.mqtt_subscriber_config.mqtt_page_view_max_entries mqtt_subscriber_log_content = logger.get_sensor_log( mqtt_subscriber_log, max_lines=max_entries).strip() if mqtt_subscriber_log_content == "": mqtt_subscriber_log_content = _mqtt_sub_entry_to_html("") else: new_return = "" for line in mqtt_subscriber_log_content.split("\n"): new_return += _mqtt_sub_entry_to_html(line) mqtt_subscriber_log_content = new_return new_sensors_in_db_count = len( get_sqlite_tables_in_list(file_locations.mqtt_subscriber_database)) app_cached_variables.mqtt_subscriber_sensors_count = new_sensors_in_db_count return render_template( "ATPro_admin/page_templates/mqtt-subscriber-data-view.html", MQTTSubDatabaseSize=get_file_size( file_locations.mqtt_subscriber_database), MQTTSubscriberServerAddress=app_config_access.mqtt_subscriber_config. broker_address, MQTTShowing=max_entries, MQTTTotoalEntries=logger.get_number_of_log_entries( mqtt_subscriber_log), SQLMQTTSensorsInDB=str(new_sensors_in_db_count), MQTTEnabledColor=_get_html_color( app_config_access.mqtt_subscriber_config.enable_mqtt_subscriber), MQTTSubscriberEnabledText=_get_html_text( app_config_access.mqtt_subscriber_config.enable_mqtt_subscriber), MQTTSQLEnabledColor=_get_html_color( app_config_access.mqtt_subscriber_config.enable_mqtt_sql_recording ), MQTTSQLSubscriberEnabledText=_get_html_text( app_config_access.mqtt_subscriber_config.enable_mqtt_sql_recording ), SubscriberTopicsContent=mqtt_subscriber_log_content)