Search in sources :

Example 1 with TimeZoneInfo

use of com.zimbra.soap.admin.type.TimeZoneInfo in project zm-mailbox by Zimbra.

the class GetServiceStatus method handle.

public Element handle(Element request, Map<String, Object> context) throws SoapFaultException, ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    // this command can only execute on the monitor host, so proxy if necessary
    Provisioning prov = Provisioning.getInstance();
    String monitorHost = prov.getConfig().getAttr(Provisioning.A_zimbraLogHostname);
    if (monitorHost == null || monitorHost.trim().equals(""))
        throw ServiceException.FAILURE("zimbraLogHostname is not configured", null);
    Server monitorServer = prov.get(Key.ServerBy.name, monitorHost);
    if (monitorServer == null)
        throw ServiceException.FAILURE("could not find zimbraLogHostname server: " + monitorServer, null);
    if (!prov.getLocalServer().getId().equalsIgnoreCase(monitorServer.getId()))
        return proxyRequest(request, context, monitorServer);
    GetServiceStatusResponse resp = new GetServiceStatusResponse();
    TimeZone tz = TimeZone.getDefault();
    TimeZoneInfo timezone = TimeZoneInfo.fromIdAndDisplayName(tz.getID(), tz.getDisplayName());
    resp.setTimezone(timezone);
    boolean loggerEnabled = false;
    Server local = prov.getLocalServer();
    String[] services = local.getMultiAttr(Provisioning.A_zimbraServiceEnabled);
    if (services != null) {
        for (int i = 0; i < services.length && !loggerEnabled; i++) {
            loggerEnabled = "logger".equals(services[i]);
        }
    }
    if (loggerEnabled) {
        HashSet<ServiceStatus> serviceStatus = Sets.newHashSet();
        List<Server> servers = prov.getAllServers();
        for (Server s : servers) {
            String[] srvs = s.getMultiAttr(Provisioning.A_zimbraServiceEnabled);
            for (String service : srvs) {
                serviceStatus.add(ServiceStatus.fromServerServiceTimeStatus(s.getName(), service, System.currentTimeMillis() / 1000, ZeroOrOne.ZERO));
            }
        }
        BufferedReader in = null;
        try {
            ProcessBuilder pb = new ProcessBuilder(ZMRRDFETCH, "-f", ZMSTATUSLOG_CSV);
            Process p = pb.start();
            in = new BufferedReader(new InputStreamReader(p.getInputStream()));
            Map<String, CsvReader> hostStatus = new HashMap<String, CsvReader>();
            StringWriter currentWriter = null;
            String currentHost = null;
            String line;
            while ((line = in.readLine()) != null) {
                if ("".equals(line.trim()))
                    continue;
                if (line.startsWith("Host: ")) {
                    if (currentHost != null)
                        hostStatus.put(currentHost, new CsvReader(new StringReader(currentWriter.toString())));
                    currentHost = line.substring("Host: ".length());
                    currentWriter = new StringWriter();
                } else {
                    if (currentWriter != null)
                        currentWriter.write(line + "\n");
                }
            }
            if (currentHost != null && currentWriter != null)
                hostStatus.put(currentHost, new CsvReader(new StringReader(currentWriter.toString())));
            List<ServiceStatus> status = ServiceStatus.parseData(hostStatus);
            for (ServiceStatus stat : status) {
                serviceStatus.remove(stat);
                serviceStatus.add(stat);
            }
            for (ServiceStatus stat : serviceStatus) {
                if (!checkRights(zsc, stat.getServer())) {
                    ZimbraLog.misc.info("skipping server " + stat.getServer() + ", has not right to get service status");
                    continue;
                }
                resp.addServiceStatus(stat);
            }
        } catch (IOException e) {
            try {
                if (in != null)
                    in.close();
            } catch (IOException x) {
            }
            ServiceException.FAILURE("Unable to read logger stats", e);
        }
    }
    return zsc.jaxbToElement(resp);
}
Also used : Server(com.zimbra.cs.account.Server) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) TimeZoneInfo(com.zimbra.soap.admin.type.TimeZoneInfo) IOException(java.io.IOException) Provisioning(com.zimbra.cs.account.Provisioning) CsvReader(com.zimbra.common.util.CsvReader) TimeZone(java.util.TimeZone) StringWriter(java.io.StringWriter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) ServiceStatus(com.zimbra.soap.admin.type.ServiceStatus) GetServiceStatusResponse(com.zimbra.soap.admin.message.GetServiceStatusResponse) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader)

Aggregations

CsvReader (com.zimbra.common.util.CsvReader)1 Provisioning (com.zimbra.cs.account.Provisioning)1 Server (com.zimbra.cs.account.Server)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GetServiceStatusResponse (com.zimbra.soap.admin.message.GetServiceStatusResponse)1 ServiceStatus (com.zimbra.soap.admin.type.ServiceStatus)1 TimeZoneInfo (com.zimbra.soap.admin.type.TimeZoneInfo)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 TimeZone (java.util.TimeZone)1