Assemble a report from Nagios email alerts

Discussion in 'Programming/Scripts' started by forrie, Aug 3, 2013.

  1. forrie

    forrie New Member

    Nagios cycles its data (at least ours has) -- I have several hundred email alerts provided to me (by my boss!) who's asked me to tabulate them into some meaningful graph (RRD) and/or report.

    He provided these all one big fat TXT file. Each entry is standard format (email) and has the standard Nagios email alert formatting. From this, I should be able to parse out and graph these... it's just not something I've done before.

    I wonder if someone else has any tips or tricks on accomplishing this.

    Here is a sample entry:

    Thanks in advance!
  2. RandomGuy

    RandomGuy New Member

    Use a programing language and do something like

    InputFile in;
    String line;
    List output;
    String[] row;
    // Read input
    while(line = in.readLine()) {
    if(line.equals("***** Nagios *****") {
    // Start a new entry and push it to the output list
    output.add(row = new String[3]);
    } else if(line.startsWith("Service") {
    // Read your fields
    row[0] = line.split(":")[1].trim();
    } else if(line.startWith("Host") {
    // Read your fields
    row[1] = line.split(":")[1].trim();
    /** Read the other fields you need in the same fashion **/

    // Produce output
    OutputFile out;
    for(String[] row : output){
    out.println(row[0] + "," + row[1] + "," + row[2]
    /** Write all your output fields to a row **/

    This will generate a csv (comma separated values) files where each entry is one row with each field in one column. You can then open this file in any office suite like OpenOffice, Microsoft office or even with Google Docs. There you can generate all kinds of statistics and graphs you require and then export the whole thing to something like pdf.
    Personaly I would use java to write somthing like that, but you can really do something like that in any programming language that you are familiar with.

Share This Page