代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from string import Template
import glob
from os.path import basename, splitext
import ConfigParser
files_path = 'test_files/ls_sqls'
dist_file_path = 'dist/input.conf'
config_file_path = 'assets/db.ini'
default_schedule = '*/2 * * * *'
es_host = '172.16.238.10:9200'
cf = ConfigParser.ConfigParser()
cf.read(config_file_path)
def get_table_schedule_map():
schedules = cf.options("schedule")
m = {}
for option in schedules:
m[option] = cf.get('schedule', option)
return m
def generate_input_configs():
sql_files = glob.glob(files_path + '/*.sql')
it = Template(open('assets/input-template.conf').read())
input_str = ''
print(len(sql_files))
d = get_table_schedule_map()
driver_type = cf.get("db", "driver_type")
driver_mysql_name = cf.get("lib", "mysql")
driver_oracle_name = cf.get("lib", "oracle")
if driver_type == 'mysql':
driver_name = driver_mysql_name
driver_class = 'com.mysql.jdbc.Driver'
elif driver_type == 'oracle':
driver_name = driver_oracle_name
driver_class = 'Java::oracle.jdbc.driver.OracleDriver'
else:
raise Exception("unsupported driver name %s yet!" % driver_type)
db_connect_url = cf.get("db", "connect_url")
db_user = cf.get("db", "user")
db_pwd = cf.get("db", "password")
for file_url in sql_files:
file_name_with_ext = basename(file_url)
file_name = splitext(file_name_with_ext)[0]
schedule = d.get(file_name.lower(), default_schedule)
input_str += it.substitute(table_name=file_name, schedule=schedule, driver_name=driver_name,
driver_class=driver_class, db_connect_url=db_connect_url, db_user=db_user,
db_pwd=db_pwd)
return input_str
if __name__ == '__main__':
input_configs = generate_input_configs()
es_index_name = cf.get('es', 'index_name')
f = open(dist_file_path, 'w+')
filein = open('assets/logstash-template.conf')
s = Template(filein.read())
ls_str = s.substitute(inputs=input_configs, es_host=es_host, es_index_name=es_index_name)
f.write(ls_str)
f.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。