Search in sources :

Example 1 with AuditEventBase

use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.

the class DBAuditDestination method log.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.apache.ranger.audit.provider.AuditHandler#logger(java.util.Collection
	 * )
	 */
@Override
public boolean log(Collection<AuditEventBase> events) {
    boolean retValue = false;
    logStatusIfRequired();
    addTotalCount(events.size());
    if (beginTransaction()) {
        boolean isFailed = false;
        for (AuditEventBase event : events) {
            try {
                event.persist(daoManager);
            } catch (Throwable t) {
                logger.error("Error persisting data. event=" + event, t);
                isFailed = true;
                break;
            }
        }
        if (isFailed) {
            retValue = false;
            rollbackTransaction();
        } else {
            retValue = commitTransaction();
        }
    }
    if (retValue) {
        addSuccessCount(events.size());
    } else {
        addDeferredCount(events.size());
    }
    return retValue;
}
Also used : AuditEventBase(org.apache.ranger.audit.model.AuditEventBase)

Example 2 with AuditEventBase

use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.

the class FileAuditDestination method log.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.apache.ranger.audit.provider.AuditProvider#log(java.util.Collection)
	 */
@Override
public boolean log(Collection<AuditEventBase> events) {
    if (isStopped) {
        addTotalCount(events.size());
        addDeferredCount(events.size());
        logError("log() called after stop was requested. name=" + getName());
        return false;
    }
    List<String> jsonList = new ArrayList<String>();
    for (AuditEventBase event : events) {
        try {
            jsonList.add(MiscUtil.stringify(event));
        } catch (Throwable t) {
            addTotalCount(1);
            addFailedCount(1);
            logFailedEvent(event);
            logger.error("Error converting to JSON. event=" + event);
        }
    }
    return logJSON(jsonList);
}
Also used : AuditEventBase(org.apache.ranger.audit.model.AuditEventBase) ArrayList(java.util.ArrayList)

Example 3 with AuditEventBase

use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.

the class HDFSAuditDestination method log.

/*
	 * (non-Javadoc)
	 *
	 * @see
	 * org.apache.ranger.audit.provider.AuditProvider#log(java.util.Collection)
	 */
@Override
public boolean log(Collection<AuditEventBase> events) {
    if (isStopped) {
        logStatusIfRequired();
        addTotalCount(events.size());
        addDeferredCount(events.size());
        logError("log() called after stop was requested. name=" + getName());
        return false;
    }
    List<String> jsonList = new ArrayList<String>();
    for (AuditEventBase event : events) {
        try {
            jsonList.add(MiscUtil.stringify(event));
        } catch (Throwable t) {
            logger.error("Error converting to JSON. event=" + event);
            addTotalCount(1);
            addFailedCount(1);
            logFailedEvent(event);
        }
    }
    return logJSON(jsonList);
}
Also used : AuditEventBase(org.apache.ranger.audit.model.AuditEventBase)

Example 4 with AuditEventBase

use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.

the class SolrAuditDestination method log.

@Override
public boolean log(Collection<AuditEventBase> events) {
    boolean ret = false;
    try {
        logStatusIfRequired();
        addTotalCount(events.size());
        if (solrClient == null) {
            connect();
            if (solrClient == null) {
                // Solr is still not initialized. So need return error
                addDeferredCount(events.size());
                return ret;
            }
        }
        final Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
        for (AuditEventBase event : events) {
            AuthzAuditEvent authzEvent = (AuthzAuditEvent) event;
            // Convert AuditEventBase to Solr document
            SolrInputDocument document = toSolrDoc(authzEvent);
            docs.add(document);
        }
        try {
            final UpdateResponse response = SolrAppUtil.addDocsToSolr(solrClient, docs);
            if (response.getStatus() != 0) {
                addFailedCount(events.size());
                logFailedEvent(events, response.toString());
            } else {
                addSuccessCount(events.size());
                ret = true;
            }
        } catch (SolrException ex) {
            addFailedCount(events.size());
            logFailedEvent(events, ex);
        }
    } catch (Throwable t) {
        addDeferredCount(events.size());
        logError("Error sending message to Solr", t);
    }
    return ret;
}
Also used : AuthzAuditEvent(org.apache.ranger.audit.model.AuthzAuditEvent) UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) AuditEventBase(org.apache.ranger.audit.model.AuditEventBase) ArrayList(java.util.ArrayList) SolrException(org.apache.solr.common.SolrException)

Example 5 with AuditEventBase

use of org.apache.ranger.audit.model.AuditEventBase in project ranger by apache.

the class AsyncAuditProvider method dequeueEvent.

private AuditEventBase dequeueEvent() throws InterruptedException {
    AuditEventBase ret = mQueue.poll();
    while (ret == null) {
        logSummaryIfRequired();
        if (mMaxFlushInterval > 0) {
            long timeTillNextFlush = getTimeTillNextFlush();
            if (timeTillNextFlush <= 0) {
                // force flush
                break;
            }
            ret = mQueue.poll(timeTillNextFlush, TimeUnit.MILLISECONDS);
        } else {
            // Let's wake up for summary logging
            long waitTime = intervalLogDurationMS - (System.currentTimeMillis() - lastIntervalLogTime);
            waitTime = waitTime <= 0 ? intervalLogDurationMS : waitTime;
            ret = mQueue.poll(waitTime, TimeUnit.MILLISECONDS);
        }
    }
    if (ret != null) {
        lifeTimeOutLogCount.incrementAndGet();
        intervalOutLogCount.incrementAndGet();
    }
    logSummaryIfRequired();
    return ret;
}
Also used : AuditEventBase(org.apache.ranger.audit.model.AuditEventBase)

Aggregations

AuditEventBase (org.apache.ranger.audit.model.AuditEventBase)15 ArrayList (java.util.ArrayList)4 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 AuthzAuditEvent (org.apache.ranger.audit.model.AuthzAuditEvent)1 AuditHandler (org.apache.ranger.audit.provider.AuditHandler)1 DebugTracer (org.apache.ranger.audit.provider.DebugTracer)1 LocalFileLogBuffer (org.apache.ranger.audit.provider.LocalFileLogBuffer)1 Log4jTracer (org.apache.ranger.audit.provider.Log4jTracer)1 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)1 SolrException (org.apache.solr.common.SolrException)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1