Search in sources :

Example 1 with AuditEventData

use of org.xipki.audit.AuditEventData in project xipki by xipki.

the class SyslogAuditServiceImpl method logEvent0.

@Override
protected void logEvent0(AuditEvent event) {
    if (!initialized) {
        LOG.error("syslog audit not initialized");
        return;
    }
    CharArrayWriter sb = new CharArrayWriter(150);
    if (notEmpty(prefix)) {
        sb.append(prefix);
    }
    AuditStatus status = event.getStatus();
    if (status == null) {
        status = AuditStatus.UNDEFINED;
    }
    sb.append("\tstatus: ").append(status.name());
    long duration = event.getDuration();
    if (duration >= 0) {
        sb.append("\tduration: ").append(Long.toString(duration));
    }
    List<AuditEventData> eventDataArray = event.getEventDatas();
    for (AuditEventData m : eventDataArray) {
        if (duration >= 0 && "duration".equalsIgnoreCase(m.getName())) {
            continue;
        }
        sb.append("\t").append(m.getName()).append(": ").append(m.getValue());
    }
    final int n = sb.size();
    if (n > maxMessageLength) {
        LOG.warn("syslog message exceeds the maximal allowed length: {} > {}, ignore it", n, maxMessageLength);
        return;
    }
    SyslogMessage sm = new SyslogMessage();
    sm.setFacility(syslog.getDefaultFacility());
    if (notEmpty(localname)) {
        sm.setHostname(localname);
    }
    sm.setAppName(event.getApplicationName());
    sm.setSeverity(getSeverity(event.getLevel()));
    Date timestamp = event.getTimestamp();
    if (timestamp != null) {
        sm.setTimestamp(timestamp);
    }
    sm.setMsgId(event.getName());
    sm.setMsg(sb);
    try {
        syslog.sendMessage(sm);
    } catch (IOException ex) {
        LOG.error("could not send syslog message: {}", ex.getMessage());
        LOG.debug("could not send syslog message", ex);
    }
}
Also used : AuditStatus(org.xipki.audit.AuditStatus) SyslogMessage(com.cloudbees.syslog.SyslogMessage) IOException(java.io.IOException) AuditEventData(org.xipki.audit.AuditEventData) CharArrayWriter(java.io.CharArrayWriter) Date(java.util.Date)

Aggregations

SyslogMessage (com.cloudbees.syslog.SyslogMessage)1 CharArrayWriter (java.io.CharArrayWriter)1 IOException (java.io.IOException)1 Date (java.util.Date)1 AuditEventData (org.xipki.audit.AuditEventData)1 AuditStatus (org.xipki.audit.AuditStatus)1