@Override public StateReport getReport(String domain) { StateReport report = new StateReport(Constants.CAT); report.setStartTime(new Date(m_startTime)); report.setEndTime(new Date(m_startTime + MINUTE * 60 - 1)); Machine machine = buildStateInfo(report.findOrCreateMachine(m_ip)); StateReport stateReport = m_reportManager.getHourlyReport(getStartTime(), Constants.CAT, true); Map<String, ProcessDomain> processDomains = stateReport.findOrCreateMachine(m_ip).getProcessDomains(); for (Map.Entry<String, ProcessDomain> entry : machine.getProcessDomains().entrySet()) { ProcessDomain processDomain = processDomains.get(entry.getKey()); if (processDomain != null) { entry.getValue().getIps().addAll(processDomain.getIps()); } } return report; }
@Override protected void process(MessageTree tree) { StateReport report = m_reportManager.getHourlyReport(getStartTime(), Constants.CAT, true); String domain = tree.getDomain(); String ip = tree.getIpAddress(); Machine machine = report.findOrCreateMachine(NetworkInterfaceManager.INSTANCE.getLocalHostAddress()); machine.findOrCreateProcessDomain(domain).addIp(ip); if (m_serverConfigManager.validateDomain(domain)) { if (!m_domainManager.containsDomainInCat(domain)) { boolean insert = m_domainManager.insertDomain(domain); if (!insert) { m_logger.warn(String.format("Error when insert domain %s info", domain)); } } Hostinfo info = m_domainManager.queryHostInfoByIp(ip); if (info == null) { m_domainManager.insert(domain, ip); } else { String oldDomain = info.getDomain(); if (!oldDomain.equals(domain) && !oldDomain.equals(Constants.CAT)) { // only work on online environment long current = System.currentTimeMillis(); Date lastModifiedDate = info.getLastModifiedDate(); if (lastModifiedDate != null && (current - lastModifiedDate.getTime()) > ONE_HOUR) { m_domainManager.update(info.getId(), domain, ip); m_logger.info( String.format("old domain is %s , change ip %s to %s", oldDomain, ip, domain)); } } } } }