feat: 备份网元Log文件到网管支持ftp转存
This commit is contained in:
@@ -850,7 +850,7 @@ INSERT INTO "sys_i18n" VALUES (746, 'dictData.cdr_sip_code_cause.580', '因其
|
||||
INSERT INTO "sys_i18n" VALUES (747, 'dictData.cdr_sip_code_cause.603', '被叫拒接', 'MT explicitly rejected the call');
|
||||
INSERT INTO "sys_i18n" VALUES (748, 'dictData.cdr_sip_code_cause.606', '呼叫已到达用户设备,但会话设置的某些部分不可接受', 'The call reached the user’s device, but some parts of the session setup weren it acceptable');
|
||||
INSERT INTO "sys_i18n" VALUES (749, 'dictType.cdr_sip_code_cause', 'IMS-Voice-SIP响应代码类别类型原因', 'IMS-Voice-SIP Response Code Category Type Cause');
|
||||
INSERT INTO "sys_i18n" VALUES (750, 'job.backup_export_log', '备份-日志数据定期导出', 'Backup-Periodic export of Log Data');
|
||||
INSERT INTO "sys_i18n" VALUES (750, 'job.backup_export_log', '备份-系统日志数据定期导出', 'Backup-Periodic export of System Log Data');
|
||||
INSERT INTO "sys_i18n" VALUES (751, 'job.backup_export_log_remark', 'dataType: 类型支持 operate/login
|
||||
fileType: 文件类型 csv/xlsx
|
||||
hour: 数据时间从任务执行时间前的小时数', 'Backup-Periodic export of dataType: type support operate/login
|
||||
@@ -990,6 +990,7 @@ INSERT INTO "sys_i18n" VALUES (806, 'dictData.cdr_cause_smsc.9', 'SMSC接收错
|
||||
INSERT INTO "sys_i18n" VALUES (807, 'dictData.cdr_cause_smsc.10', 'CAMEL 流程错误', 'CAMEL process error');
|
||||
INSERT INTO "sys_i18n" VALUES (808, 'menu.neData.udmAuth.exportDec', '导出解密', 'Export Dec');
|
||||
INSERT INTO "sys_i18n" VALUES (809, 'dictType.cdr_cause_smsc', 'SMSC CDR 响应原因代码类别类型', 'SMSC CDR Cause Code Type');
|
||||
INSERT INTO "sys_i18n" VALUES (810, 'job.backup_export_log_ne', '备份-网元日志数据定期导出', 'Backup-Periodic export of NE Log Data');
|
||||
|
||||
INSERT INTO "sys_i18n" VALUES (2000, 'menu.psap.agent', '座席', 'Agent');
|
||||
INSERT INTO "sys_i18n" VALUES (2001, 'menu.psap.agent.callings', '并行话务', 'Calling Information');
|
||||
|
||||
@@ -52,3 +52,4 @@ INSERT INTO "sys_job" VALUES (31, 'job.backup_export_udm', 'SYSTEM', 'backup_exp
|
||||
INSERT INTO "sys_job" VALUES (32, 'job.backup_export_cdr', 'SYSTEM', 'backup_export_cdr', '{"dataType":["ims","smf","sgwc","smsc"],"fileType":"xlsx","hour":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_cdr_remark');
|
||||
INSERT INTO "sys_job" VALUES (33, 'job.backup_export_log', 'SYSTEM', 'backup_export_log', '{"dataType":["operate","login"],"fileType":"xlsx","hour":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_log_remark');
|
||||
INSERT INTO "sys_job" VALUES (34, 'job.backup_export_kpi', 'SYSTEM', 'backup_export_kpi', '{"dataType":["ims","amf","udm","smf","pcf","upf","mme","smsc"],"fileType":"xlsx","hour":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_kpi_remark');
|
||||
INSERT INTO "sys_job" VALUES (35, 'job.backup_export_log_ne', 'SYSTEM', 'backup_export_log_ne', '', '0 59 23 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, '');
|
||||
|
||||
@@ -849,7 +849,7 @@ REPLACE INTO "sys_i18n" VALUES (746, 'dictData.cdr_sip_code_cause.580', '因其
|
||||
REPLACE INTO "sys_i18n" VALUES (747, 'dictData.cdr_sip_code_cause.603', '被叫拒接', 'MT explicitly rejected the call');
|
||||
REPLACE INTO "sys_i18n" VALUES (748, 'dictData.cdr_sip_code_cause.606', '呼叫已到达用户设备,但会话设置的某些部分不可接受', 'The call reached the user’s device, but some parts of the session setup weren it acceptable');
|
||||
REPLACE INTO "sys_i18n" VALUES (749, 'dictType.cdr_sip_code_cause', 'IMS-Voice-SIP响应代码类别类型原因', 'IMS-Voice-SIP Response Code Category Type Cause');
|
||||
REPLACE INTO "sys_i18n" VALUES (750, 'job.backup_export_log', '备份-日志数据定期导出', 'Backup-Periodic export of Log Data');
|
||||
REPLACE INTO "sys_i18n" VALUES (750, 'job.backup_export_log', '备份-系统日志数据定期导出', 'Backup-Periodic export of System Log Data');
|
||||
REPLACE INTO "sys_i18n" VALUES (751, 'job.backup_export_log_remark', 'dataType: 类型支持 operate/login
|
||||
fileType: 文件类型 csv/xlsx
|
||||
hour: 数据时间从任务执行时间前的小时数', 'Backup-Periodic export of dataType: type support operate/login
|
||||
@@ -989,6 +989,7 @@ REPLACE INTO "sys_i18n" VALUES (806, 'dictData.cdr_cause_smsc.9', 'SMSC接收错
|
||||
REPLACE INTO "sys_i18n" VALUES (807, 'dictData.cdr_cause_smsc.10', 'CAMEL 流程错误', 'CAMEL process error');
|
||||
REPLACE INTO "sys_i18n" VALUES (808, 'menu.neData.udmAuth.exportDec', '导出解密', 'Export Dec');
|
||||
REPLACE INTO "sys_i18n" VALUES (809, 'dictType.cdr_cause_smsc', 'SMSC CDR 响应原因代码类别类型', 'SMSC CDR Cause Code Type');
|
||||
REPLACE INTO "sys_i18n" VALUES (810, 'job.backup_export_log_ne', '备份-网元日志数据定期导出', 'Backup-Periodic export of NE Log Data');
|
||||
|
||||
REPLACE INTO "sys_i18n" VALUES (2000, 'menu.psap.agent', '座席', 'Agent');
|
||||
REPLACE INTO "sys_i18n" VALUES (2001, 'menu.psap.agent.callings', '并行话务', 'Calling Information');
|
||||
|
||||
@@ -51,3 +51,4 @@ REPLACE INTO "sys_job" VALUES (31, 'job.backup_export_udm', 'SYSTEM', 'backup_ex
|
||||
REPLACE INTO "sys_job" VALUES (32, 'job.backup_export_cdr', 'SYSTEM', 'backup_export_cdr', '{"dataType":["ims","smf","sgwc","smsc"],"fileType":"xlsx","hour":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_cdr_remark');
|
||||
REPLACE INTO "sys_job" VALUES (33, 'job.backup_export_log', 'SYSTEM', 'backup_export_log', '{"dataType":["operate","login"],"fileType":"xlsx","hour":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_log_remark');
|
||||
REPLACE INTO "sys_job" VALUES (34, 'job.backup_export_kpi', 'SYSTEM', 'backup_export_kpi', '{"dataType":["ims","amf","udm","smf","pcf","upf","mme","smsc"],"fileType":"xlsx","hour":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_kpi_remark');
|
||||
REPLACE INTO "sys_job" VALUES (35, 'job.backup_export_log_ne', 'SYSTEM', 'backup_export_log_ne', '', '0 59 23 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, '');
|
||||
|
||||
@@ -764,7 +764,7 @@ INSERT INTO `sys_i18n` VALUES (746, 'dictData.cdr_sip_code_cause.580', '因其
|
||||
INSERT INTO `sys_i18n` VALUES (747, 'dictData.cdr_sip_code_cause.603', '被叫拒接', 'MT explicitly rejected the call');
|
||||
INSERT INTO `sys_i18n` VALUES (748, 'dictData.cdr_sip_code_cause.606', '呼叫已到达用户设备,但会话设置的某些部分不可接受', 'The call reached the user’s device, but some parts of the session setup weren it acceptable');
|
||||
INSERT INTO `sys_i18n` VALUES (749, 'dictType.cdr_sip_code_cause', 'IMS-Voice-SIP响应代码类别类型原因', 'IMS-Voice-SIP Response Code Category Type Cause');
|
||||
INSERT INTO `sys_i18n` VALUES (750, 'job.backup_export_log', '备份-日志数据定期导出', 'Backup-Periodic export of Log Data');
|
||||
INSERT INTO `sys_i18n` VALUES (750, 'job.backup_export_log', '备份-系统日志数据定期导出', 'Backup-Periodic export of System Log Data');
|
||||
INSERT INTO `sys_i18n` VALUES (751, 'job.backup_export_log_remark', 'dataType: 类型支持 operate/login\nfileType: 文件类型 csv/xlsx\nhour: 数据时间从任务执行时间前的小时数', 'Backup-Periodic export of dataType: type support operate/login\nfileType: file type csv/xlsx\nhour: data time from the hour before the task execution time');
|
||||
INSERT INTO `sys_i18n` VALUES (752, 'job.ne_alarm_state_check_cmd', '网元告警-内存/CPU/磁盘检查', 'NE Alarm-Memory/CPU/Disk Checks');
|
||||
INSERT INTO `sys_i18n` VALUES (753, 'job.ne_alarm_state_check_cmd_remark', '检查网元的内存/CPU/磁盘检查健康状况,在出现过阈值时发出警报。\r\n\r\nAlarm type:\r\nCommunicationAlarm=1\r\nEquipmentAlarm=2\r\nProcessingFailure=3\r\nEnvironmentalAlarm=4\r\nQualityOfServiceAlarm=5\r\n\r\nSeverity:\r\nCritical=1\r\nMajor=2\r\nMinor=3\r\nWarning=4\r\n\r\nAddInfo: 告警补充信息\r\ncpuUseGt: CPU使用率大于, 范围0~100*CPU核心数\r\nmemUseGt: 内存使用率大于, 范围0~100%\r\ndiskUseGt: 磁盘使用率大于, 范围0~100%', 'Checks the memory/CPU/disk check health of the network element and sends alerts when thresholds are crossed.\n\nAlarm type:\nCommunicationAlarm=1\nEquipmentAlarm=2\nProcessingFailure=3\nEnvironmentalAlarm=4\nQualityOfServiceAlarm=5\n\nSeverity:\nCritical=1\nMajor=2\nMinor=3\nWarning=4\r\n\r\nAddInfo: Additional information on alarms\r\ncpuUseGt: CPU utilization is greater than, range 0~100*number of CPU cores\r\nmemUseGt: Memory utilization greater than, range 0 to 100%\r\ndiskUseGt: Disk utilization greater than, range 0 to 100%');
|
||||
@@ -824,6 +824,7 @@ INSERT INTO `sys_i18n` VALUES (806, 'dictData.cdr_cause_smsc.9', 'SMSC接收错
|
||||
INSERT INTO `sys_i18n` VALUES (807, 'dictData.cdr_cause_smsc.10', 'CAMEL 流程错误', 'CAMEL process error');
|
||||
INSERT INTO `sys_i18n` VALUES (808, 'menu.neData.udmAuth.exportDec', '导出解密', 'Export Dec');
|
||||
INSERT INTO `sys_i18n` VALUES (809, 'dictType.cdr_cause_smsc', 'SMSC CDR 响应原因代码类别类型', 'SMSC CDR Cause Code Type');
|
||||
INSERT INTO `sys_i18n` VALUES (810, 'job.backup_export_log_ne', '备份-网元日志数据定期导出', 'Backup-Periodic export of NE Log Data');
|
||||
|
||||
INSERT INTO `sys_i18n` VALUES (2000, 'menu.psap.agent', '座席', 'Agent');
|
||||
INSERT INTO `sys_i18n` VALUES (2001, 'menu.psap.agent.callings', '并行话务', 'Calling Information');
|
||||
|
||||
@@ -47,6 +47,7 @@ INSERT INTO `sys_job` VALUES (31, 'job.backup_export_udm', 'SYSTEM', 'backup_exp
|
||||
INSERT INTO `sys_job` VALUES (32, 'job.backup_export_cdr', 'SYSTEM', 'backup_export_cdr', '{\"dataType\":[\"ims\",\"smf\",\"sgwc\",\"smsc\"],\"fileType\":\"xlsx\",\"hour\":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_cdr_remark');
|
||||
INSERT INTO `sys_job` VALUES (33, 'job.backup_export_log', 'SYSTEM', 'backup_export_log', '{\"dataType\":[\"operate\",\"login\"],\"fileType\":\"xlsx\",\"hour\":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_log_remark');
|
||||
INSERT INTO `sys_job` VALUES (34, 'job.backup_export_kpi', 'SYSTEM', 'backup_export_kpi', '{\"dataType\":[\"ims\",\"amf\",\"udm\",\"smf\",\"pcf\",\"upf\",\"mme\",\"smsc\"],\"fileType\":\"xlsx\",\"hour\":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_kpi_remark');
|
||||
INSERT INTO `sys_job` VALUES (35, 'job.backup_export_log_ne', 'SYSTEM', 'backup_export_log_ne', '', '0 59 23 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, '');
|
||||
|
||||
|
||||
-- INSERT INTO `sys_job` VALUES (34, 'job.backup_export_table_sys_log_operate', 'SYSTEM', 'backup_export_table', '{\"hour\":1,\"columns\":[\"id\",\"title\",\"business_type\",\"opera_by\",\"opera_url_method\",\"opera_url\",\"opera_ip\",\"status\",\"opera_time\",\"cost_time\"],\"tableName\":\"sys_log_operate\",\"backupPath\":\"/log/operate_log\"}', '0 0 0/1 * * ?', '3', '0', '0', '1', 'system', 1698478134839, 'system', 1698478134839, 'job.backup_export_table_sys_log_operate_remark');
|
||||
|
||||
@@ -761,7 +761,7 @@ REPLACE INTO `sys_i18n` VALUES (746, 'dictData.cdr_sip_code_cause.580', '因其
|
||||
REPLACE INTO `sys_i18n` VALUES (747, 'dictData.cdr_sip_code_cause.603', '被叫拒接', 'MT explicitly rejected the call');
|
||||
REPLACE INTO `sys_i18n` VALUES (748, 'dictData.cdr_sip_code_cause.606', '呼叫已到达用户设备,但会话设置的某些部分不可接受', 'The call reached the user’s device, but some parts of the session setup weren it acceptable');
|
||||
REPLACE INTO `sys_i18n` VALUES (749, 'dictType.cdr_sip_code_cause', 'IMS-Voice-SIP响应代码类别类型原因', 'IMS-Voice-SIP Response Code Category Type Cause');
|
||||
REPLACE INTO `sys_i18n` VALUES (750, 'job.backup_export_log', '备份-日志数据定期导出', 'Backup-Periodic export of Log Data');
|
||||
REPLACE INTO `sys_i18n` VALUES (750, 'job.backup_export_log', '备份-系统日志数据定期导出', 'Backup-Periodic export of System Log Data');
|
||||
REPLACE INTO `sys_i18n` VALUES (751, 'job.backup_export_log_remark', 'dataType: 类型支持 operate/login\nfileType: 文件类型 csv/xlsx\nhour: 数据时间从任务执行时间前的小时数', 'Backup-Periodic export of dataType: type support operate/login\nfileType: file type csv/xlsx\nhour: data time from the hour before the task execution time');
|
||||
REPLACE INTO `sys_i18n` VALUES (752, 'job.ne_alarm_state_check_cmd', '网元告警-内存/CPU/磁盘检查', 'NE Alarm-Memory/CPU/Disk Checks');
|
||||
REPLACE INTO `sys_i18n` VALUES (753, 'job.ne_alarm_state_check_cmd_remark', '检查网元的内存/CPU/磁盘检查健康状况,在出现过阈值时发出警报。\r\n\r\nAlarm type:\r\nCommunicationAlarm=1\r\nEquipmentAlarm=2\r\nProcessingFailure=3\r\nEnvironmentalAlarm=4\r\nQualityOfServiceAlarm=5\r\n\r\nSeverity:\r\nCritical=1\r\nMajor=2\r\nMinor=3\r\nWarning=4\r\n\r\nAddInfo: 告警补充信息\r\ncpuUseGt: CPU使用率大于, 范围0~100*CPU核心数\r\nmemUseGt: 内存使用率大于, 范围0~100%\r\ndiskUseGt: 磁盘使用率大于, 范围0~100%', 'Checks the memory/CPU/disk check health of the network element and sends alerts when thresholds are crossed.\n\nAlarm type:\nCommunicationAlarm=1\nEquipmentAlarm=2\nProcessingFailure=3\nEnvironmentalAlarm=4\nQualityOfServiceAlarm=5\n\nSeverity:\nCritical=1\nMajor=2\nMinor=3\nWarning=4\r\n\r\nAddInfo: Additional information on alarms\r\ncpuUseGt: CPU utilization is greater than, range 0~100*number of CPU cores\r\nmemUseGt: Memory utilization greater than, range 0 to 100%\r\ndiskUseGt: Disk utilization greater than, range 0 to 100%');
|
||||
@@ -821,6 +821,7 @@ REPLACE INTO `sys_i18n` VALUES (806, 'dictData.cdr_cause_smsc.9', 'SMSC接收错
|
||||
REPLACE INTO `sys_i18n` VALUES (807, 'dictData.cdr_cause_smsc.10', 'CAMEL 流程错误', 'CAMEL process error');
|
||||
REPLACE INTO `sys_i18n` VALUES (808, 'menu.neData.udmAuth.exportDec', '导出解密', 'Export Dec');
|
||||
REPLACE INTO `sys_i18n` VALUES (809, 'dictType.cdr_cause_smsc', 'SMSC CDR 响应原因代码类别类型', 'SMSC CDR Cause Code Type');
|
||||
REPLACE INTO `sys_i18n` VALUES (810, 'job.backup_export_log_ne', '备份-网元日志数据定期导出', 'Backup-Periodic export of NE Log Data');
|
||||
|
||||
REPLACE INTO `sys_i18n` VALUES (2000, 'menu.psap.agent', '座席', 'Agent');
|
||||
REPLACE INTO `sys_i18n` VALUES (2001, 'menu.psap.agent.callings', '并行话务', 'Calling Information');
|
||||
|
||||
@@ -63,6 +63,7 @@ REPLACE INTO `sys_job` VALUES (31, 'job.backup_export_udm', 'SYSTEM', 'backup_ex
|
||||
REPLACE INTO `sys_job` VALUES (32, 'job.backup_export_cdr', 'SYSTEM', 'backup_export_cdr', '{\"dataType\":[\"ims\",\"smf\",\"sgwc\",\"smsc\"],\"fileType\":\"xlsx\",\"hour\":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_cdr_remark');
|
||||
REPLACE INTO `sys_job` VALUES (33, 'job.backup_export_log', 'SYSTEM', 'backup_export_log', '{\"dataType\":[\"operate\",\"login\"],\"fileType\":\"xlsx\",\"hour\":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_log_remark');
|
||||
REPLACE INTO `sys_job` VALUES (34, 'job.backup_export_kpi', 'SYSTEM', 'backup_export_kpi', '{\"dataType\":[\"ims\",\"amf\",\"udm\",\"smf\",\"pcf\",\"upf\",\"mme\",\"smsc\"],\"fileType\":\"xlsx\",\"hour\":1}', '0 0 0/1 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, 'job.backup_export_kpi_remark');
|
||||
REPLACE INTO `sys_job` VALUES (35, 'job.backup_export_log_ne', 'SYSTEM', 'backup_export_log_ne', '', '0 59 23 * * ?', '3', '0', '1', '1', 'system', 1698478134839, 'supervisor', 1745481169354, '');
|
||||
|
||||
|
||||
-- REPLACE INTO `sys_job` VALUES (34, 'job.backup_export_table_sys_log_operate', 'SYSTEM', 'backup_export_table', '{\"hour\":1,\"columns\":[\"id\",\"title\",\"business_type\",\"opera_by\",\"opera_url_method\",\"opera_url\",\"opera_ip\",\"status\",\"opera_time\",\"cost_time\"],\"tableName\":\"sys_log_operate\",\"backupPath\":\"/log/operate_log\"}', '0 0 0/1 * * ?', '3', '0', '0', '1', 'system', 1698478134839, 'system', 1698478134839, 'job.backup_export_table_sys_log_operate_remark');
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package backup_export_log_ne
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/cron"
|
||||
"be.ems/src/framework/database/redis"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/ssh"
|
||||
neDataService "be.ems/src/modules/network_data/service"
|
||||
neModel "be.ems/src/modules/network_element/model"
|
||||
neService "be.ems/src/modules/network_element/service"
|
||||
)
|
||||
|
||||
var NewProcessor = &BackupExportLogNEProcessor{
|
||||
count: 0,
|
||||
backupService: neDataService.NewBackup,
|
||||
neInfoService: neService.NewNeInfo,
|
||||
logFilePath: "/var/log",
|
||||
}
|
||||
|
||||
// BackupExportLogNEProcessor 备份导出日志任务处理
|
||||
type BackupExportLogNEProcessor struct {
|
||||
count int // 执行次数
|
||||
backupService *neDataService.Backup // 备份相关服务
|
||||
neInfoService *neService.NeInfo // 网元信息服务
|
||||
logFilePath string // 日志文件目录
|
||||
}
|
||||
|
||||
func (s *BackupExportLogNEProcessor) Execute(data any) (any, error) {
|
||||
s.count++ // 执行次数加一
|
||||
options := data.(cron.JobData)
|
||||
sysJob := options.SysJob
|
||||
logger.Infof("重复:%v 任务ID:%d 执行次数:%d", options.Repeat, sysJob.JobId, s.count)
|
||||
// 返回结果,用于记录执行结果
|
||||
result := map[string]any{
|
||||
"count": s.count,
|
||||
}
|
||||
|
||||
// 分布式锁,防止多个任务同时执行
|
||||
lockKey := fmt.Sprintf("processor:backup_export_log_ne:%d", sysJob.JobId)
|
||||
if ok := redis.SetNX("", lockKey, time.Minute); !ok {
|
||||
return nil, cron.ErrTaskRunning
|
||||
}
|
||||
defer redis.Del("", lockKey)
|
||||
|
||||
// 时间目录
|
||||
timeDir := time.Now().Format("20060102150405")
|
||||
|
||||
neList := s.neInfoService.Find(neModel.NeInfo{}, false, false)
|
||||
for _, neInfo := range neList {
|
||||
if neInfo.IP == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// 网元主机的SSH客户端
|
||||
sshClient, err := s.neInfoService.NeRunSSHClient(neInfo.NeType, neInfo.NeId)
|
||||
if err != nil {
|
||||
result[neInfo.NeName] = err.Error()
|
||||
continue
|
||||
}
|
||||
defer sshClient.Close()
|
||||
// 网元主机的SSH客户端进行文件传输
|
||||
sftpClient, err := sshClient.NewClientSFTP()
|
||||
if err != nil {
|
||||
result[neInfo.NeName] = err.Error()
|
||||
continue
|
||||
}
|
||||
defer sftpClient.Close()
|
||||
|
||||
// 备份导出日志
|
||||
if neInfo.NeType == "IMS" {
|
||||
imsDirArr := [...]string{"icscf", "bgcf", "mmtel", "pcscf", "scscf", "iwf", "bsf", "ismc"}
|
||||
for _, dirPath := range imsDirArr {
|
||||
logFilePathIMS := filepath.ToSlash(filepath.Join(s.logFilePath, "ims", dirPath))
|
||||
output := s.backup(timeDir, logFilePathIMS, neInfo, sshClient, sftpClient)
|
||||
for k, v := range output {
|
||||
result[k+"-"+dirPath] = v
|
||||
}
|
||||
}
|
||||
} else {
|
||||
output := s.backup(timeDir, s.logFilePath, neInfo, sshClient, sftpClient)
|
||||
for k, v := range output {
|
||||
result[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 返回结果,用于记录执行结果
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// backup 备份导出日志
|
||||
func (s *BackupExportLogNEProcessor) backup(timeDir string, logFilePath string, neInfo neModel.NeInfo, sshClient *ssh.ConnSSH, sftpClient *ssh.SSHClientSFTP) map[string]string {
|
||||
var result = map[string]string{}
|
||||
|
||||
// 获取文件列表
|
||||
search := strings.ToLower(neInfo.NeType)
|
||||
if neInfo.NeType == "IMS" {
|
||||
search = ""
|
||||
}
|
||||
rows, err := ssh.FileList(sshClient, logFilePath, search)
|
||||
if err != nil {
|
||||
result[neInfo.NeName] = err.Error()
|
||||
return result
|
||||
}
|
||||
|
||||
// 计算今天00:00:00的时间戳(秒)
|
||||
today := time.Now()
|
||||
todayStart := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||||
todayStartTimestamp := todayStart.Unix()
|
||||
for _, row := range rows {
|
||||
if row.ModifiedTime < todayStartTimestamp || row.FileType != "file" {
|
||||
continue
|
||||
}
|
||||
// 网元日志文件路径
|
||||
neFilePath := fmt.Sprintf("%s/%s", logFilePath, row.FileName)
|
||||
// 复制到备份目录
|
||||
neDirPath := fmt.Sprintf("%s/%s", search, row.FileName)
|
||||
if neInfo.NeType == "IMS" {
|
||||
neDirPath = strings.Replace(neFilePath, s.logFilePath, "", 1)
|
||||
}
|
||||
localFilePath := filepath.Join(s.backupService.BACKUP_DIR, "/log/ne_log", timeDir, neDirPath)
|
||||
if err := sftpClient.CopyFileRemoteToLocal(neFilePath, localFilePath); err != nil {
|
||||
result[neInfo.NeName+"-copy"] = err.Error()
|
||||
continue
|
||||
}
|
||||
// 上传到FTP服务器
|
||||
if err := s.backupService.FTPPushFile(localFilePath, "log"); err != nil {
|
||||
result[neInfo.NeName+"-copy-ftp"] = "ok, ftp err:" + err.Error()
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
processorBackupExportCDR "be.ems/src/modules/crontask/processor/backup_export_cdr"
|
||||
processorBackupExportKPI "be.ems/src/modules/crontask/processor/backup_export_kpi"
|
||||
processorBackupExportLog "be.ems/src/modules/crontask/processor/backup_export_log"
|
||||
processorBackupExportLogNE "be.ems/src/modules/crontask/processor/backup_export_log_ne"
|
||||
processorBackupExportTable "be.ems/src/modules/crontask/processor/backup_export_table"
|
||||
processorBackupExportUDM "be.ems/src/modules/crontask/processor/backup_export_udm"
|
||||
processorBackupRemoveFile "be.ems/src/modules/crontask/processor/backup_remove_file"
|
||||
@@ -59,8 +60,10 @@ func InitCronQueue() {
|
||||
cron.CreateQueue("backup_export_udm", processorBackupExportUDM.NewProcessor)
|
||||
// 备份-导出CDR数据
|
||||
cron.CreateQueue("backup_export_cdr", processorBackupExportCDR.NewProcessor)
|
||||
// 备份-导出Log数据
|
||||
// 备份-导出系统Log数据
|
||||
cron.CreateQueue("backup_export_log", processorBackupExportLog.NewProcessor)
|
||||
// 备份-导出KPI数据
|
||||
cron.CreateQueue("backup_export_kpi", processorBackupExportKPI.NewProcessor)
|
||||
// 备份-导出网元Log数据
|
||||
cron.CreateQueue("backup_export_log_ne", processorBackupExportLogNE.NewProcessor)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user