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);
}
Aggregations