Ejemplo n.º 1
0
  public String getJsonData(Map<String, List<String>> params) {
    Db db = null;

    StringBuilder sb = new StringBuilder();

    try {
      db = DbPool.pick();

      ResultSet queryResult = getResultSet(db, params);
      if (queryResult == null) return "";

      boolean first = true;

      while (queryResult.next()) {
        if (first) {
          first = false;
        } else {
          sb.append(",");
        }
        int idx = 1;
        sb.append("{");

        sb.append("\"id\":\"");
        sb.append(queryResult.getInt(idx++));
        sb.append("\",");

        sb.append("\"agentName\":\"");
        String agentName = queryResult.getString(idx++);
        sb.append(agentName);
        sb.append("\",");

        sb.append("\"agentHostname\":\"");
        sb.append(AgentHostname.get(agentName));
        sb.append("\",");

        sb.append("\"time\":\"");
        sb.append(DateUtil.formatISODate(new Date(queryResult.getTimestamp(idx++).getTime())));
        sb.append("\",");

        sb.append("\"message\":\"");
        // sb.append(StringUtils.replace(queryResult.getString(idx++), "\t", ""));
        sb.append(queryResult.getString(idx++));
        sb.append("\",");

        sb.append("\"shortMessage\":\"");
        sb.append(queryResult.getString(idx++));
        sb.append("\"");

        sb.append("}");
      }
    } catch (Throwable t) {
      log.error("Failed to get all queue genral info", t);
    } finally {
      DbPool.release(db);
    }

    return sb.toString();
  }
Ejemplo n.º 2
0
 public String toJson() {
   return String.format(
       "{\"agentName\":\"%s\",\"agentHostname\":\"%s\",\"time\":\"%s\",\"subject\":\"%s\",\"predicate\":\"%s\",\"value\":\"%s\"}",
       this.agentName,
       AgentHostname.get(agentName),
       ISO8601.format(new Date(time)),
       subject,
       predicate,
       value);
 }
Ejemplo n.º 3
0
 public String toJson() {
   return String.format(
       "{\"id\":\"%s\",\"agentName\":\"%s\",\"agentHostname\":\"%s\",\"time\":\"%s\",\"shortMessage\":\"%s\",\"message\":\"%s\"}",
       this.id,
       this.agentName,
       AgentHostname.get(this.agentName),
       ISO8601.format(new Date(time)),
       shortMessage,
       message);
 }