Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
This is the third post from the Autonomous Self-Analysis System blog series. Read "Autonomous Self-Analysis System II" to set up the autonomous self-analysis system this post builds upon. This blog aims to enhance the autonomous self-analysis solution with the feature: show error history for a HANA system by chat bot in Slack.

To recap what have been achieved so far:

  • A chat bot (i.e. Hubot) is started and integrated with a messaging app (i.e. Slack). You can ask the chat bot to do stuff in Slack (e.g. using Hubot native commands).

  • A Tomcat server is started to view the analysis reports.

  • If the HANA system is hanging (i.e. not responding to "select * from dummy" request after 3 minutes), the following will happen:

    • The HANASitter will automatically create a HANA runtime dump.

    • The HANA dump analyzer will be called to generate the analysis report from the HANA runtime dump created.

    • The URL to the analysis report will be created.

    • A Slack message will be sent to a Slack channel and tell what happened and what to do with the analysis report.




The feature 'show error history' can be only implemented once the autonomous self-analysis system mentioned above is achieved. You need to finish the preceding steps in the blog Self-Analysis System II before you start to implement the 'show error history' feature explained in this blog.

Please be noted, this blog is only using a simple example to explain how to implement the function, e.g. the system returns all the analysis reports from the report folder as history issues directly. If you want to run it on your production system, you need to complete the implementation based on the requirements from your real-life scenario. Before running the solution on a production environment, you need to fully test it as you will run it “at your own risk”.

Develop a Web Application to Return Analysis reports for History Issues on the HANA system


To react on the 'show error history' command in Slack, you need to develop an application to return the list of the historical issues. In this blog, I create a Java servlet in Eclipse to check the report folder and return the list of the historical issues with the corresponding analysis reports. Eclipse provide quite good documentation to guide you creating servlets. In this blog, you need to do the following steps:

  1. Create a web application to return the analysis reports. In the following example, I create a Java web application project HdaBot in Eclipse.

    Fig.1 Eclipse Java Web Application Project

  2. In the Java Web Application project, create a Java servlet class GetRuntimedumpsServlet extends HttpServlet. The GetRuntimedumpsServlet just checks the filesystem for reports and returns a list of the analysis reports. Implement the doGet method, doPost method in GetRuntimedumpsServlet.
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, {
    // Specify the file path for saving the analysis reports
    File path = new File("/<report folder>/HANADumpAnalyzer/");

    JSONArray jsonArray = new JSONArray ();
    // Get all the analysis reports under the report folder
    File [] files = path.listFiles();
    Arrays.sort(files, new Comparator<File>(){
    public int compare(File f1, File f2) {
    return Long.valueOf(f2.lastModified()).compareTo(f1.lastModified());
    }
    });
    // Get the key information (e.g. URLs, Runtime dump time) for the analysis reports, Saving the list of analysis reports to a JSONArray
    for (File file : files){
    if (file.isDirectory()) {
    File indexFile = new File (file.getAbsolutePath() + "/analysis.html");
    if (indexFile.exists()) {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("Link", "http://<tomcat server:8080>/reports/HANADumpAnalyzer/"
    + file.getName() + "/analysis.html");

    BufferedReader br = null;
    try {
    br = new BufferedReader(new InputStreamReader(
    new FileInputStream(new File(file.getAbsolutePath() + "/analysis.html"))));
    String s;

    while ((s = br.readLine()) != null) {
    if (s.contains("Runtime dump time:")) {
    int index = s.indexOf("Runtime dump time:");
    jsonObject.put("CreationTime", s.substring(index + "Runtime dump time: ".length(), index
    + "Runtime dump time: ".length() + "2017-06-02 13:59:28 472 Local".length()));
    } else if (s.contains("<tr><th>Host</th><td>")) {
    jsonObject.put("ServerName", s.substring("<tr><th>Host</th><td>".length(), s.length() - "</td></tr>".length()));
    }
    }
    } catch (IOException e) {
    // Add suitable error handling
    } finally {
    try {
    br.close();
    } catch (IOException e) {
    // Add suitable error handling
    }
    }
    jsonObject.put("Reason", "Runtimedump");
    jsonArray.add(jsonObject);
    }
    }
    }
    // Respond the JSONArray(i.e. list of analysis reports) back
    response.setContentType("application/json");
    PrintWriter out = response.getWriter();
    out.println(jsonArray.toString());
    out.flush();
    }

    /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
    }​


  3. Export the project in Eclipse as a war file.
    Right click on a Web project folder and select Export from the pop-up menu. Then select WAR file in the Export window and then select Next. Specify the Web project you want to export (this field is primed if you used the pop-up menu to open the wizard), and specify a location for the new WAR file. Click Finish.

  4. Deploy the war file to the web server (the Tomcat server in this post).
    As in this blog series, we've already set up a Tomcat server for viewing the analysis report. I'm just re-use the same Tomcat server to deploy the war file to return the list of historical HANA issues.
    Go to Tomcat Web Application Manager Page, i.e. via
    HTTP://<servername:port>/manager/html​​

    Go to Deploy section to “Deploy directory or WAR file located on server”, then provide the target directory in the “Context path” and press “Deploy”.


Show Error History by Chat Bot in Slack


As a chat bot, the most common interactions are based on messages. Hubot can respond to messages directly addressed at it via the respond method. The respond method take a regular expression and a callback function as parameters. In our example, When I ask the chat bot to ‘show error history’, the chat bot is expected to list all the historical issues and provide the corresponding analysis reports. In order to respond as expected to command 'show error history', the required steps are:

1. Create show_errorhistory.coffee script under the chat bot script folder (for my chat bot, the script folder is C:\Janix\scripts). Implement the respond method when the chat bot receives 'show error history' command:

  • Call the GetRuntimeDumpsServlet to check the filesystem for reports and return a list of the analysis reports.

  • For each analysis report, print it as one historical issue with the issue information, e.g. HANA server info, time when the issue happened, cause of runtime dump creation etc.


module.exports = (robot) ->
robot.respond /show error history/i, (response) ->
runtimedumps = "\n"
robot.http("http://<tomcat server:8080>/HdaBot
/GetRuntimedumpsServlet").header('Accept',
'application/json').get() (err, res, body) ->
data = JSON.parse body
for k,v of data
runtimedumps = runtimedumps + v.CreationTime + ", " + v.ServerName + ", "
+ v.Reason + ", <" + v.Link + "|Analyze>\n"
response.reply runtimedumps​

start the chat bot when the show_errorhistory.coffee is done.

After finishing the above steps, your chat bot will be able to 'show error history' now!

1 Comment