def check_paramiko(): r_handle = os.popen('python -c "import paramiko;"') result = r_handle.read() r_handle.close() if result.find('No module named') == -1: info(u'paramiko包检查结果:正常。') else: err(u'paramiko包检查结果:异常,请手动安装,否则会导致无法自动清理存储空间。')
def check_network_connection(): r_handle_in = os.popen("ping -c 1 sc.parkingwang.com") result = r_handle_in.read() r_handle_in.close() lost_per = '' index = result.rfind('% packet loss,') if index != -1: index_begin = result[:index].rfind(' ') if index_begin != -1: lost_per = result[index_begin + 1:index] if lost_per and int(lost_per) > 0: err(u'外网检测异常,请检查网络连接和DNS。') else: info(u'外网检测正常。')
def main(): start() try: charge_no = sys.argv[1] log_date = sys.argv[2] log_date = datetime.datetime.strptime(log_date, '%Y-%m-%d').date() lines = read_log_lines(LogFile.IData, log_date) if not lines: raise Exception('Read nothing from log') sync_info = sync_info_extract(lines, charge_no) info(sync_info.__repr__()) except Exception, e: err('%s\n%s' % (str(e), traceback()))
def check_disk_space(): r_handle = os.popen('df -hl') result = r_handle.read() r_handle.close() # debug(result) patt = re.compile('.*?/dev/root.*?(\d+)%.*?', re.I) temp = patt.findall(result) if temp: value = int(temp[0]) if value > 90: err(u'磁盘占用:%i%%, 存储满,请手动清理。' % value) else: info(u'磁盘占用:%i%%, 正常。' % value) else: err(u'磁盘空间检查失败,无法获取到磁盘占用')
def check_vpr_config(db_cursor, local_ip, db_ip): cp = ConfigParser.ConfigParser() cp.read('/home/park/config/config.cfg') vpr_in_cfg = cp.get('vpr', 'in_ip').strip() vpr_in_cfg2 = cp.get('vpr', 'in_ip2').strip() vpr_out_cfg = cp.get('vpr', 'out_ip').strip() vpr_out_cfg2 = cp.get('vpr', 'out_ip2').strip() vpr_type = cp.get('vpr', 'vpr_type').strip() db_server = cp.get('mysql', 'host').strip() db_cursor.execute( 'select depot_site.vpr_ip, depot_site.vpr_1_ip from depot_site,depot_terminal where depot_site.terminal_id = ' 'depot_terminal.id and depot_terminal.ip = "%s" and depot_site.is_in_site = 1; ' % local_ip) value = db_cursor.fetchall() if value: vpr_in_db = value[0][0].strip() vpr_in_db2 = value[0][1].strip() else: vpr_in_db = '' vpr_in_db2 = '' db_cursor.execute( 'select depot_site.vpr_ip, depot_site.vpr_1_ip from depot_site,depot_terminal where ' 'depot_site.terminal_id = depot_terminal.id and depot_terminal.ip = "%s" and depot_site.is_in_site = 0; ' % local_ip) value = db_cursor.fetchall() if value: vpr_out_db = value[0][0].strip() vpr_out_db2 = value[0][1].strip() else: vpr_out_db = '' vpr_out_db2 = '' flag = 0 if vpr_in_cfg != vpr_in_db: err(u'进口主相机ip配置不一致,页面配置值:%s,config文件值:%s,请同步页面配置值到config.cfg文件。' % (vpr_in_db, vpr_in_cfg)) flag = 1 if vpr_in_cfg2 != vpr_in_db2: err(u'进口辅相机ip配置不一致,页面配置值:%s,config文件值:%s,请同步页面配置值到config.cfg文件。' % (vpr_in_db2, vpr_in_cfg2)) flag = 1 if vpr_out_cfg != vpr_out_db: err(u'出口主相机ip配置不一致,页面配置值:%s,config文件值:%s,请同步页面配置值到config.cfg文件。' % (vpr_out_db, vpr_out_cfg)) flag = 1 if vpr_out_cfg2 != vpr_out_db2: err(u'出口辅相机ip配置不一致,页面配置值:%s,config文件值:%s,请同步页面配置值到config.cfg文件。' % (vpr_out_db2, vpr_out_cfg2)) flag = 1 if not flag: info(u'V3 相机配置一致性检查结果:正常。')
def main(): local_ip = get_local_ip() set_prefix(local_ip) progress(5, '本机地址: %s' % local_ip) db_ip, db_port = get_mysql_addr() progress(15, '数据库地址: %s:%d' % (db_ip, db_port)) try: check_disk_space() conn = MySQLdb.connect(host=db_ip, user='******', passwd='iraindb10241GB', db='irain_park', charset='utf8') cursor = conn.cursor() cursor.execute( 'select depot_terminal.name from depot_terminal where depot_terminal.ip = "%s"; ' % local_ip) name = cursor.fetchall() progress(20, "板子名称:%s" % name[0]) check_processes() progress(30) check_vpr_config(cursor, local_ip, db_ip) progress(40) check_boa_and_serial(cursor, local_ip) progress(50) check_paramiko() progress(60) check_network_connection() progress(70) check_rinetd() progress(80) check_link_file() except Exception, e: err("exception![%s]\n%s" % (str(e), traceback.format_exc()))
def check_link_file(): r_handle = os.popen( '''python -c "import os,sys,irain_lib; print sys.modules['irain_lib'].__version__"''' ) result = r_handle.read().strip() r_handle.close() info('版本检查: %s' % result) err_list = [] file_list = [ '/usr/local/lib/python2.7/dist-packages/irain_park-%s-py2.7.egg/irain_web/app/static/xls' % result ] for item in file_list: if not (not os.path.isfile(item) and os.path.exists(item)): err_list.append(item) if not err_list: info(u'V3 链接文件检查结果:正常。') else: err(u'V3 链接文件检查结果:异常,缺少以下文件:%s。' % err_list)
def main(): start() try: vpr = sys.argv[1] log_datetime = sys.argv[2] log_datetime = datetime.datetime.strptime(log_datetime, '%Y-%m-%d %H:%M:%S') lines = read_log_lines(LogFile.ParkOut, log_datetime.date()) if not lines: raise Exception('Read nothing from log') park_info = extract_park_info(lines, vpr, log_datetime) if u'出场方式' not in park_info: if u'出口报费' in park_info and park_info[u'出口报费'] == 0: park_info[u'出场方式'] = u'自动抬杆出场' else: park_info[u'出场方式'] = u'未知' info(park_info.__repr__()) except Exception, e: err('%s\n%s' % (str(e), traceback()))
def check_boa_and_serial(db_cursor, local_ip): db_cursor.execute("select id from depot_terminal where ip = '%s'" % local_ip) terminal_id = db_cursor.fetchall()[0][0] db_cursor.execute( 'select conf_value from depot_terminal_detail where terminal_id = %d and conf_type = "img_server_port";' % terminal_id) boa_port_conf = '' value = db_cursor.fetchall() if value: boa_port_conf = value[0][0] with open('/etc/boa/boa.conf', 'rb') as r_handle: text = r_handle.read() patt = re.compile('.*?Port\s+(\d+).*?', re.I) temp = patt.findall(text) value = '' if temp: value = temp[0] if boa_port_conf == value: info(u'boa 配置检查结果, 正常。') else: err(u'boa 配置检查结果:错误,系统配置值:%s, boa.conf配置值:%s' % (boa_port_conf, value)) serial_trans_flag = '0' db_cursor.execute( 'select conf_value from depot_terminal_detail where terminal_id = %d and conf_type = ' '"serial_trans_camera_flag"; ' % terminal_id) boa_port_conf = '' value = db_cursor.fetchall() if value: serial_trans_flag = value[0][0] if serial_trans_flag == '1': info(u'车场透传标志校验结果:正常。') else: err(u'车场透传标志校验结果:未开启,请确认此终端是否为非透传模式。')
def check_processes(): r_handle = os.popen("ps -ef|grep python") result = r_handle.read() r_handle.close() err_proc_list = [] # key_list = ['mails', 'code', 'codes', 'exchange'] key_list = [ 'irain_park', 'irain_web', 'irain_websocket', 'irain_sync', 'irain_celery' ] for item in key_list: if result.find(item) == -1: err_proc_list.append(item) r_handle = os.popen("ps -ef|grep vpr_ser") result = r_handle.read() r_handle.close() if result.find('vpr_server') == -1: err_proc_list.append('vpr_server') if not err_proc_list: info(u'关键进程检查结果:正常。') else: err(u'关键进程检查结果:异常,缺少以下关键进程:%s。' % err_proc_list)
ssh.connect(ip, port, name, pwd, timeout=20) return ssh if __name__ == "__main__": progress(0) start() try: db_ip, db_port = get_mysql_addr() arm_ip = os.popen( "ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}' | head -1" ).read() except Exception as e: err("init param exception %s\n%s" % (e, traceback.format_exc())) try: info("mysqldump start") tool_run_time = time.strftime('%Y%m%d_%H%M%S', time.localtime()) ssh = active_connect(str(arm_ip), 22, "root", "iraindev10241GB") ssh.exec_command( "mysqldump -h%s -uroot -piraindb10241GB irain_park new_auth_charge > /home/park/new_auth_charge_%s.sql" % (db_ip, tool_run_time)) info("mysqldump new_auth_charge end") except Exception as e: err("dump new_auth_charge failed:%s" % e)
import traceback import MySQLdb import sys from helper import info, start, end, err, progress, get_mysql_addr if __name__ == "__main__": progress(0) start() try: db_ip, db_port = get_mysql_addr() abnomal_num = sys.argv[1] except Exception as e: err("init param exception %s\n%s" % (e, traceback.format_exc())) try: conn = MySQLdb.connect(host=db_ip, port=db_port, user='******', passwd='iraindb10241GB', db='irain_park', charset='utf8') except Exception as e: err("connect mysql exception %s\n%s" % (e, traceback.format_exc())) try: cursor = conn.cursor() cursor.execute( "update project_conf set value = %s where name = 'abnormal_inout_display_num';"
start() db_user = '******' db_pwd = 'iraindb10241GB' progress(5, '开始获取数据库地址') db_ip, db_port = get_mysql_addr() progress(10, '获取成功') info('数据库 %s : %d' % (db_ip, db_port)) if not os.path.exists(bak_dir): progress(25, '未找到 %s 目录,自动创建该目录' % bak_dir) os.makedirs(bak_dir) progress(40, '开始进行备份,过程中将使得数据库不可用,进出车将无法正常工作') f_path = os.path.join( bak_dir, '%s.sql' % str(datetime.datetime.now()).replace(' ', '_')) os.system('mysqldump -u%s -p%s -h%s irain_park > %s' % (db_user, db_pwd, db_ip, f_path)) progress(95, '备份成功') progress(98, '备份文件地址:%s:%s' % (get_local_ip(), f_path)) end() except Exception, e: err(e) err(traceback()) end()
import traceback import time import sys import os from helper import info, start, end, err, progress, get_mysql_addr, get_local_ip if __name__ == "__main__": progress(0) start() try: db_ip, db_port = get_mysql_addr() end_time = sys.argv[1] except Exception as e: err("init param exception %s\n%s" % (e, traceback.format_exc())) try: if not os.path.exists("./db_dump"): os.mkdir("./db_dump") tool_run_time = time.strftime('%Y%m%d_%H%M%S', time.localtime()) f_path = os.path.join("./db_dump", "irain_parkin_inside_'%s'.sql" % tool_run_time) os.system( "mysqldump - h'%s' - uroot - piraindb10241GB irain_park park_in park_inside " "> %s" % (db_ip, f_path)) info("dump park_inside success: %s: %s" % (get_local_ip(), f_path)) except Exception as e: err("dump mysql park_inside failed")
import traceback import MySQLdb import paramiko from helper import info, start, end, err, progress, get_mysql_addr import threading if __name__ == "__main__": progress(0) start() try: db_ip, db_port = get_mysql_addr() except Exception as e: err("init param exception %s\n%s" % (e, traceback.format_exc())) try: conn = MySQLdb.connect(host=db_ip, port=db_port, user='******', passwd='iraindb10241GB', db='irain_park', charset='utf8') except Exception as e: err("connect mysql exception %s\n%s" % (e, traceback.format_exc())) try: cursor = conn.cursor() cursor.execute("SELECT ip FROM depot_terminal;") ip_list = cursor.fetchall() except Exception as e: err("check terminal ip failuer %s\n%s" % (e, traceback.format_exc())) try:
gtk.main() if __name__ == "__main__": flag = 0 name = '' while name=='': name = helper.get_name() if name==False: sys.exit() host, port = helper.get_connection_details() while host=='' or port=='': host, port = helper.get_connection_details() if host==False and port==False: sys.exit() serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serv.settimeout(2) try : serv.connect((host, int(port))) except: helper.err() print "Unable to connect" sys.exit() send_msg(name) client_obj = client() client_obj.textbuffer.insert_at_cursor('Connected to remote host.' + '\n') client_obj.main()
# coding:utf-8 import MySQLdb import traceback from helper import info, start, end, err, progress, get_mysql_addr if __name__ == "__main__": progress(0) start() try: db_ip, db_port = get_mysql_addr() except Exception as e: err("init param exception %s\n%s" % (e, traceback.format_exc())) try: conn = MySQLdb.connect(host=db_ip, port=db_port, user='******', passwd='iraindb10241GB', db='irain_park', charset='utf8') except Exception as e: err("connect mysql exception %s\n%s" % (e, traceback.format_exc())) try: cursor = conn.cursor() cursor.execute( "update new_auth_group set eday = DATE_SUB(eday, INTERVAL 1 DAY)" " where time_range = '00:00:00,23:59:59' and week='1,2,3,4,5,6,7' and auth_no"