Search in sources :

Example 1 with FacterData

use of org.gluu.oxtrust.model.FacterData in project oxTrust by GluuFederation.

the class StatusCheckerTimer method processInt.

/**
 * Gather periodically site and server status
 *
 * @param when
 *            Date
 * @param interval
 *            Interval
 */
private void processInt() {
    log.debug("Starting update of configuration status");
    AppConfiguration appConfiguration = configurationFactory.getAppConfiguration();
    if (!appConfiguration.isUpdateStatus()) {
        log.debug("isUpdateStatus");
        return;
    }
    ConfigurationStatus configurationStatus = new ConfigurationStatus();
    OxtrustStat oxtrustStatObject = new OxtrustStat();
    oxtrustStatObject.setGroupCount(String.valueOf(groupService.countGroups()));
    oxtrustStatObject.setPersonCount(String.valueOf(personService.countPersons()));
    log.debug("Setting FactorAttributes");
    FacterData facterData = getFacterData();
    configurationStatus.setHostname(facterData.getHostname());
    oxtrustStatObject.setIpAddress(facterData.getIpaddress());
    oxtrustStatObject.setLoadAvg(facterData.getLoadAverage());
    oxtrustStatObject.setSystemUptime(facterData.getUptime());
    oxtrustStatObject.setFreeDiskSpace(facterData.getFreeDiskSpace());
    oxtrustStatObject.setFreeMemory(facterData.getMemoryfree());
    setHttpdAttributes(configurationStatus);
    try {
        setCertificateExpiryAttributes(configurationStatus);
    } catch (Exception ex) {
        log.error("Failed to check certificate expiration", ex);
    }
    GluuConfiguration configuration = configurationService.getConfiguration();
    GluuOxTrustStat gluuOxTrustStat = configurationService.getOxtrustStat();
    try {
        BeanUtils.copyProperties(configuration, configurationStatus);
        BeanUtils.copyProperties(gluuOxTrustStat, oxtrustStatObject);
    } catch (Exception ex) {
        log.error("Failed to copy status attributes", ex);
    }
    Date currentDateTime = new Date();
    configuration.setLastUpdate(currentDateTime);
    configurationService.updateConfiguration(configuration);
    configurationService.updateOxtrustStat(gluuOxTrustStat);
    log.debug("Configuration status update finished");
}
Also used : AppConfiguration(org.gluu.config.oxtrust.AppConfiguration) ConfigurationStatus(org.gluu.oxtrust.model.status.ConfigurationStatus) GluuOxTrustStat(org.gluu.oxtrust.model.GluuOxTrustStat) FacterData(org.gluu.oxtrust.model.FacterData) OxtrustStat(org.gluu.oxtrust.model.status.OxtrustStat) GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Date(java.util.Date)

Example 2 with FacterData

use of org.gluu.oxtrust.model.FacterData in project oxTrust by GluuFederation.

the class StatusCheckerTimer method getFacterData.

private FacterData getFacterData() {
    FacterData facterData = new FacterData();
    ObjectMapper mapper = new ObjectMapper();
    if (!isLinux()) {
        return facterData;
    }
    CommandLine commandLine = new CommandLine(OxTrustConstants.PROGRAM_FACTER);
    commandLine.addArgument("-j");
    String resultOutput;
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream(4096)) {
        boolean result = ProcessHelper.executeProgram(commandLine, false, 0, bos);
        if (!result) {
            return facterData;
        }
        resultOutput = new String(bos.toByteArray(), "UTF-8");
        facterData = mapper.readValue(resultOutput, FacterData.class);
    } catch (UnsupportedEncodingException ex) {
        log.error("Failed to parse program {} output", OxTrustConstants.PROGRAM_FACTER, ex);
        return facterData;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return facterData;
}
Also used : CommandLine(org.apache.commons.exec.CommandLine) FacterData(org.gluu.oxtrust.model.FacterData) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 FacterData (org.gluu.oxtrust.model.FacterData)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Date (java.util.Date)1 CommandLine (org.apache.commons.exec.CommandLine)1 AppConfiguration (org.gluu.config.oxtrust.AppConfiguration)1 GluuConfiguration (org.gluu.oxtrust.model.GluuConfiguration)1 GluuOxTrustStat (org.gluu.oxtrust.model.GluuOxTrustStat)1 ConfigurationStatus (org.gluu.oxtrust.model.status.ConfigurationStatus)1 OxtrustStat (org.gluu.oxtrust.model.status.OxtrustStat)1