diff options
author | 2017-02-15 02:26:54 +0000 | |
---|---|---|
committer | 2017-02-15 02:26:54 +0000 | |
commit | d534e34d020881b193564e38513299ae3faef9e3 (patch) | |
tree | 1f1a42767061c531fbec0e590fedbadbf94c6271 /logging-sdk/src/main/java/org/openo/log/api | |
parent | 5ffdd63a0bd74d1e7da97b58febaf0970493616e (diff) | |
parent | 1c364623b8cf9e75028fc8d22d0246e2a8fce412 (diff) |
Merge "Add Logging sdk"
Diffstat (limited to 'logging-sdk/src/main/java/org/openo/log/api')
5 files changed, 884 insertions, 0 deletions
diff --git a/logging-sdk/src/main/java/org/openo/log/api/LogMessage.java b/logging-sdk/src/main/java/org/openo/log/api/LogMessage.java new file mode 100644 index 0000000..4a21584 --- /dev/null +++ b/logging-sdk/src/main/java/org/openo/log/api/LogMessage.java @@ -0,0 +1,132 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.log.api; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import org.slf4j.Logger; + +import org.openo.log.impl.Facitility; +import org.slf4j.LoggerFactory; + + +/** + * + * @author Huabing Zhao + * + */ + +public class LogMessage implements Serializable { + private static final Logger LOGGER = LoggerFactory.getLogger(LogMessage.class.getName()); + + protected long id = -1; + + + protected String detail = null; + + protected String hostname = ""; + + + + private String logType = ""; + + + protected HashMap<String, Object> extendedFields = null; + + private HashMap<String, String> localeMap = null; + + + + private static final long serialVersionUID = 200408041651009L; + + public String getDetail() { + return detail; + } + + + public long getId() { + return id; + } + + public String getHostname() { + return hostname; + } + + + + public LogMessage() {} + + + + public String getLogType() { + return logType; + } + + public void setLogType(String logType) { + this.logType = logType; + } + + public HashMap<String, Object> getExtendedFields() { + return extendedFields; + } + + public void setExtendedFields(HashMap<String, Object> extendedFields) { + this.extendedFields = extendedFields; + } + + public HashMap<String, String> getLocaleMap() { + return this.localeMap; + } + + public void setLocalMap(HashMap<String, String> localeMap) { + this.localeMap = localeMap; + } + + protected void set(String condName, Object condValue) { + if (condValue != null && !"".equals(condValue)) { + if (localeMap == null) { + localeMap = new HashMap<String, String>(); + } + localeMap.put(condName, condValue.toString()); + + } + } + + + protected void setLocale(String condName, String condValue) { + + if (condValue != null && !"".equals(condValue)) { + if (localeMap == null) { + localeMap = new HashMap<String, String>(); + } + + + + Map<String, String> mapJson = Facitility.readJson2Map(condValue); + for (Entry<String, String> entry : mapJson.entrySet()) { + String key = entry.getKey(); + + String value = entry.getValue().replace("\"", "\'"); + localeMap.put(condName + "_" + key, value); + } + } + + } + + +} diff --git a/logging-sdk/src/main/java/org/openo/log/api/LogService.java b/logging-sdk/src/main/java/org/openo/log/api/LogService.java new file mode 100644 index 0000000..737d4e2 --- /dev/null +++ b/logging-sdk/src/main/java/org/openo/log/api/LogService.java @@ -0,0 +1,140 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.log.api; + +import org.openo.log.impl.InsertLogHandler; +import org.openo.log.impl.LogConst; +import org.openo.log.impl.LogIdTool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LogService { + + private static final Logger LOGGER = LoggerFactory.getLogger(LogService.class.getName()); + + + public static final String OPERLOG_SUCCESS = "log_success"; + + public static final String OPERLOG_ERROR = "log_fail"; + + + public static final String OPERLOG_RANK_NORMAL = "operlog_rank_normal"; + + public static final String OPERLOG_RANK_NOTICE = "operlog_rank_notice"; + + public static final String OPERLOG_RANK_IMPORTANT = "operlog_rank_important"; + + public static final String OPERLOG_RANK_VERYIMPORTANT = " operlog_rank_veryimportant"; + + + public static final String SYSLOG_RANK_INFORM = "syslog_rank_inform"; + + public static final String SYSLOG_RANK_NOTICE = "syslog_rank_notice"; + + + public static final String SYSLOG_RANK_WARN = "syslog_rank_warn"; + + public static final String SYSLOG_RANK_ERROR = "syslog_rank_error"; + + + public static final String SYSLOG_RANK_ALERT = "syslog_rank_alert"; + + + public static final String SYSLOG_RANK_EMERG = "syslog_rank_emerg"; + + + public static final String CONNECT_TYPE_WEB = "WEB"; + + public static final String CONNECT_TYPE_TELNET = "TELNET"; + + public static final String CONNECT_TYPE_SSH = "SSH"; + + public static final String CONNECT_TYPE_EM = "EM"; + + public static final short LOG_DISPLAY_NOT = 0; + + public static final short LOG_DISPLAY = 1; + + public static final int LOG_ROOT_LINK_ID = -1; + + private static final int LOG_NO_LINK_ID = 0; + + private static LogService recordLogHandler = null; + + public static LogService getInstance() { + if (recordLogHandler == null) { + recordLogHandler = new LogService(); + } + return recordLogHandler; + } + + public long recordOperLog(OperLogMessage logMessage) { + // TODO Auto-generated method stub + LOGGER.info("receive a insert operLog message"); + InsertLogHandler insertLogHandler = new InsertLogHandler(); + if (insertLogHandler.checkCmdLog((OperLogMessage) logMessage)) { + + long id = + LogIdTool.getRandomID(LogConst.CMD_LOG_FLAG, logMessage.getLogStartDate().getTime()); + logMessage.setId(id); + insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_OPERATION, LogConst.OPERLOG_TYPE); + + return logMessage.getId(); + } + + return 0; + } + + public long recordSecLog(SecLogMessage logMessage) { + // TODO Auto-generated method stub + LOGGER.info("receive a insert sec log message"); + InsertLogHandler insertLogHandler = new InsertLogHandler(); + if (insertLogHandler.checkSecLog((SecLogMessage) logMessage)) { + + long id = LogIdTool.getRandomID(LogConst.SECRET_LOG_FLAG, logMessage.getLogDate().getTime()); + logMessage.setId(id); + + insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_SECURITY, LogConst.SERLOG_TYPE); + + return logMessage.getId(); + } + return 0; + } + + + + public long recordSysLog(SysLogMessage logMessage) { + LOGGER.info("receive a insert sys log message"); + InsertLogHandler insertLogHandler = new InsertLogHandler(); + if (insertLogHandler.checkSysLog((SysLogMessage) logMessage)) { + + long id = + LogIdTool.getRandomID(LogConst.SYS_LOG_FLAG, logMessage.getLogStartDate().getTime()); + logMessage.setId(id); + insertLogHandler.insertLog(logMessage, LogConst.AUDITLOG_SYSTEM, LogConst.SYSLOG_TYPE); + return logMessage.getId(); + } + return 0; + } + + public static void main(String[] args) + { + LogService service = new LogService(); + OperLogMessage logMessage = new OperLogMessage(); + + service.recordOperLog(logMessage ); + } +} diff --git a/logging-sdk/src/main/java/org/openo/log/api/OperLogMessage.java b/logging-sdk/src/main/java/org/openo/log/api/OperLogMessage.java new file mode 100644 index 0000000..567cfd0 --- /dev/null +++ b/logging-sdk/src/main/java/org/openo/log/api/OperLogMessage.java @@ -0,0 +1,286 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.log.api; + +import java.util.Date; + +import org.openo.log.impl.Facitility; +import org.openo.log.impl.LogConst; + + + +public class OperLogMessage extends LogMessage { + private static final long serialVersionUID = 200408041704009L; + + + public OperLogMessage() { + super(); + this.setLogType(LogConst.OPERLOG_TYPE); + } + + + public OperLogMessage(String userName, String operation, String descriptionInfo, String hostname, + String operateResult, String rank, Date logStartDate, Date logEndDate, String detail) { + super(); + this.setLogType(LogConst.OPERLOG_TYPE); + + this.userName = userName; + this.set("userName", userName); + + this.descriptionInfo = descriptionInfo; + this.setLocale("descriptionInfo", descriptionInfo); + + this.operation = operation; + this.setLocale("operation", operation); + + this.logStartDate = logStartDate; + this.set("logStartDate", Facitility.dateFormat(logStartDate)); + + this.logEndDate = logEndDate; + this.set("logEndDate", Facitility.dateFormat(logEndDate)); + + this.hostname = hostname; + this.set("hostname", hostname); + + this.operateResult = operateResult; + this.set("operateResult", operateResult); + + this.rank = rank; + this.set("rank", rank); + + this.detail = detail; + this.setLocale("detail", detail); + } + + + protected String userName = ""; + + + protected String operation = null; + + + protected String descriptionInfo = null; + + + private String operationType = "other"; + + protected String failReason = null; + + + protected String operateResult = LogService.OPERLOG_SUCCESS; + + + protected String connectMode = LogService.CONNECT_TYPE_WEB; + + + protected String[] resourceIP; + + + protected Date logStartDate = null; + + + protected Date logEndDate = null; + + + protected long linkId = -100; + + protected int isDisplay = LogService.LOG_DISPLAY; + + protected String mac = ""; + + /** + * name(id)|name(id) + */ + private String[] operateResource = null; + + + protected String rank = LogService.OPERLOG_RANK_NORMAL; + + public String getMac() { + return mac; + } + + public OperLogMessage setMac(String mac) { + this.set("mac", mac); + this.mac = mac; + return this; + } + + + public String getUserName() { + return userName; + } + + public OperLogMessage setUserName(String name) { + this.userName = name; + this.set("userName", name); + return this; + } + + public String getFailReason() { + return failReason; + } + + public OperLogMessage setFailReason(String reason) { + this.setLocale("failReason", reason); + this.failReason = reason; + return this; + } + + public String getConnectMode() { + return connectMode; + + } + + public OperLogMessage setConnectMode(String mode) { + this.set("connectMode", mode); + this.connectMode = mode; + return this; + } + + public long getLinkId() { + return linkId; + } + + public OperLogMessage setLinkId(long linkId) { + this.set("linkId", linkId); + this.linkId = linkId; + return this; + } + + public String getOperateResult() { + return operateResult; + } + + public OperLogMessage setOperateResult(String operateResult) { + this.set("operateResult", operateResult); + this.operateResult = operateResult; + return this; + } + + public String getRank() { + return rank; + } + + public OperLogMessage setRank(String rank) { + this.set("rank", rank); + this.rank = rank; + return this; + } + + public String getDescriptionInfo() { + return descriptionInfo; + } + + public OperLogMessage setDescriptionInfo(String desc) { + this.setLocale("descriptionInfo", desc); + descriptionInfo = desc; + return this; + } + + public String getOperation() { + return operation; + } + + public OperLogMessage setOperation(String operation) { + this.setLocale("operation", operation); + this.operation = operation; + return this; + } + + public String[] getResourceIP() { + return resourceIP; + } + + public OperLogMessage setResourceIP(String[] resourceIP) { + this.set("resourceIP", resourceIP); + this.resourceIP = resourceIP; + return this; + } + + public Date getLogStartDate() { + return logStartDate; + } + + public OperLogMessage setLogStartDate(Date logStartDate) { + this.set("logStartDate", Facitility.dateFormat(logStartDate)); + this.logStartDate = logStartDate; + return this; + } + + public Date getLogEndDate() { + return logEndDate; + } + + public OperLogMessage setLogEndDate(Date logEndDate) { + this.set("logEndDate", Facitility.dateFormat(logEndDate)); + this.logEndDate = logEndDate; + return this; + } + + public int getIsDisplay() { + return isDisplay; + } + + public OperLogMessage setIsDisplay(int isDisplay) { + this.set("isDisplay", isDisplay); + this.isDisplay = isDisplay; + return this; + } + + public String[] getOperateResource() { + return operateResource; + } + + public OperLogMessage setOperateResource(String[] operateResource) { + this.set("operateResource", operateResource); + this.operateResource = operateResource; + return this; + } + + public String getOperationType() { + return operationType; + } + + public OperLogMessage setOperationType(String operationType) { + + this.operationType = operationType; + return this; + } + + + + public OperLogMessage setHostname(String hostname) { + this.set("hostname", hostname); + this.hostname = hostname; + return this; + } + + + public LogMessage setId(long id) { + this.set("id", id); + this.id = id; + return this; + } + + + public LogMessage setDetail(String detail) { + this.detail = detail; + this.setLocale("detail", detail); + return this; + } + +} diff --git a/logging-sdk/src/main/java/org/openo/log/api/SecLogMessage.java b/logging-sdk/src/main/java/org/openo/log/api/SecLogMessage.java new file mode 100644 index 0000000..7eafbf7 --- /dev/null +++ b/logging-sdk/src/main/java/org/openo/log/api/SecLogMessage.java @@ -0,0 +1,146 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.log.api; + +import java.util.Date; + +import org.openo.log.impl.Facitility; +import org.openo.log.impl.LogConst; + +public class SecLogMessage extends LogMessage { + + private static final long serialVersionUID = 201603100924009L; + + + public SecLogMessage() { + super(); + this.setLogType(LogConst.SERLOG_TYPE); + } + + + public SecLogMessage(String userName, String hostname, String detail, String logName, + Date logDate) { + super(); + this.setLogType(LogConst.SERLOG_TYPE); + + this.userName = userName; + this.set("userName", userName); + + this.hostname = hostname; + this.set("hostname", hostname); + + this.logName = logName; + this.setLocale("logName", logName); + + this.detail = detail; + this.setLocale("detail", detail); + + this.logDate = logDate; + this.set("logDate", Facitility.dateFormat(logDate)); + } + + protected String userName = ""; + + + protected String logName = null; + + + protected String connectMode = ""; + + + protected String systemID = ""; + + protected String mac = ""; + + public String getMac() { + return mac; + } + + public SecLogMessage setMac(String mac) { + this.set("mac", mac); + this.mac = mac; + return this; + } + + + protected Date logDate = null; + + + public String getUserName() { + + return userName; + } + + + public SecLogMessage setUserName(String userName) { + this.set("userName", userName); + this.userName = userName; + return this; + } + + + public String getConnectMode() { + return connectMode; + } + + + public SecLogMessage setConnectMode(String connectMode) { + this.set("connectMode", connectMode); + this.connectMode = connectMode; + return this; + } + + public String getLogName() { + return logName; + } + + public SecLogMessage setLogName(String logName) { + this.setLocale("logName", logName); + this.logName = logName; + return this; + } + + public Date getLogDate() { + return logDate; + } + + public SecLogMessage setLogDate(Date logDate) { + this.set("logDate", Facitility.dateFormat(logDate)); + this.logDate = logDate; + return this; + } + + public SecLogMessage setHostname(String hostname) { + this.set("hostname", hostname); + this.hostname = hostname; + return this; + } + + + public SecLogMessage setId(long id) { + this.set("id", id); + this.id = id; + return this; + } + + + public SecLogMessage setDetail(String detail) { + this.detail = detail; + this.setLocale("detail", detail); + return this; + } + +} diff --git a/logging-sdk/src/main/java/org/openo/log/api/SysLogMessage.java b/logging-sdk/src/main/java/org/openo/log/api/SysLogMessage.java new file mode 100644 index 0000000..6c389bf --- /dev/null +++ b/logging-sdk/src/main/java/org/openo/log/api/SysLogMessage.java @@ -0,0 +1,180 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.log.api; + +import java.util.Date; + +import org.openo.log.impl.Facitility; +import org.openo.log.impl.LogConst; + + +public class SysLogMessage extends LogMessage { + private static final long serialVersionUID = 200408041707009L; + + + protected String rank = LogService.SYSLOG_RANK_INFORM; + + protected String source = null; + + protected String sourceId = ""; + + protected String logName = null; + + + protected Date logStartDate = null; + + protected Date logEndDate = null; + + protected int isDisplay = LogService.LOG_DISPLAY; + + protected long linkId = -100; + + + public SysLogMessage() { + super(); + this.setLogType(LogConst.SYSLOG_TYPE); + } + + + public SysLogMessage(String logName, String hostname, String rank, String detail, + Date logStartDate, Date logEndDate) { + super(); + this.setLogType(LogConst.SYSLOG_TYPE); + + this.logName = logName; + this.setLocale("logName", logName); + + this.rank = rank; + this.set("rank", rank); + + this.hostname = hostname; + this.set("hostname", hostname); + + this.detail = detail; + this.setLocale("detail", detail); + + this.logStartDate = logStartDate; + this.set("logStartDate", Facitility.dateFormat(logStartDate)); + + this.logEndDate = logEndDate; + this.set("logEndDate", Facitility.dateFormat(logEndDate)); + } + + public Date getLogStartDate() { + return logStartDate; + } + + public SysLogMessage setLogStartDate(Date logStartDate) { + this.set("logStartDate", Facitility.dateFormat(logStartDate)); + this.logStartDate = logStartDate; + return this; + } + + public Date getLogEndDate() { + return logEndDate; + } + + public SysLogMessage setLogEndDate(Date logEndDate) { + this.set("logEndDate", Facitility.dateFormat(logEndDate)); + this.logEndDate = logEndDate; + return this; + } + + public String getRank() { + return rank; + } + + public SysLogMessage setRank(String rank) { + this.set("rank", rank); + this.rank = rank; + return this; + } + + public String getLogName() { + return logName; + } + + public SysLogMessage setLogName(String logName) { + this.setLocale("logName", logName); + this.logName = logName; + return this; + } + + + public final String getSource() { + return source; + } + + + public SysLogMessage setSource(String source) { + this.setLocale("source", source); + this.source = source; + return this; + } + + public int getIsDisplay() { + return isDisplay; + } + + public SysLogMessage setIsDisplay(int isDisplay) { + this.set("isDisplay", isDisplay); + this.isDisplay = isDisplay; + return this; + } + + public long getLinkId() { + return linkId; + } + + public String getSourceId() { + return sourceId; + } + + public SysLogMessage setSourceId(String sourceId) { + this.set("sourceId", sourceId); + this.sourceId = sourceId; + return this; + } + + public SysLogMessage setLinkId(long linkId) { + this.set("linkId", linkId); + this.linkId = linkId; + return this; + } + + public SysLogMessage setHostname(String hostname) { + this.set("hostname", hostname); + this.hostname = hostname; + return this; + } + + + public SysLogMessage setId(long id) { + this.set("id", id); + this.id = id; + return this; + } + + + public SysLogMessage setDetail(String detail) { + this.detail = detail; + this.setLocale("detail", detail); + return this; + } + + + +} |