blob: 8ec940a8e5161b3fba0acd746cf7d93d10b0099f [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.metron.helpers.topology;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.json.simple.JSONObject;
public class ErrorGenerator {
@SuppressWarnings("unchecked")
public static JSONObject generateErrorMessage(String message, Exception e)
{
JSONObject error_message = new JSONObject();
/*
* Save full stack trace in object.
*/
String stackTrace = ExceptionUtils.getStackTrace(e);
String exception = e.toString();
error_message.put("time", System.currentTimeMillis());
try {
error_message.put("hostname", InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
error_message.put("message", message);
error_message.put("exception", exception);
error_message.put("stack", stackTrace);
return error_message;
}
}