Is there a way to generate a report via the command-line or groovy script?

I would like the option to generate a report (example, template "Physical Host Load Summary") from the command-line, where I can supply the parameters that it requires.   Is there such a way to do this in groovy?

  • Hello. Here is a simple groovy script which creates a report from "Physical Host Load Summary" template

    import com.quest.nitro.service.sl.interfaces.reporting.ReportDefinition

    import com.quest.nitro.service.sl.interfaces.reporting.ReportContext

     

    repService=server.ReportingService

    reps = repService.listAvailableReports()

    ReportDefinition rep

     

    reps.each {

     

      if (it.getName().equals("Physical Host Load Summary")) {

          rep = it

      }

    }

    if (rep!=null) {

      ReportContext con = repService.createReportContext(rep)

      finalRep = repService.generateReport(con, "My Report")

      return finalRep

    }

    else {

      return "ERROR: Cannot find template"

    }


    Hope that helps.

    Merve

  • Hi Merve,

    This is great!     But what about setting my own title and timeRange for the report?   "My Report" does not appear in the "Name" column in the "Generated Reports" table of Manage Reports.  Only "n/a" appears.  If I can set these two parameters for the report, then it will be perfect.

    Thanks!

  • You can set the timeRange paramaeter on the report before generating it as follows:

    import com.quest.wcf.data.wcfdo.SpecificTimeRange

    import com.quest.wcf.core.timerange.LastNTimeRange;

    repService = server.ReportingService

    reps = repService.listAvailableReports()

    def rep = reps.find { it.name == "Physical Host Load Summary" }

    if (rep!=null)

    {

        con = repService.createReportContext(rep);

        con.setReportName("MyScriptedReport")

        // Generate the report for the last 7 days.

        LastNTimeRange tr = new LastNTimeRange(LastNTimeRange.Unit.day, 7, SpecificTimeRange.GRANULARITY_AUTO);

        con.setParameter("timeRange", tr);

        con.setGeneratedManually(true)

        finalRep = repService.generateReport(con, null)

    }

    else {

      return "ERROR: Cannot find template"

    }

  • Thanks Louis.  How about if I wanted to set the startTime and endTime of the timeRange.  Example:  From "2012-03-10 00:00:00" to "2012-03-13 12:30:00".   How would that be done?

  • You can create a Custom time range. So, in the code above, add the following import

    import com.quest.wcf.core.timerange.CustomTimeRange

    and replace LastNTimeRange tr = new LastNTimeRange(LastNTimeRange.Unit.day, 7, SpecificTimeRange.GRANULARITY_AUTO) with something like

        // 2012-03-10 00:00:00" to "2012-03-13 12:30:00".  

        start = new GregorianCalendar(2012,3,10,0,0,0).time

        end   = new GregorianCalendar(2012,3,10,12,30,0).time

        CustomTimeRange tr = new CustomTimeRange( start, end, SpecificTimeRange.GRANULARITY_AUTO )

    Regards

    Louis

  • Unfortunately, I am getting:

    script1001591.groovy: 1: unable to resolve class com.quest.wcf.core.timerange.CustomTimeRange

    @ line 1, column 1.

       import com.quest.wcf.core.timerange.CustomTimeRange

    My FMS version is 5.5.8.2

  • The code I listed above executes without error on Foglight 5.6.2. Try the following import, which I have seen in older posts:

    import com.quest.wcf.core.timerange.impl.CustomTimeRange

    Regards

    Louis

  • I get a different error now:

    Error : com.quest.nitro.service.sl.interfaces.scripting.ScriptAbortException: script1001595: groovy.lang.MissingPropertyException: No such property: GRANULARITY_AUTO for class: com.quest.wcf.data.wcfdo.SpecificTimeRange

    Here's the code:

    import com.quest.wcf.core.timerange.impl.CustomTimeRange

    import com.quest.wcf.data.wcfdo.SpecificTimeRange

    // 2012-03-10 00:00:00" to "2012-03-13 12:30:00".

    start = new GregorianCalendar(2012,3,5,0,0,0).time

    end   = new GregorianCalendar(2012,3,9,0,0,0).time

    CustomTimeRange tr = new CustomTimeRange( start, end, SpecificTimeRange.GRANULARITY_AUTO )

    repService = server.ReportingService

    reps = repService.listAvailableReports()

    def rep = reps.find { it.name == "WebSphere Server Performance Report" }

    if (rep!=null)

    {

        con = repService.createReportContext(rep);

        con.setReportName("MyScriptedReport")

        con.setParameter("timeRange", tr);

        con.setGeneratedManually(true)

        finalRep = repService.generateReport(con, null)

    }

    else {

      return "ERROR: Cannot find template"

    }

  • Ok, maybe this constant is not declared in 5.5.8.2 yet. Just replace it with -1

  • That worked!   Thanks Louis for helping.  This will be a big help for me