Skip to content

Commit 9424ffc

Browse files
committed
Monitoring alert log file by server os in AlertLogMonitoring menu
1 parent 1b283e7 commit 9424ffc

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/main/java/root/core/repository/implement/WindowServerMonitoringRepository.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public String checkAlertLog(AlertLogCommand alc) {
5858
} catch (Exception e) {
5959
log.error(e.getMessage());
6060
}
61-
6261
log.debug(alc.toString());
6362
return result;
6463
}
@@ -85,22 +84,34 @@ public AlertLog checkAlertLogDuringPeriod(AlertLogCommand alc, String startDate,
8584

8685
for (int i = 0; i < lines.length; i++) {
8786
String line = lines[i];
87+
8888
// 조회시작일자 찾기
8989
if (!isStartDate) {
9090
LocalDate parsedDate = DateUtils.parse(line);
9191
if (parsedDate != null) {
92+
// [조회시작일자 >= 최초 로그기록일자]일 때, 최초 로그기록일자부터 읽기 시작
9293
String parsedDateString = DateUtils.convertDateFormat("yyyy-MM-dd", parsedDate);
9394
if (DateUtils.getDateDiffTime("yyyy-MM-dd", parsedDateString, startDate) >= 0) {
9495
isStartDate = true;
9596
readStartIndex = i;
97+
logTimeStamp = line;
98+
99+
// [조회종료일자 > 조회 시작일자 >= 최초 로그기록일자]일 때 최초 로그기록일자부터 읽기 시작
100+
if(DateUtils.getDateDiffTime("yyyy-MM-dd", parsedDateString, endDate) > 0) {
101+
isEndDate = true;
102+
readEndIndex = i;
103+
break;
104+
}
96105
}
97106
}
98107
}
99-
108+
100109
// 로그 저장 시작 & 조회종료일자 찾기
101110
if (isStartDate) {
102111
LocalDate parsedDate = DateUtils.parse(line);
103112
if (parsedDate != null) { // Log TimeStamp Line
113+
114+
// 현재 로그기록일자가 조회종료일자 + 1일인지 확인
104115
String logDate = DateUtils.convertDateFormat("yyyy-MM-dd", parsedDate);
105116
if (logDate.startsWith(DateUtils.addDate(endDate, 0, 0, 1))) {
106117
isEndDate = true;
@@ -111,7 +122,7 @@ public AlertLog checkAlertLogDuringPeriod(AlertLogCommand alc, String startDate,
111122
logTimeStamp = line;
112123
}
113124

114-
if (i != readStartIndex && !isEndDate) {
125+
if (i != readStartIndex) {
115126
alertLog.addLog(new Log(logTimeStamp, logContents));
116127
logContents = new ArrayList<>();
117128
logTimeStamp = line;
@@ -129,8 +140,7 @@ public AlertLog checkAlertLogDuringPeriod(AlertLogCommand alc, String startDate,
129140
}
130141
}
131142

132-
// 종료 후 마지막 로그 추가하기
133-
alertLog.addLog(new Log(logTimeStamp, logContents));
143+
// 종료 후 fullLogString 추가
134144
alertLog.setFullLogString(sb.toString());
135145

136146
log.info("\t▶ Alert Log READ LINE: " + (readEndIndex - readStartIndex) + "/" + alc.getReadLine());

src/main/java/root/core/usecase/implement/ServerMonitoringUsecaseImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ public List<OSDiskUsage> getCurrentOSDiskUsage() {
268268
public AlertLog getAlertLogDuringPeriod(AlertLogCommand alc, String startDate, String endDate) {
269269
log.debug(String.format("alert log file monitoring, %s (%s ~ %s)", alc.getReadFilePath(), startDate, endDate));
270270
AlertLog result = serverCheckRepository.checkAlertLogDuringPeriod(alc, startDate, endDate);
271-
log.debug(result.toString());
272271
return result;
273272
}
274273
}

src/main/java/root/javafx/Controller/AlertLogMonitoringMenuController.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import root.core.domain.AlertLog;
2020
import root.core.domain.JschConnectionInfo;
2121
import root.core.domain.Log;
22+
import root.core.domain.enums.ServerOS;
2223
import root.core.repository.constracts.ServerMonitoringRepository;
2324
import root.core.repository.implement.LinuxServerMonitoringRepository;
2425
import root.core.repository.implement.PropertyRepositoryImpl;
2526
import root.core.repository.implement.ReportFileRepo;
27+
import root.core.repository.implement.WindowServerMonitoringRepository;
2628
import root.core.service.contracts.PropertyService;
2729
import root.core.service.implement.FilePropertyService;
2830
import root.core.usecase.constracts.ServerMonitoringUsecase;
@@ -170,7 +172,7 @@ private boolean validateInput() {
170172
return true;
171173
}
172174

173-
public void monitoringAlertLog(ActionEvent e) {
175+
public void monitoringAlertLog(ActionEvent e) throws Exception {
174176
// 입력값 검사
175177
if (!validateInput()) {
176178
return;
@@ -184,7 +186,14 @@ public void monitoringAlertLog(ActionEvent e) {
184186

185187
JschServer server = new JschServer(connInfo);
186188
server.init();
187-
ServerMonitoringRepository repo = new LinuxServerMonitoringRepository(server);
189+
ServerMonitoringRepository repo = null;
190+
if (connInfo.getServerOS() == ServerOS.WINDOW) {
191+
repo = new WindowServerMonitoringRepository(server);
192+
} else if (connInfo.getServerOS() == ServerOS.LINUX) {
193+
repo = new LinuxServerMonitoringRepository(server);
194+
} else {
195+
throw new Exception("Server OS is not valid");
196+
}
188197
ServerMonitoringUsecase usecase = new ServerMonitoringUsecaseImpl(repo, ReportFileRepo.getInstance());
189198

190199
alertLogMonitoringResultMap.put(selectedServer,

0 commit comments

Comments
 (0)