def get_update(key, value, port=2208, user="******"): global res redis_obj = get_redis() ssh_obj = Ssh(value, 2208, "master", redis_obj.get(value)) try: ssh_obj.connect() result, err = ssh_obj.cmd( ''' grep 'Up' `ls -rt /ss/login/log/login*|tail -1` ''') update = result.strip() res[key] = update except Exception as e: res[key] = 'error' get_logger().error("pass is wrong") pass
def modify_iptables(cmd_str,key,value,port=2208,user="******"): global ans redis_obj=get_redis() ssh_obj=Ssh(value,2208,user,redis_obj.hget(user,value)) try: ssh_obj.connect() result,err=ssh_obj.cmd(cmd_str,sudo=True) if not err.strip(): ans[key]='sucess' else: print err except Exception as e: ans[key]='wrong' pass
def get_gamewall(key,value,port=2208,user="******"): global res redis_obj=get_redis() ssh_obj=Ssh(value,2208,user,redis_obj.get(value)) try: ssh_obj.connect() result,err=ssh_obj.cmd('''cat /etc/sysconfig/iptables|grep '#'|wc -l ''',sudo=True) wall_num=result.strip() if wall_num == '2': res[key]='open' else: res[key]='close' except Exception as e: res[key]='wrong' get_logger().error("pass is wrong") pass
def get_cron(key, value, port=2208, user="******"): global res redis_obj = get_redis() ssh_obj = Ssh(value, 2208, "master", redis_obj.get(value)) try: ssh_obj.connect() result, err = ssh_obj.cmd('''cat /etc/crontab|wc -l ''', sudo=True) wall_num = result.strip() res[key] = wall_num except Exception as e: res[key] = 'wrong' get_logger().error("pass is wrong") pass ssh_obj.close()
def get_version(key, value, port=2208, user="******"): ver = {} #global ver redis_obj = get_redis() ssh_obj = Ssh(value, port, user, redis_obj.get(value)) ssh_obj.connect() try: result, err = ssh_obj.cmd('''cat /ss/login/ver|grep name ''') version = result.strip().split()[2] ver[key] = version except Exception as e: ver[key] = 'error' pass ssh_obj.close() return ver
def get_gamestatus(key, value, port=2208, user="******"): redis_obj = get_redis() global res ssh_obj = Ssh(value, 2208, "master", redis_obj.get(value)) try: ssh_obj.connect() result, err = ssh_obj.cmd('ps -ef|grep server|grep -v grep|wc -l') result = result.strip() if result == '6': res[key] = 'ok' else: res[key] = 'error' except Exception as e: res[key] = 'pass wrong' get_logger().error("pass is wrong") pass ssh_obj.close()
def modify_iptables(res, cmd_str, key, value, port=2208, user="******"): redis_obj = get_redis() ssh_obj = Ssh(value, 2208, user, redis_obj.hget(user, value)) try: ssh_obj.connect() result, err = ssh_obj.cmd(cmd_str, sudo=True) if not err.strip(): cmd_str = '''/etc/init.d/iptables restart ''' result, err = ssh_obj.cmd(cmd_str, sudo=True) if err.strip(): res[key] = err else: res[key] = result except Exception as e: res[key] = 'pass is wrong' pass