blob: faab22a8f0308daf7fb27dda86802edfdd480d9f [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.eagle.security.auditlog;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Tuple;
import com.typesafe.config.Config;
import org.apache.eagle.security.service.IPZoneEntity;
import org.apache.eagle.security.enrich.AbstractDataEnrichBolt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
public class IPZoneDataEnrichBolt extends AbstractDataEnrichBolt<IPZoneEntity, String> {
private static final Logger LOG = LoggerFactory.getLogger(IPZoneDataEnrichBolt.class);
public IPZoneDataEnrichBolt(Config config) {
super(config, new IPZoneDataEnrichLCM(config));
}
@Override
public void executeWithEnrich(Tuple input, Map<String, IPZoneEntity> map) {
try {
Map<String, Object> toBeCopied = (Map<String, Object>) input.getValue(1);
Map<String, Object> event = new TreeMap<String, Object>(toBeCopied); // shallow copy
IPZoneEntity e = null;
if (map != null) {
e = map.get(event.get("host"));
}
event.put("securityZone", e == null ? "NA" : e.getSecurityZone());
if (LOG.isDebugEnabled()) {
LOG.debug("After IP zone lookup: " + event);
}
collector.emit(Arrays.asList(event.get("user"), event));
} catch (Exception ex) {
LOG.error("error joining data, ignore it", ex);
} finally {
collector.ack(input);
}
}
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("user", "message"));
}
}