You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hbyd_ueba/corn/ueba_corn_pg.py

56 lines
1.7 KiB

5 months ago
# coding=utf-8
"""
4 months ago
@Author: tangwy
@FileName: user_cron_pg.py
@DateTime: 2024/7/09 14:19
@Description: 定时清洗es数据
5 months ago
"""
from __future__ import unicode_literals
import random,string
4 months ago
import traceback,json
import time
from datetime import datetime,timedelta
5 months ago
import calendar
from uebaMetricsAnalysis.utils.ext_logging import logger
4 months ago
from uebaMetricsAnalysis.utils.db2json import DBUtils, DBType
from uebaMetricsAnalysis.utils.base_dataclean_pg import entry
5 months ago
JOB_STATUS ={
"RUNNING":1,
"FINISH":2,
"ERROR":3
}
class UserCron:
4 months ago
def generate_job_id(self):
5 months ago
timestamp = int(time.time() * 1000)
random_letters = ''.join(random.choice(string.ascii_letters) for _ in range(7))
return str(timestamp) + random_letters
#每5分钟执行一次
def processing(self):
4 months ago
job_id =self.generate_job_id()
5 months ago
try:
logger.info("job:开始执行")
4 months ago
start,end= DBUtils.get_job_period()
5 months ago
if start is None or end is None:
logger.info("job:结束时间大于服务器时间不执行")
return
4 months ago
DBUtils.insert_job_record(job_id,start,end,JOB_STATUS.get("RUNNING"))
logger.info("job:运行参数:{}".format(start,end))
5 months ago
logger.info("job:"+"准备获取es数据")
entry(start,end)
logger.info("job:"+"执行完成")
DBUtils.write_job_status(job_id,JOB_STATUS.get("FINISH"),"")
except Exception ,e:
err_info="定时任务执行失败:".format(str(e), traceback.format_exc())
DBUtils.write_job_status(job_id,JOB_STATUS.get("ERROR"),err_info)
4 months ago
logger.error(err_info)
5 months ago
raise
if __name__ == '__main__':
UserCron().processing()