def main(): parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", help="verbose log output", default=False) parser.add_option("-l", "--label", dest="label", help="label of the agent", default=None) parser.add_option("--host", dest="host", help="AppMaster host", default=None) parser.add_option("--port", dest="port", help="AppMaster port", default=None) (options, args) = parser.parse_args() if not "AGENT_WORK_ROOT" in os.environ: parser.error("AGENT_WORK_ROOT environment variable must be set.") options.root_folder = os.environ["AGENT_WORK_ROOT"] if not "AGENT_LOG_ROOT" in os.environ: parser.error("AGENT_LOG_ROOT environment variable must be set.") options.log_folder = os.environ["AGENT_LOG_ROOT"] if not options.label: parser.error("label is required.") bind_signal_handlers() # Check for configuration file. agentConfig = AgentConfig(options.root_folder, options.log_folder, options.label) update_config_from_file(agentConfig) # update configurations if needed if options.host: agentConfig.set(AgentConfig.SERVER_SECTION, "hostname", options.host) if options.port: agentConfig.set(AgentConfig.SERVER_SECTION, "port", options.port) logFile = os.path.join(agentConfig.getResolvedPath(AgentConfig.LOG_DIR), logFileName) perform_prestart_checks(agentConfig) ensure_folder_layout(agentConfig) setup_logging(options.verbose, logFile) update_log_level(agentConfig, logFile) write_pid() logger.info("Using AGENT_WORK_ROOT = " + options.root_folder) logger.info("Using AGENT_LOG_ROOT = " + options.log_folder) server_url = SERVER_STATUS_URL.format( agentConfig.get(AgentConfig.SERVER_SECTION, "hostname"), agentConfig.get(AgentConfig.SERVER_SECTION, "port"), agentConfig.get(AgentConfig.SERVER_SECTION, "check_path"), ) print("Connecting to the server at " + server_url + "...") logger.info("Connecting to the server at: " + server_url) # Wait until server is reachable netutil = NetUtil() netutil.try_to_connect(server_url, -1, logger) # Launch Controller communication controller = Controller(agentConfig) controller.start() controller.join() stop_agent() logger.info("... agent finished")
def main(): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname setup_logging(options.verbose) default_cfg = { 'agent' : { 'prefix' : '/home/ambari' } } config = ConfigParser.RawConfigParser(default_cfg) bind_signal_handlers() if (len(sys.argv) >1) and sys.argv[1]=='stop': stop_agent() # Check for ambari configuration file. config = resolve_ambari_config() # Starting data cleanup daemon data_cleaner = None if int(config.get('agent','data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) daemonize() # Starting ping port listener try: ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message); sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) server_url = 'https://' + config.get('server', 'hostname') + ':' + config.get('server', 'url_port') print("Connecting to the server at " + server_url + "...") logger.info('Connecting to the server at: ' + server_url) # Wait until server is reachable netutil = NetUtil() netutil.try_to_connect(server_url, -1, logger) # Launch Controller communication controller = Controller(config) controller.start() controller.join() stop_agent() logger.info("finished")
def main(): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname setup_logging(options.verbose) default_cfg = { 'agent' : { 'prefix' : '/home/ambari' } } config = ConfigParser.RawConfigParser(default_cfg) bind_signal_handlers() if (len(sys.argv) >1) and sys.argv[1]=='stop': stop_agent() # Check for ambari configuration file. config = resolve_ambari_config() # Starting data cleanup daemon data_cleaner = None if int(config.get('agent','data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) daemonize() # Starting ping port listener ping_port_listener = PingPortListener(config) ping_port_listener.start() update_log_level(config) server_url = 'https://' + config.get('server', 'hostname') + ':' + config.get('server', 'url_port') print("Connecting to the server at " + server_url + "...") logger.info('Connecting to the server at: ' + server_url) # Wait until server is reachable netutil = NetUtil() netutil.try_to_connect(server_url, -1, logger) # Launch Controller communication controller = Controller(config) controller.start() controller.join() stop_agent() logger.info("finished")
def gatherData(self): ''' Method responsible for gathering data ''' # Returns NetUtil object for each NSEW test, in case gateway # changes with location self.nt = NetUtil() # Calls Ping method with arg ping, returns unused list p_results = self.nt.pingTest('ping') type(p_results) quality, level = self.nt.signalTest() res_dict = collections.OrderedDict() res_dict['GatewayIP'] = self.nt.ping_ip res_dict['GatewayMac'] = self.nt.gw_mac res_dict['PacketLoss %'] = self.nt.pingTest('loss') res_dict['Delay ms'] = self.nt.pingTest('delay') res_dict['Quality /70'] = quality res_dict['Level dBms'] = level res_dict['Throughput Mbps'] = self.nt.pingTest('tput') self.results.append(res_dict) self.counter += 1 # Apply gathered information to a variable scanData = [] scanData2 = [] for k, v in res_dict.items(): # String for Text Area string = '%s\n%s\n' % (k, v) # String for scanArray string2 = '%s\n' % v # Append arrays scanData.append(string) scanData2.append(string2) # Store Information in an array self.scanArray.append(scanData2) scanData = ' '.join(scanData) scanData2 = ', '.join(scanData2) # Apply information to vtext Field if self.nt.ping_ip == None: self.scanInfo.setPlainText( "Scan Failed, Error!\n\nPlease check your wireless connection!" ) else: self.scanInfo.setPlainText("{} Test:\r\n\n {}\r\n ".format( self.nsewc[self.scanCount], scanData))
def __init__(self, config, range=30): threading.Thread.__init__(self) logger.debug('Initializing Controller RPC thread.') self.lock = threading.Lock() self.safeMode = True self.credential = None self.config = config self.hostname = hostname.hostname() server_secured_url = 'https://' + config.get( 'server', 'hostname') + ':' + config.get('server', 'secured_url_port') self.registerUrl = server_secured_url + '/agent/v1/register/' + self.hostname self.unregisterUrl = server_secured_url + '/agent/v1/unregister/' + self.hostname self.heartbeatUrl = server_secured_url + '/agent/v1/heartbeat/' + self.hostname self.netutil = NetUtil() self.responseId = -1 self.repeatRegistration = False self.cachedconnect = None self.range = range self.hasMappedComponents = True self.actionQueue = ActionQueue(self.config) self.actionQueue.start() self.register = Register(self.config) self.unregister = Unregister(self.config) self.heartbeat = Heartbeat(self.actionQueue, self.config)
def main(): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) (options, args) = parser.parse_args() setup_logging(options.verbose) default_cfg = { 'agent' : { 'prefix' : '/home/ambari' } } config = ConfigParser.RawConfigParser(default_cfg) bind_signal_handlers() if (len(sys.argv) >1) and sys.argv[1]=='stop': stop_agent() # Check for ambari configuration file. config = resolve_ambari_config() perform_prestart_checks() daemonize() killstaleprocesses() update_log_level(config) server_url = 'https://' + config.get('server', 'hostname') + ':' + config.get('server', 'url_port') print("Connecting to the server at " + server_url + "...") logger.info('Connecting to the server at: ' + server_url) # Wait until server is reachable netutil = NetUtil() netutil.try_to_connect(server_url, -1, logger) #Initiate security """ Check if security is enable if not then disable it""" logger.info("Creating certs") certMan = security.CertificateManager(config) certMan.initSecurity() # Launch Controller communication controller = Controller(config) controller.start() logger.info("finished")
def __init__(self, config): threading.Thread.__init__(self) logger.debug('Initializing Controller RPC thread.') self.lock = threading.Lock() self.safeMode = True self.credential = None self.config = config self.hostname = socket.gethostname() server_secured_url = 'https://' + config.get( 'server', 'hostname') + ':' + config.get('server', 'secured_url_port') self.registerUrl = server_secured_url + '/agent/register/' + self.hostname self.heartbeatUrl = server_secured_url + '/agent/heartbeat/' + self.hostname self.netutil = NetUtil()
def gatherData(self): ''' Method responsible for gathering data ''' # Returns NetUtil object for each NSEW test, in case gateway # changes with location self.nt = NetUtil() # Calls Ping method with arg ping, returns unused list p_results = self.nt.pingTest('ping') type(p_results) quality, level = self.nt.signalTest() res_dict = collections.OrderedDict() res_dict['GatewayIP'] = self.nt.ping_ip res_dict['GatewayMac'] = self.nt.gw_mac res_dict['PacketLoss %'] = self.nt.pingTest('loss') res_dict['Delay ms'] = self.nt.pingTest('delay') res_dict['Quality /70'] = quality res_dict['Level dBms'] = level res_dict['Throughput Mbps'] = self.nt.pingTest('tput') self.results.append(res_dict) self.counter += 1 # Apply gathered information to a variable scanData = [] scanData2 = [] for k, v in res_dict.items(): # String for Text Area string = '%s\n%s\n' % (k, v) # String for scanArray string2 = '%s\n' % v # Append arrays scanData.append(string) scanData2.append(string2) # Store Information in an array self.scanArray.append(scanData2) scanData = ' '.join(scanData) scanData2 = ', '.join(scanData2) # Apply information to vtext Field if self.nt.ping_ip == None: self.scanInfo.setPlainText("Scan Failed, Error!\n\nPlease check your wireless connection!") else: self.scanInfo.setPlainText("{} Test:\r\n\n {}\r\n ".format(self.nsewc[self.scanCount], scanData ))
def main(): parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", help="verbose log output", default=False) parser.add_option("-l", "--label", dest="label", help="label of the agent", default=None) parser.add_option("--zk-quorum", dest=Constants.ZK_QUORUM, help="Zookeeper Quorum", default=None) parser.add_option("--zk-reg-path", dest=Constants.ZK_REG_PATH, help="Zookeeper Registry Path", default=None) parser.add_option("--debug", dest="debug", help="Agent debug hint", default="") (options, args) = parser.parse_args() if not Constants.AGENT_WORK_ROOT in os.environ and not 'PWD' in os.environ: parser.error("AGENT_WORK_ROOT environment variable or PWD must be set.") if Constants.AGENT_WORK_ROOT in os.environ: options.root_folder = os.environ[Constants.AGENT_WORK_ROOT] else: # some launch environments do not end up setting all environment variables options.root_folder = os.environ['PWD'] if not 'AGENT_LOG_ROOT' in os.environ: parser.error("AGENT_LOG_ROOT environment variable must be set.") options.log_folder = os.environ['AGENT_LOG_ROOT'] all_log_folders = [x.strip() for x in options.log_folder.split(',')] if len(all_log_folders) > 1: options.log_folder = all_log_folders[0] # If there are multiple log folder, separate by comma, pick one if not options.label: parser.error("label is required."); if not IS_WINDOWS: bind_signal_handlers() # Check for configuration file. agentConfig = AgentConfig(options.root_folder, options.log_folder, options.label) update_config_from_file(agentConfig) # update configurations if needed if options.zk_quorum: agentConfig.set(AgentConfig.SERVER_SECTION, Constants.ZK_QUORUM, options.zk_quorum) if options.zk_reg_path: agentConfig.set(AgentConfig.SERVER_SECTION, Constants.ZK_REG_PATH, options.zk_reg_path) if options.debug: agentConfig.set(AgentConfig.AGENT_SECTION, AgentConfig.APP_DBG_CMD, options.debug) logFile = posixpath.join(agentConfig.getResolvedPath(AgentConfig.LOG_DIR), logFileName) setup_logging(options.verbose, logFile) update_log_level(agentConfig, logFile) secDir = posixpath.join(agentConfig.getResolvedPath(AgentConfig.RUN_DIR), "security") logger.info("Security/Keys directory: " + secDir) agentConfig.set(AgentConfig.SECURITY_SECTION, "keysdir", secDir) perform_prestart_checks(agentConfig) ensure_folder_layout(agentConfig) # create security dir if necessary ensure_path_exists(secDir) write_pid() logger.info("Using AGENT_WORK_ROOT = " + options.root_folder) logger.info("Using AGENT_LOG_ROOT = " + options.log_folder) if len(all_log_folders) > 1: logger.info("Selected log folder from available: " + ",".join(all_log_folders)) # Extract the AM hostname and secured port from ZK registry zk_lookup_tries = 0 while zk_lookup_tries < Constants.MAX_AM_CONNECT_RETRIES: registry = Registry(options.zk_quorum, options.zk_reg_path) amHost, amUnsecuredPort, amSecuredPort = registry.readAMHostPort() tryConnect = True if not amHost or not amSecuredPort or not amUnsecuredPort: logger.info("Unable to extract AM host details from ZK, retrying ...") tryConnect = False time.sleep(NetUtil.CONNECT_SERVER_RETRY_INTERVAL_SEC) if tryConnect: if amHost: agentConfig.set(AgentConfig.SERVER_SECTION, "hostname", amHost) if amSecuredPort: agentConfig.set(AgentConfig.SERVER_SECTION, "secured_port", amSecuredPort) if amUnsecuredPort: agentConfig.set(AgentConfig.SERVER_SECTION, "port", amUnsecuredPort) server_url = SERVER_STATUS_URL.format( agentConfig.get(AgentConfig.SERVER_SECTION, 'hostname'), agentConfig.get(AgentConfig.SERVER_SECTION, 'port'), agentConfig.get(AgentConfig.SERVER_SECTION, 'check_path')) print("Connecting to the server at " + server_url + "...") logger.info('Connecting to the server at: ' + server_url) # Wait until server is reachable and continue to query ZK netutil = NetUtil() retries = netutil.try_to_connect(server_url, 3, logger) if retries < 3: break; pass pass zk_lookup_tries += 1 pass # Launch Controller communication global controller controller = Controller(agentConfig) controller.start() try: while controller.is_alive(): controller.join(timeout=1.0) except (KeyboardInterrupt, SystemExit): logger.info("... agent interrupted") pass
def main(heartbeat_stop_callback=None): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname logging_level = logging.DEBUG if options.verbose else logging.INFO setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), logging_level) global is_logger_setup is_logger_setup = True setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level) Logger.initialize_logger('resource_management', logging_level=logging_level) # use the host's locale for numeric formatting try: locale.setlocale(locale.LC_ALL, '') except locale.Error as ex: logger.warning("Cannot set locale for ambari-agent. Please check your systemwide locale settings. Failed due to: {0}.".format(str(ex))) default_cfg = {'agent': {'prefix': '/home/ambari'}} config.load(default_cfg) if (len(sys.argv) > 1) and sys.argv[1] == 'stop': stop_agent() if (len(sys.argv) > 2) and sys.argv[1] == 'reset': reset_agent(sys.argv) # Check for ambari configuration file. resolve_ambari_config() # Add syslog hanlder based on ambari config file add_syslog_handler(logger) # Starting data cleanup daemon data_cleaner = None if config.has_option('agent', 'data_cleanup_interval') and int(config.get('agent','data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) # Starting ping port listener try: #This acts as a single process machine-wide lock (albeit incomplete, since # we still need an extra file to track the Agent PID) ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message) sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: daemonize() # # Iterate through the list of server hostnames and connect to the first active server # active_server = None server_hostnames = hostname.server_hostnames(config) connected = False stopped = False # Keep trying to connect to a server or bail out if ambari-agent was stopped while not connected and not stopped: for server_hostname in server_hostnames: try: server_ip = socket.gethostbyname(server_hostname) server_url = config.get_api_url(server_hostname) logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip) except socket.error: logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname) # Wait until MAX_RETRIES to see if server is reachable netutil = NetUtil(config, heartbeat_stop_callback) (retries, connected, stopped) = netutil.try_to_connect(server_url, MAX_RETRIES, logger) # if connected, launch controller if connected: logger.info('Connected to Ambari server %s', server_hostname) # Set the active server active_server = server_hostname # Launch Controller communication controller = Controller(config, server_hostname, heartbeat_stop_callback) controller.start() while controller.is_alive(): time.sleep(0.1) # # If Ambari Agent connected to the server or # Ambari Agent was stopped using stop event # Clean up if not Windows OS # if connected or stopped: ExitHelper().exit(0) logger.info("finished") break pass # for server_hostname in server_hostnames pass # while not (connected or stopped) return active_server
def main(heartbeat_stop_callback=None): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), options.verbose) global is_logger_setup is_logger_setup = True setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), options.verbose) default_cfg = {'agent': {'prefix': '/home/ambari'}} config.load(default_cfg) if (len(sys.argv) > 1) and sys.argv[1] == 'stop': stop_agent() if (len(sys.argv) > 2) and sys.argv[1] == 'reset': reset_agent(sys.argv) # Check for ambari configuration file. resolve_ambari_config() # Add syslog hanlder based on ambari config file add_syslog_handler(logger) # Starting data cleanup daemon data_cleaner = None if config.has_option('agent', 'data_cleanup_interval') and int(config.get('agent','data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) # Starting ping port listener try: #This acts as a single process machine-wide lock (albeit incomplete, since # we still need an extra file to track the Agent PID) ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message) sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) server_hostname = hostname.server_hostname(config) server_url = config.get_api_url() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: daemonize() try: server_ip = socket.gethostbyname(server_hostname) logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip) except socket.error: logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname) # Wait until server is reachable netutil = NetUtil(heartbeat_stop_callback) retries, connected = netutil.try_to_connect(server_url, -1, logger) # Ambari Agent was stopped using stop event if connected: # Launch Controller communication controller = Controller(config, heartbeat_stop_callback) controller.start() controller.join() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: ExitHelper.execute_cleanup() stop_agent() logger.info("finished")
def main(): parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", help="verbose log output", default=False) parser.add_option("-l", "--label", dest="label", help="label of the agent", default=None) parser.add_option("--host", dest="host", help="AppMaster host", default=None) parser.add_option("--port", dest="port", help="AppMaster port", default=None) (options, args) = parser.parse_args() if not 'AGENT_WORK_ROOT' in os.environ: parser.error("AGENT_WORK_ROOT environment variable must be set.") options.root_folder = os.environ['AGENT_WORK_ROOT'] if not 'AGENT_LOG_ROOT' in os.environ: parser.error("AGENT_LOG_ROOT environment variable must be set.") options.log_folder = os.environ['AGENT_LOG_ROOT'] if not options.label: parser.error("label is required.") bind_signal_handlers() # Check for configuration file. agentConfig = AgentConfig(options.root_folder, options.log_folder, options.label) update_config_from_file(agentConfig) # update configurations if needed if options.host: agentConfig.set(AgentConfig.SERVER_SECTION, "hostname", options.host) if options.port: agentConfig.set(AgentConfig.SERVER_SECTION, "port", options.port) logFile = os.path.join(agentConfig.getResolvedPath(AgentConfig.LOG_DIR), logFileName) perform_prestart_checks(agentConfig) ensure_folder_layout(agentConfig) setup_logging(options.verbose, logFile) update_log_level(agentConfig, logFile) write_pid() logger.info("Using AGENT_WORK_ROOT = " + options.root_folder) logger.info("Using AGENT_LOG_ROOT = " + options.log_folder) server_url = SERVER_STATUS_URL.format( agentConfig.get(AgentConfig.SERVER_SECTION, 'hostname'), agentConfig.get(AgentConfig.SERVER_SECTION, 'port'), agentConfig.get(AgentConfig.SERVER_SECTION, 'check_path')) print("Connecting to the server at " + server_url + "...") logger.info('Connecting to the server at: ' + server_url) # Wait until server is reachable netutil = NetUtil() netutil.try_to_connect(server_url, -1, logger) # Launch Controller communication controller = Controller(agentConfig) controller.start() controller.join() stop_agent() logger.info("... agent finished")
class wifi_class(QtGui.QMainWindow, Ui_MainWindow): ''' This is the Main Class which builds and processes the data required to run the program ''' # Initialize mega__class def __init__(self): QtGui.QMainWindow.__init__(self) # Call the UI Main window class self.setupUi(self) self.nextCount = 0 self.scanArray = [] self.setStyleSheet(" font-size: 10px; font-family: Ubuntu Light;") self.viewOne.setGeometry(QtCore.QRect(10, 10, 580, 580)) self.viewTwo.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.floorNext.setEnabled(True) self.floorNext.clicked.connect(self.next) self.roomNext.clicked.connect(self.next) # Link Actions self.groundFloor.clicked.connect(self.getFloorWing) self.firstFloor.clicked.connect(self.getFloorWing) self.secondFloor.clicked.connect(self.getFloorWing) self.u.clicked.connect(self.getFloorWing) self.v.clicked.connect(self.getFloorWing) self.w.clicked.connect(self.getFloorWing) self.x.clicked.connect(self.getFloorWing) self.y.clicked.connect(self.getFloorWing) self.z.clicked.connect(self.getFloorWing) self.csv.clicked.connect(self.enableSave) self.database.clicked.connect(self.enableSave) self.logFile.clicked.connect(self.enableSave) self.allFiles.clicked.connect(self.enableSave) self.saveFileBttn.clicked.connect(self.saveFile) self.restartButton.clicked.connect(self.resetProgram) self.exitButton.clicked.connect(self.closeProgram) # Build Room Data self.roomsU = [['', 'U103', 'U105', 'U107', 'U108', 'U110'], ['', 'U201', 'U211', 'U212', 'U213', 'U214'], ['', 'U301', 'U302', 'U303', 'U304', 'U305', 'U306', 'U309', 'U310']] self.roomsV = [['', 'V103', 'V104', 'V105', 'V106', 'V107', 'V108', 'V109'], ['', 'V203', 'V204', 'V205', 'V206', 'V207'], ['', 'V301', 'V302', 'V303', 'V304', 'V305', 'V306', 'V308', 'V311']] self.roomsW = [['', 'W Coffee Area','W101', 'W106', 'W107', 'W108'], ['', 'W201', 'W202', 'W205', 'W206', 'W207', 'W208'], ['', 'W301 MSC Lab', 'W304', 'W305']] self.roomsX = [['', 'X101', 'X101B', 'X106', 'X107', 'X108', 'X109'], ['', 'X203', 'X204', 'X205', 'X206', 'X207'], ['', 'X Head of Administration', 'X Head of Dept Office 2', 'X Head of Dept Office', 'X Head of School Office', 'X Meeting Room General', 'X School Admin General', 'X309', 'X310']] self.roomsY = [['', 'Y102', 'Y103', 'Y105', 'Y107'], ['', 'Y201', 'Y202', 'Y205', 'Y206', 'Y207'], ['', 'Y301', 'Y302', 'Y303', 'Y304', 'Y305', 'Y306', 'Y307', 'Y308']] self.roomsZ = [['','Z103', 'Z104', 'Z105', 'Z107'], ['', 'Z203', 'Z204', 'Z205', 'Z206', 'Z207'], ['', 'Z301', 'Z302', 'Z303', 'Z304', 'Z305', 'Z306', 'Z308']] # Load U by Default self.selectRoom.addItems(self.roomsU[0]) self.getRoom() # Monitor the ComboBox self.selectRoom.currentIndexChanged.connect(self.getRoom) self.scanButton.clicked.connect(self.scanUpdate) self.scanCount = 0 # Dictionary for results dictionary self.results = [] self.counter = 0 self.nsewc=["","North","South","East","West","Central"] # Gather the Room Information def getRoom(self): if self.selectRoom.currentText() == '': self.floorNext.setEnabled(False) else: self.floorNext.setEnabled(True) self.floorImage.setPixmap( QtGui.QPixmap( ("assets/rooms/" + str(self.selectRoom.currentText()) + ".jpg"))) self.room = self.selectRoom.currentText() self.fname = str( ('/' + self.room + '_' + time.strftime("%d-%m-%Y-%H:%M:%S"))) # Gather the Floor and Wing Information def getFloorWing(self): # Set the Floor Index if self.groundFloor.isChecked(): self.floor = 0 elif self.firstFloor.isChecked(): self.floor = 1 elif self.secondFloor.isChecked(): self.floor = 2 # Set the Room Information self.selectRoom.clear() if self.u.isChecked(): self.selectRoom.addItems(self.roomsU[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "U.jpg"))) elif self.v.isChecked(): self.selectRoom.addItems(self.roomsV[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "V.jpg"))) elif self.w.isChecked(): self.selectRoom.addItems(self.roomsW[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "W.jpg"))) elif self.x.isChecked(): self.selectRoom.addItems(self.roomsX[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "X.jpg"))) elif self.y.isChecked(): self.selectRoom.addItems(self.roomsY[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "Y.jpg"))) elif self.z.isChecked(): self.selectRoom.addItems(self.roomsZ[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "Z.jpg"))) # Turn the Page - Room Scan def next(self): if self.nextCount == 0: self.roomImage.setPixmap( QtGui.QPixmap( ("assets/rooms/" + str(self.selectRoom.currentText()) + ".jpg"))) self.viewOne.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewTwo.setGeometry(QtCore.QRect(10, 10, 580, 580)) self.nextCount += 1 else: self.viewOne.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewTwo.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 10, 580, 580)) # Force Column Widths self.dataTable.setColumnWidth(0, 90) self.dataTable.setColumnWidth(1, 105) self.dataTable.setColumnWidth(2, 50) self.dataTable.setColumnWidth(3, 65) self.dataTable.setColumnWidth(4, 50) self.dataTable.setColumnWidth(5, 75) # Build Table from Arrays x = 0 for item in self.scanArray: y = 0 for data in self.scanArray[x]: self.dataTable.setItem(x, y, QtGui.QTableWidgetItem(data)) y += 1 x += 1 # Initiate Scan Sequence def scanUpdate(self): self.scanCount += 1 if self.scanCount == 1: self.gatherData() self.scanButton.setText("Scan South") if self.scanCount == 2: self.gatherData() self.scanButton.setText("Scan East") if self.scanCount == 3: self.gatherData() self.scanButton.setText("Scan West") if self.scanCount == 4: self.gatherData() self.scanButton.setText("Scan Center") if self.scanCount == 5: self.gatherData() # Disable the Scan Button self.scanButton.setEnabled(False) self.scanButton.setText("SCAN COMPLETE") self.roomNext.setEnabled(True) def gatherData(self): ''' Method responsible for gathering data ''' # Returns NetUtil object for each NSEW test, in case gateway # changes with location self.nt = NetUtil() # Calls Ping method with arg ping, returns unused list p_results = self.nt.pingTest('ping') type(p_results) quality, level = self.nt.signalTest() res_dict = collections.OrderedDict() res_dict['GatewayIP'] = self.nt.ping_ip res_dict['GatewayMac'] = self.nt.gw_mac res_dict['PacketLoss %'] = self.nt.pingTest('loss') res_dict['Delay ms'] = self.nt.pingTest('delay') res_dict['Quality /70'] = quality res_dict['Level dBms'] = level res_dict['Throughput Mbps'] = self.nt.pingTest('tput') self.results.append(res_dict) self.counter += 1 # Apply gathered information to a variable scanData = [] scanData2 = [] for k, v in res_dict.items(): # String for Text Area string = '%s\n%s\n' % (k, v) # String for scanArray string2 = '%s\n' % v # Append arrays scanData.append(string) scanData2.append(string2) # Store Information in an array self.scanArray.append(scanData2) scanData = ' '.join(scanData) scanData2 = ', '.join(scanData2) # Apply information to vtext Field if self.nt.ping_ip == None: self.scanInfo.setPlainText("Scan Failed, Error!\n\nPlease check your wireless connection!") else: self.scanInfo.setPlainText("{} Test:\r\n\n {}\r\n ".format(self.nsewc[self.scanCount], scanData )) #if self.counter == 5: # nt.saveFile(self.fname, self.results) #Save File def enableSave(self): #Enabled the Save Button self.saveFileBttn.setEnabled(True) def saveFile(self): # nt=NetUtil() if self.csv.isChecked(): self.nt.saveFile(self.fname, self.results,2) elif self.database.isChecked(): self.nt.saveFile(self.fname, self.results,0) elif self.logFile.isChecked(): self.nt.saveFile(self.fname, self.results,1) elif self.allFiles.isChecked(): self.nt.saveFile(self.fname, self.results,4) #Reset The Program def resetProgram(self): self.viewTwo.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewOne.setGeometry(QtCore.QRect(10, 10, 580, 580)) self.nextCount = 0 self.scanCount = 0 self.scanArray = [] self.scanButton.setText("Scan South") self.scanButton.setEnabled(True) self.roomNext.setEnabled(False) #Close The Program def closeProgram(self): #Terminate the program self.close()
def main(): parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", help="verbose log output", default=False) parser.add_option("-l", "--label", dest="label", help="label of the agent", default=None) parser.add_option("--host", dest="host", help="AppMaster host", default=None) parser.add_option("--port", dest="port", help="AppMaster port", default=None) parser.add_option("--secured_port", dest="secured_port", help="AppMaster 2 Way port", default=None) parser.add_option("--debug", dest="debug", help="Agent debug hint", default="") (options, args) = parser.parse_args() if not 'AGENT_WORK_ROOT' in os.environ: parser.error("AGENT_WORK_ROOT environment variable must be set."); options.root_folder = os.environ['AGENT_WORK_ROOT'] if not 'AGENT_LOG_ROOT' in os.environ: parser.error("AGENT_LOG_ROOT environment variable must be set."); options.log_folder = os.environ['AGENT_LOG_ROOT'] if not options.label: parser.error("label is required."); bind_signal_handlers() # Check for configuration file. agentConfig = AgentConfig(options.root_folder, options.log_folder, options.label) update_config_from_file(agentConfig) # update configurations if needed if options.host: agentConfig.set(AgentConfig.SERVER_SECTION, "hostname", options.host) if options.port: agentConfig.set(AgentConfig.SERVER_SECTION, "port", options.port) if options.secured_port: agentConfig.set(AgentConfig.SERVER_SECTION, "secured_port", options.secured_port) if options.debug: agentConfig.set(AgentConfig.AGENT_SECTION, AgentConfig.APP_DBG_CMD, options.debug) # set the security directory to a subdirectory of the run dir secDir = os.path.join(agentConfig.getResolvedPath(AgentConfig.RUN_DIR), "security") logger.info("Security/Keys directory: " + secDir) agentConfig.set(AgentConfig.SECURITY_SECTION, "keysdir", secDir) logFile = os.path.join(agentConfig.getResolvedPath(AgentConfig.LOG_DIR), logFileName) perform_prestart_checks(agentConfig) ensure_folder_layout(agentConfig) # create security dir if necessary ensure_path_exists(secDir) setup_logging(options.verbose, logFile) update_log_level(agentConfig, logFile) write_pid() logger.info("Using AGENT_WORK_ROOT = " + options.root_folder) logger.info("Using AGENT_LOG_ROOT = " + options.log_folder) server_url = SERVER_STATUS_URL.format( agentConfig.get(AgentConfig.SERVER_SECTION, 'hostname'), agentConfig.get(AgentConfig.SERVER_SECTION, 'port'), agentConfig.get(AgentConfig.SERVER_SECTION, 'check_path')) print("Connecting to the server at " + server_url + "...") logger.info('Connecting to the server at: ' + server_url) # Wait until server is reachable netutil = NetUtil() netutil.try_to_connect(server_url, -1, logger) # Launch Controller communication controller = Controller(agentConfig) controller.start() try: while controller.is_alive(): controller.join(timeout=1.0) except (KeyboardInterrupt, SystemExit): logger.info("... agent interrupted") pass
def main(heartbeat_stop_callback=None): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname current_user = getpass.getuser() setup_logging(options.verbose) default_cfg = {'agent': {'prefix': '/home/ambari'}} config.load(default_cfg) bind_signal_handlers(agentPid) if (len(sys.argv) > 1) and sys.argv[1] == 'stop': stop_agent() if (len(sys.argv) > 2) and sys.argv[1] == 'reset': reset_agent(sys.argv) # Check for ambari configuration file. resolve_ambari_config() # Starting data cleanup daemon data_cleaner = None if config.has_option('agent', 'data_cleanup_interval') and int(config.get('agent','data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) # Starting ping port listener try: #This acts as a single process machine-wide lock (albeit incomplete, since # we still need an extra file to track the Agent PID) ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message) sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) server_hostname = config.get('server', 'hostname') server_url = config.get_api_url() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: daemonize() try: server_ip = socket.gethostbyname(server_hostname) logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip) except socket.error: logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname) # Wait until server is reachable netutil = NetUtil(heartbeat_stop_callback) retries, connected = netutil.try_to_connect(server_url, -1, logger) # Ambari Agent was stopped using stop event if connected: # Launch Controller communication controller = Controller(config, heartbeat_stop_callback) controller.start() controller.join() if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: stop_agent() logger.info("finished")
class AmbariConfig: TWO_WAY_SSL_PROPERTY = "security.server.two_way_ssl" CONFIG_FILE = "/etc/ambari-agent/conf/ambari-agent.ini" SERVER_CONNECTION_INFO = "{0}/connection_info" CONNECTION_PROTOCOL = "https" config = None net = None def __init__(self): global content self.config = ConfigParser.RawConfigParser() self.net = NetUtil() self.config.readfp(StringIO.StringIO(content)) def get(self, section, value): return self.config.get(section, value) def set(self, section, option, value): self.config.set(section, option, value) def add_section(self, section): self.config.add_section(section) def setConfig(self, customConfig): self.config = customConfig def getConfig(self): return self.config def getRolesToClass(self): global rolesToClass return rolesToClass def getServiceStates(self): global serviceStates return serviceStates def getServicesToPidNames(self): global servicesToPidNames return servicesToPidNames def getImports(self): global imports return imports def getPidPathesVars(self): global pidPathesVars return pidPathesVars def has_option(self, section, option): return self.config.has_option(section, option) def remove_option(self, section, option): return self.config.remove_option(section, option) def load(self, data): self.config = ConfigParser.RawConfigParser(data) def read(self, filename): self.config.read(filename) def getServerOption(self, url, name, default=None): status, response = self.net.checkURL(url) if status is True: try: data = json.loads(response) if name in data: return data[name] except: pass return default def get_api_url(self): return "%s://%s:%s" % (self.CONNECTION_PROTOCOL, self.get('server', 'hostname'), self.get('server', 'url_port')) def isTwoWaySSLConnection(self): req_url = self.get_api_url() response = self.getServerOption( self.SERVER_CONNECTION_INFO.format(req_url), self.TWO_WAY_SSL_PROPERTY, 'false') if response is None: return False elif response.lower() == "true": return True else: return False
def __init__(self): global content self.config = ConfigParser.RawConfigParser() self.net = NetUtil() self.config.readfp(StringIO.StringIO(content))
def main(): global config parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option("-e", "--expected-hostname", dest="expected_hostname", action="store", help="expected hostname of current host. If hostname differs, agent will fail", default=None) (options, args) = parser.parse_args() expected_hostname = options.expected_hostname setup_logging(options.verbose) default_cfg = {'agent': {'prefix': '/home/ambari'}} config.load(default_cfg) bind_signal_handlers() if (len(sys.argv) > 1) and sys.argv[1] == 'stop': stop_agent() # Check for ambari configuration file. config = resolve_ambari_config() # Starting data cleanup daemon data_cleaner = None if int(config.get('agent', 'data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) daemonize() # Starting ping port listener try: ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message) sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) server_hostname = config.get('server', 'hostname') server_url = config.get_api_url() try: server_ip = socket.gethostbyname(server_hostname) logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip) except socket.error: logger.warn("Unable to determine the IP address of the Ambari server '%s'", server_hostname) # Wait until server is reachable netutil = NetUtil() netutil.try_to_connect(server_url, -1, logger) # Launch Controller communication controller = Controller(config) controller.start() controller.join() stop_agent() logger.info("finished")
def main(heartbeat_stop_callback=None): global config global home_dir parser = OptionParser() parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="verbose log output", default=False) parser.add_option( "-e", "--expected-hostname", dest="expected_hostname", action="store", help= "expected hostname of current host. If hostname differs, agent will fail", default=None) parser.add_option("--home", dest="home_dir", action="store", help="Home directory", default="") (options, args) = parser.parse_args() expected_hostname = options.expected_hostname home_dir = options.home_dir logging_level = logging.DEBUG if options.verbose else logging.INFO setup_logging(logger, AmbariConfig.AmbariConfig.getLogFile(), logging_level) global is_logger_setup is_logger_setup = True setup_logging(alerts_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level) Logger.initialize_logger('resource_management', logging_level=logging_level) if home_dir != "": # When running multiple Ambari Agents on this host for simulation, each one will use a unique home directory. Logger.info("Agent is using Home Dir: %s" % str(home_dir)) # use the host's locale for numeric formatting try: locale.setlocale(locale.LC_ALL, '') except locale.Error as ex: logger.warning( "Cannot set locale for ambari-agent. Please check your systemwide locale settings. Failed due to: {0}." .format(str(ex))) default_cfg = {'agent': {'prefix': '/home/ambari'}} config.load(default_cfg) if (len(sys.argv) > 1) and sys.argv[1] == 'stop': stop_agent() if (len(sys.argv) > 2) and sys.argv[1] == 'reset': reset_agent(sys.argv) # Check for ambari configuration file. resolve_ambari_config() # Add syslog hanlder based on ambari config file add_syslog_handler(logger) # Starting data cleanup daemon data_cleaner = None if config.has_option('agent', 'data_cleanup_interval') and int( config.get('agent', 'data_cleanup_interval')) > 0: data_cleaner = DataCleaner(config) data_cleaner.start() perform_prestart_checks(expected_hostname) # Starting ping port listener try: #This acts as a single process machine-wide lock (albeit incomplete, since # we still need an extra file to track the Agent PID) ping_port_listener = PingPortListener(config) except Exception as ex: err_message = "Failed to start ping port listener of: " + str(ex) logger.error(err_message) sys.stderr.write(err_message) sys.exit(1) ping_port_listener.start() update_log_level(config) update_open_files_ulimit(config) if not config.use_system_proxy_setting(): logger.info('Agent is configured to ignore system proxy settings') reconfigure_urllib2_opener(ignore_system_proxy=True) if not OSCheck.get_os_family() == OSConst.WINSRV_FAMILY: daemonize() # # Iterate through the list of server hostnames and connect to the first active server # active_server = None server_hostnames = hostname.server_hostnames(config) connected = False stopped = False # Keep trying to connect to a server or bail out if ambari-agent was stopped while not connected and not stopped: for server_hostname in server_hostnames: server_url = config.get_api_url(server_hostname) try: server_ip = socket.gethostbyname(server_hostname) logger.info('Connecting to Ambari server at %s (%s)', server_url, server_ip) except socket.error: logger.warn( "Unable to determine the IP address of the Ambari server '%s'", server_hostname) # Wait until MAX_RETRIES to see if server is reachable netutil = NetUtil(config, heartbeat_stop_callback) (retries, connected, stopped) = netutil.try_to_connect(server_url, MAX_RETRIES, logger) # if connected, launch controller if connected: logger.info('Connected to Ambari server %s', server_hostname) # Set the active server active_server = server_hostname # Launch Controller communication run_threads(server_hostname, heartbeat_stop_callback) # # If Ambari Agent connected to the server or # Ambari Agent was stopped using stop event # Clean up if not Windows OS # if connected or stopped: ExitHelper().exit(0) logger.info("finished") break pass # for server_hostname in server_hostnames pass # while not (connected or stopped) return active_server
class wifi_class(QtGui.QMainWindow, Ui_MainWindow): ''' This is the Main Class which builds and processes the data required to run the program ''' # Initialize mega__class def __init__(self): QtGui.QMainWindow.__init__(self) # Call the UI Main window class self.setupUi(self) self.nextCount = 0 self.scanArray = [] self.setStyleSheet(" font-size: 10px; font-family: Ubuntu Light;") self.viewOne.setGeometry(QtCore.QRect(10, 10, 580, 580)) self.viewTwo.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.floorNext.setEnabled(True) self.floorNext.clicked.connect(self.next) self.roomNext.clicked.connect(self.next) # Link Actions self.groundFloor.clicked.connect(self.getFloorWing) self.firstFloor.clicked.connect(self.getFloorWing) self.secondFloor.clicked.connect(self.getFloorWing) self.u.clicked.connect(self.getFloorWing) self.v.clicked.connect(self.getFloorWing) self.w.clicked.connect(self.getFloorWing) self.x.clicked.connect(self.getFloorWing) self.y.clicked.connect(self.getFloorWing) self.z.clicked.connect(self.getFloorWing) self.csv.clicked.connect(self.enableSave) self.database.clicked.connect(self.enableSave) self.logFile.clicked.connect(self.enableSave) self.allFiles.clicked.connect(self.enableSave) self.saveFileBttn.clicked.connect(self.saveFile) self.restartButton.clicked.connect(self.resetProgram) self.exitButton.clicked.connect(self.closeProgram) # Build Room Data self.roomsU = [['', 'U103', 'U105', 'U107', 'U108', 'U110'], ['', 'U201', 'U211', 'U212', 'U213', 'U214'], [ '', 'U301', 'U302', 'U303', 'U304', 'U305', 'U306', 'U309', 'U310' ]] self.roomsV = [[ '', 'V103', 'V104', 'V105', 'V106', 'V107', 'V108', 'V109' ], ['', 'V203', 'V204', 'V205', 'V206', 'V207'], [ '', 'V301', 'V302', 'V303', 'V304', 'V305', 'V306', 'V308', 'V311' ]] self.roomsW = [['', 'W Coffee Area', 'W101', 'W106', 'W107', 'W108'], ['', 'W201', 'W202', 'W205', 'W206', 'W207', 'W208'], ['', 'W301 MSC Lab', 'W304', 'W305']] self.roomsX = [['', 'X101', 'X101B', 'X106', 'X107', 'X108', 'X109'], ['', 'X203', 'X204', 'X205', 'X206', 'X207'], [ '', 'X Head of Administration', 'X Head of Dept Office 2', 'X Head of Dept Office', 'X Head of School Office', 'X Meeting Room General', 'X School Admin General', 'X309', 'X310' ]] self.roomsY = [['', 'Y102', 'Y103', 'Y105', 'Y107'], ['', 'Y201', 'Y202', 'Y205', 'Y206', 'Y207'], [ '', 'Y301', 'Y302', 'Y303', 'Y304', 'Y305', 'Y306', 'Y307', 'Y308' ]] self.roomsZ = [['', 'Z103', 'Z104', 'Z105', 'Z107'], ['', 'Z203', 'Z204', 'Z205', 'Z206', 'Z207'], [ '', 'Z301', 'Z302', 'Z303', 'Z304', 'Z305', 'Z306', 'Z308' ]] # Load U by Default self.selectRoom.addItems(self.roomsU[0]) self.getRoom() # Monitor the ComboBox self.selectRoom.currentIndexChanged.connect(self.getRoom) self.scanButton.clicked.connect(self.scanUpdate) self.scanCount = 0 # Dictionary for results dictionary self.results = [] self.counter = 0 self.nsewc = ["", "North", "South", "East", "West", "Central"] # Gather the Room Information def getRoom(self): if self.selectRoom.currentText() == '': self.floorNext.setEnabled(False) else: self.floorNext.setEnabled(True) self.floorImage.setPixmap( QtGui.QPixmap(("assets/rooms/" + str(self.selectRoom.currentText()) + ".jpg"))) self.room = self.selectRoom.currentText() self.fname = str( ('/' + self.room + '_' + time.strftime("%d-%m-%Y-%H:%M:%S"))) # Gather the Floor and Wing Information def getFloorWing(self): # Set the Floor Index if self.groundFloor.isChecked(): self.floor = 0 elif self.firstFloor.isChecked(): self.floor = 1 elif self.secondFloor.isChecked(): self.floor = 2 # Set the Room Information self.selectRoom.clear() if self.u.isChecked(): self.selectRoom.addItems(self.roomsU[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "U.jpg"))) elif self.v.isChecked(): self.selectRoom.addItems(self.roomsV[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "V.jpg"))) elif self.w.isChecked(): self.selectRoom.addItems(self.roomsW[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "W.jpg"))) elif self.x.isChecked(): self.selectRoom.addItems(self.roomsX[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "X.jpg"))) elif self.y.isChecked(): self.selectRoom.addItems(self.roomsY[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "Y.jpg"))) elif self.z.isChecked(): self.selectRoom.addItems(self.roomsZ[self.floor]) self.floorImage.setPixmap( QtGui.QPixmap(("assets/" + str(self.floor) + "Z.jpg"))) # Turn the Page - Room Scan def next(self): if self.nextCount == 0: self.roomImage.setPixmap( QtGui.QPixmap(("assets/rooms/" + str(self.selectRoom.currentText()) + ".jpg"))) self.viewOne.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewTwo.setGeometry(QtCore.QRect(10, 10, 580, 580)) self.nextCount += 1 else: self.viewOne.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewTwo.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 10, 580, 580)) # Force Column Widths self.dataTable.setColumnWidth(0, 90) self.dataTable.setColumnWidth(1, 105) self.dataTable.setColumnWidth(2, 50) self.dataTable.setColumnWidth(3, 65) self.dataTable.setColumnWidth(4, 50) self.dataTable.setColumnWidth(5, 75) # Build Table from Arrays x = 0 for item in self.scanArray: y = 0 for data in self.scanArray[x]: self.dataTable.setItem(x, y, QtGui.QTableWidgetItem(data)) y += 1 x += 1 # Initiate Scan Sequence def scanUpdate(self): self.scanCount += 1 if self.scanCount == 1: self.gatherData() self.scanButton.setText("Scan South") if self.scanCount == 2: self.gatherData() self.scanButton.setText("Scan East") if self.scanCount == 3: self.gatherData() self.scanButton.setText("Scan West") if self.scanCount == 4: self.gatherData() self.scanButton.setText("Scan Center") if self.scanCount == 5: self.gatherData() # Disable the Scan Button self.scanButton.setEnabled(False) self.scanButton.setText("SCAN COMPLETE") self.roomNext.setEnabled(True) def gatherData(self): ''' Method responsible for gathering data ''' # Returns NetUtil object for each NSEW test, in case gateway # changes with location self.nt = NetUtil() # Calls Ping method with arg ping, returns unused list p_results = self.nt.pingTest('ping') type(p_results) quality, level = self.nt.signalTest() res_dict = collections.OrderedDict() res_dict['GatewayIP'] = self.nt.ping_ip res_dict['GatewayMac'] = self.nt.gw_mac res_dict['PacketLoss %'] = self.nt.pingTest('loss') res_dict['Delay ms'] = self.nt.pingTest('delay') res_dict['Quality /70'] = quality res_dict['Level dBms'] = level res_dict['Throughput Mbps'] = self.nt.pingTest('tput') self.results.append(res_dict) self.counter += 1 # Apply gathered information to a variable scanData = [] scanData2 = [] for k, v in res_dict.items(): # String for Text Area string = '%s\n%s\n' % (k, v) # String for scanArray string2 = '%s\n' % v # Append arrays scanData.append(string) scanData2.append(string2) # Store Information in an array self.scanArray.append(scanData2) scanData = ' '.join(scanData) scanData2 = ', '.join(scanData2) # Apply information to vtext Field if self.nt.ping_ip == None: self.scanInfo.setPlainText( "Scan Failed, Error!\n\nPlease check your wireless connection!" ) else: self.scanInfo.setPlainText("{} Test:\r\n\n {}\r\n ".format( self.nsewc[self.scanCount], scanData)) #if self.counter == 5: # nt.saveFile(self.fname, self.results) #Save File def enableSave(self): #Enabled the Save Button self.saveFileBttn.setEnabled(True) def saveFile(self): # nt=NetUtil() if self.csv.isChecked(): self.nt.saveFile(self.fname, self.results, 2) elif self.database.isChecked(): self.nt.saveFile(self.fname, self.results, 0) elif self.logFile.isChecked(): self.nt.saveFile(self.fname, self.results, 1) elif self.allFiles.isChecked(): self.nt.saveFile(self.fname, self.results, 4) #Reset The Program def resetProgram(self): self.viewTwo.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewThree.setGeometry(QtCore.QRect(10, 600, 580, 580)) self.viewOne.setGeometry(QtCore.QRect(10, 10, 580, 580)) self.nextCount = 0 self.scanCount = 0 self.scanArray = [] self.scanButton.setText("Scan South") self.scanButton.setEnabled(True) self.roomNext.setEnabled(False) #Close The Program def closeProgram(self): #Terminate the program self.close()