}
// Build a new list containing the event sources that are enabled.
List<PropertyMap> enabledEventSources = new ArrayList<PropertyMap>();
for (Property prop : logEventSources.getList()) {
PropertyMap logEventSource = (PropertyMap) prop;
String enabled = logEventSource.getSimpleValue(LogEventSourcePropertyNames.ENABLED, null);
if (enabled == null) {
throw new IllegalStateException("Required property [" + LogEventSourcePropertyNames.ENABLED
+ "] is not defined in map.");
}
if (Boolean.valueOf(enabled)) {
enabledEventSources.add(logEventSource);
}
}
// Log a warning then return if SIGAR isn't available, since LogFileEventPoller depends on it. We only log this
// warning if at least one event source is enabled, since otherwise the user probably doesn't care.
boolean sigarAvailable = this.resourceContext.getSystemInformation().isNative();
if (!sigarAvailable && !enabledEventSources.isEmpty()) {
boolean nativeSystemInfoDisabled = SystemInfoFactory.isNativeSystemInfoDisabled();
ResourceType resourceType = this.resourceContext.getResourceType();
List<String> logFilePaths = getLogFilePaths(enabledEventSources);
LOG.warn("Log files " + logFilePaths + " for [" + resourceType.getPlugin() + ":"
+ resourceType.getName() + "] Resource with key [" + this.resourceContext.getResourceKey()
+ "] cannot be polled, because log file polling requires RHQ native support, which "
+ ((nativeSystemInfoDisabled) ? "has been disabled for this Agent" : "is not available on this platform") + ".");
return;
}
// Start up log file pollers for each of the enabled event sources.
for (PropertyMap logEventSource : enabledEventSources) {
String logFilePath = logEventSource.getSimpleValue(LogEventSourcePropertyNames.LOG_FILE_PATH, null);
if (logFilePath == null) {
throw new IllegalStateException("Required property [" + LogEventSourcePropertyNames.LOG_FILE_PATH
+ "] is not defined in map.");
}
File logFile = new File(logFilePath);
if (!logFile.canRead()) {
LOG.warn("LOGFILE: Logfile at location " + logFilePath + " does not exist or is not readable. "
+ "The poller will be started but no events will be polled until the file is created.");
}
Log4JLogEntryProcessor processor = new Log4JLogEntryProcessor(LOG_ENTRY_EVENT_TYPE, logFile);
String dateFormatString = logEventSource.getSimpleValue(LogEventSourcePropertyNames.DATE_FORMAT, null);
if (dateFormatString != null) {
try {
DateFormat dateFormat = new SimpleDateFormat(dateFormatString); // TODO locale specific ?
processor.setDateFormat(dateFormat);
} catch (IllegalArgumentException e) {
throw new InvalidPluginConfigurationException("Date format [" + dateFormatString
+ "] is not a valid simple date format.");
}
}
String includesPatternString = logEventSource.getSimpleValue(
LogEventSourcePropertyNames.INCLUDES_PATTERN, null);
if (includesPatternString != null) {
try {
Pattern includesPattern = Pattern.compile(includesPatternString);
processor.setIncludesPattern(includesPattern);
} catch (PatternSyntaxException e) {
throw new InvalidPluginConfigurationException("Includes pattern [" + includesPatternString
+ "] is not a valid regular expression.");
}
}
String minimumSeverityString = logEventSource.getSimpleValue(
LogEventSourcePropertyNames.MINIMUM_SEVERITY, null);
if (minimumSeverityString != null) {
EventSeverity minimumSeverity = EventSeverity.valueOf(minimumSeverityString.toUpperCase());
processor.setMinimumSeverity(minimumSeverity);
}