use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class LocalDBHealthChecker method doHealthCheck.
public List<HealthRecord> doHealthCheck(final PwmApplication pwmApplication) {
if (pwmApplication == null) {
return null;
}
final List<HealthRecord> healthRecords = new ArrayList<>();
final LocalDB localDB = pwmApplication.getLocalDB();
if (localDB == null) {
final String detailedError = pwmApplication.getLastLocalDBFailure() == null ? "unknown, check logs" : pwmApplication.getLastLocalDBFailure().toDebugStr();
healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDB_BAD, detailedError));
return healthRecords;
}
if (LocalDB.Status.NEW == localDB.status()) {
healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDB_NEW));
return healthRecords;
}
if (LocalDB.Status.CLOSED == localDB.status()) {
healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDB_CLOSED));
return healthRecords;
}
if (healthRecords.isEmpty()) {
healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDB_OK));
}
return healthRecords;
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class PwmLogManager method initializeLocalDBLogger.
public static LocalDBLogger initializeLocalDBLogger(final PwmApplication pwmApplication) {
final LocalDB localDB = pwmApplication.getLocalDB();
if (pwmApplication.getApplicationMode() == PwmApplicationMode.READ_ONLY) {
LOGGER.trace("skipping initialization of LocalDBLogger due to read-only mode");
return null;
}
// initialize the localDBLogger
final LocalDBLogger localDBLogger;
final PwmLogLevel localDBLogLevel = pwmApplication.getConfig().getEventLogLocalDBLevel();
try {
localDBLogger = initLocalDBLogger(localDB, pwmApplication);
if (localDBLogger != null) {
PwmLogger.setLocalDBLogger(localDBLogLevel, localDBLogger);
}
} catch (Exception e) {
LOGGER.warn("unable to initialize localDBLogger: " + e.getMessage());
return null;
}
// add appender for other packages;
try {
final LocalDBLog4jAppender localDBLog4jAppender = new LocalDBLog4jAppender(localDBLogger);
localDBLog4jAppender.setThreshold(localDBLogLevel.getLog4jLevel());
for (final Package logPackage : LOGGING_PACKAGES) {
if (logPackage != null && !logPackage.equals(PwmApplication.class.getPackage())) {
final Logger logger = Logger.getLogger(logPackage.getName());
logger.addAppender(localDBLog4jAppender);
logger.setLevel(Level.TRACE);
}
}
} catch (Exception e) {
LOGGER.warn("unable to initialize localDBLogger/extraAppender: " + e.getMessage());
}
return localDBLogger;
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class ExportLocalDBCommand method doCommand.
@Override
void doCommand() throws Exception {
final LocalDB localDB = cliEnvironment.getLocalDB();
final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
if (outputFile.exists()) {
out("outputFile for exportLocalDB cannot already exist");
return;
}
final LocalDBUtility localDBUtility = new LocalDBUtility(localDB);
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
localDBUtility.exportLocalDB(fileOutputStream, System.out, true);
} catch (PwmOperationalException e) {
out("error during export: " + e.getMessage());
}
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class MainClass method createEnv.
private static CliEnvironment createEnv(final CliParameters parameters, final List<String> args) throws Exception {
final Map<String, Object> options = parseCommandOptions(parameters, args);
final File applicationPath = figureApplicationPath(mainOptions);
out("applicationPath=" + applicationPath.getAbsolutePath());
PwmEnvironment.verifyApplicationPath(applicationPath);
final File configurationFile = locateConfigurationFile(applicationPath);
final ConfigurationReader configReader = loadConfiguration(configurationFile);
final Configuration config = configReader.getConfiguration();
final PwmApplication pwmApplication;
final LocalDB localDB;
if (parameters.needsPwmApplication) {
pwmApplication = loadPwmApplication(applicationPath, mainOptions.getApplicationFlags(), config, configurationFile, parameters.readOnly);
localDB = pwmApplication.getLocalDB();
} else if (parameters.needsLocalDB) {
pwmApplication = null;
localDB = loadPwmDB(config, parameters.readOnly, applicationPath);
} else {
pwmApplication = null;
localDB = null;
}
out("environment initialized");
out("");
final Writer outputStream = new OutputStreamWriter(System.out, PwmConstants.DEFAULT_CHARSET);
return CliEnvironment.builder().configurationReader(configReader).configurationFile(configurationFile).config(config).applicationPath(applicationPath).pwmApplication(pwmApplication).localDB(localDB).debugWriter(outputStream).options(options).mainOptions(mainOptions).build();
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class ExportLogsCommand method doCommand.
@Override
void doCommand() throws Exception {
final LocalDB localDB = this.cliEnvironment.getLocalDB();
final LocalDBStoredQueue logQueue = LocalDBStoredQueue.createLocalDBStoredQueue(null, localDB, LocalDB.DB.EVENTLOG_EVENTS);
if (logQueue.isEmpty()) {
out("no logs present");
return;
}
final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
out("outputting " + logQueue.size() + " log events to " + outputFile.getAbsolutePath() + "....");
try (Writer outputWriter = new OutputStreamWriter(new FileOutputStream(outputFile), PwmConstants.DEFAULT_CHARSET)) {
for (final Iterator<String> iter = logQueue.descendingIterator(); iter.hasNext(); ) {
final String loopString = iter.next();
final PwmLogEvent logEvent = PwmLogEvent.fromEncodedString(loopString);
if (logEvent != null) {
outputWriter.write(logEvent.toLogString());
outputWriter.write("\n");
}
}
}
out("output complete");
}
Aggregations