UCSM - Report on all Physical Network Devices VLAN(s) & All UCS Manager VLAN(s) / Combine Reports

Version 4
    Task Name

    Generate a report on all physical network devices and their VLAN(s)

    and all UCS manager vlans

    Description

     

    Prerequisites

    Minimum UCSD version: 5.4.0.2

    CategoryCustom task
    Components
    User Inputs

     

    User Output

    Instructions for Regular Workflow Use:

    Instructions for Regular Workflow Use:

    1. Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
    2. Unzip the file on your computer. Should end up with a .WFD file.
    3. Log in to UCS Director as a user that has "system-admin" privileges.
    4. Navigate to "Policies-->Orchestration" and click on "Import".
    5. Click "Browse" and navigate to the location on your computer where the .WFD file resides. Choose the .WFD file and click "Open".
    6. Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
    7. Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
    8. Click "Submit".
    9. A new folder should appear in "Policies-->Orchestration" that contains the imported workflow. You will now need to update the included tasks with information about the specific environment.

     

    Inspired by Rob Grossman

     

    The workflow:

     

    Screen Shot 2016-02-24 at 4.05.53 PM.png

     

    Custom Task Input:

    Screen Shot 2016-02-24 at 4.06.35 PM.png

     

     

     

    The Resulting e-mail with report:

     

    Screen Shot 2016-02-24 at 4.04.34 PM.png

     

    Screen Shot 2016-02-24 at 4.05.05 PM.png

     

    Workflow log:

     

    Service Request ID: 6247

     

     

     

     

    Feb 24, 2016 21:47:35 UTC Request submitted

    Feb 24, 2016 21:47:39 UTC Executing workflow item number 1

    Feb 24, 2016 21:47:39 UTC Completed workflow item number 0, with status Completed

    Feb 24, 2016 21:47:45 UTC Executing workflow item number 2

    Feb 24, 2016 21:47:45 UTC Trigger context executeWorkFlowStep called

    Feb 24, 2016 21:47:45 UTC Executing custom action Report Get All VLANS (custom_Get ALL VLANs Report)

    Feb 24, 2016 21:47:45 UTC Executing custom action Report Get All VLANS (custom_Get ALL VLANs Report)

    Feb 24, 2016 21:47:45 UTC Executing custom script for Get ALL VLANs Report

    Feb 24, 2016 21:47:48 UTC POD Name = Building A

    Feb 24, 2016 21:47:48 UTC -------------------------------------------

    Feb 24, 2016 21:47:48 UTC Generating pod vlan report

    Feb 24, 2016 21:47:48 UTC Number of rows found = 0

    Feb 24, 2016 21:47:48 UTC POD Name = Building B

    Feb 24, 2016 21:47:48 UTC -------------------------------------------

    Feb 24, 2016 21:47:48 UTC Generating pod vlan report

    Feb 24, 2016 21:47:48 UTC Number of rows found = 0

    Feb 24, 2016 21:47:48 UTC POD Name = Default Datacenter

    Feb 24, 2016 21:47:48 UTC -------------------------------------------

    Feb 24, 2016 21:47:48 UTC Generating pod vlan report

    Feb 24, 2016 21:47:48 UTC Number of rows found = 13

    Feb 24, 2016 21:47:48 UTC Greater then Zero...............:

    Feb 24, 2016 21:47:48 UTC Number of Rows found...............: 13

    Feb 24, 2016 21:47:48 UTC POD Name = Default Pod

    Feb 24, 2016 21:47:48 UTC -------------------------------------------

    Feb 24, 2016 21:47:48 UTC Generating pod vlan report

    Feb 24, 2016 21:47:48 UTC Number of rows found = 0

    Feb 24, 2016 21:47:49 UTC POD Name = LAB Rusty

    Feb 24, 2016 21:47:49 UTC -------------------------------------------

    Feb 24, 2016 21:47:49 UTC Generating pod vlan report

    Feb 24, 2016 21:47:49 UTC Number of rows found = 0

    Feb 24, 2016 21:47:49 UTC POD Name = SmartStackPod

    Feb 24, 2016 21:47:49 UTC -------------------------------------------

    Feb 24, 2016 21:47:49 UTC Generating pod vlan report

    Feb 24, 2016 21:47:49 UTC Number of rows found = 0

    Feb 24, 2016 21:47:49 UTC POD Name = Versa

    Feb 24, 2016 21:47:49 UTC -------------------------------------------

    Feb 24, 2016 21:47:49 UTC Generating pod vlan report

    Feb 24, 2016 21:47:49 UTC Number of rows found = 0

    Feb 24, 2016 21:47:49 UTC -------------------------------------------

    Feb 24, 2016 21:47:49 UTC UCSM Name = DallasUCSM

    Feb 24, 2016 21:47:49 UTC -------------------------------------------

    Feb 24, 2016 21:47:49 UTC Generating UCSM vlan report

    Feb 24, 2016 21:47:49 UTC Number of rows found = 10

    Feb 24, 2016 21:47:49 UTC Greater then Zero...............:

    Feb 24, 2016 21:47:49 UTC Number of Rows found...............: 10

    Feb 24, 2016 21:47:49 UTC UCSM Name = RustyLab

    Feb 24, 2016 21:47:49 UTC -------------------------------------------

    Feb 24, 2016 21:47:49 UTC Generating UCSM vlan report

    Feb 24, 2016 21:47:49 UTC Number of rows found = 11

    Feb 24, 2016 21:47:49 UTC Greater then Zero...............:

    Feb 24, 2016 21:47:49 UTC Number of Rows found...............: 11

    Feb 24, 2016 21:47:49 UTC Sending email

    Feb 24, 2016 21:47:49 UTC Processing output: ReturnStatus

    Feb 24, 2016 21:47:49 UTC output: ReturnStatus is not set

    Feb 24, 2016 21:47:49 UTC Task #1 (Report Get All VLANS (custom_Get ALL VLANs Report)) completed successfully in 4 seconds

    Feb 24, 2016 21:47:49 UTC Input/Output values for Task #1 (Report Get All VLANS (custom_Get ALL VLANs Report)):

    Feb 24, 2016 21:47:49 UTC [Template Input:email = ${SUBMITTER_EMAIL}]

    Feb 24, 2016 21:47:49 UTC [Resolved Template Input: email = ogelbric@cisco.com]

    Feb 24, 2016 21:47:49 UTC [Local Input: email = ogelbric@cisco.com]

    Feb 24, 2016 21:47:49 UTC Completed workflow item number 1, with status Completed

    Feb 24, 2016 21:47:54 UTC Executing workflow item number 3

    Feb 24, 2016 21:47:54 UTC Completed workflow item number 2, with status Completed

     

     

    The Custom Task Code:

     

    importPackage(java.util);

    importPackage(java.lang);

    importPackage(java.io);

    importPackage(com.cloupia.model.cEvent.notify);

    importPackage(com.cloupia.model.cIM);

    importPackage(com.cloupia.lib.util.mail);

    importPackage(com.cloupia.fw.objstore);

    importPackage(com.cloupia.lib.util.managedreports);

     

     

     

    var toEmail = input.email;

     

     

     

     

    function getMailSettings()

    {

          return ObjStoreHelper.getStore((new MailSettings()).getClass()).getSingleton();

    }

     

     

    function getReport(reportContext, reportName)

    {

         var report = null;

          try

          {

                 report = ctxt.getAPI().getConfigTableReport(reportContext, reportName);

          } catch(e)

          {

          }

     

          if (report == null)

          {

                 return ctxt.getAPI().getTabularReport(reportName, reportContext);

          } else

         {

               var source = report.getSourceReport();

               return ctxt.getAPI().getTabularReport(source, reportContext);

         }

    }

     

    function getReportView(reportContext, reportName)

    {

          var report = getReport(reportContext, reportName);

         if (report == null)

         {

               logger.addError("No such report exists for the specified context "+reportName);

               return null;

         }

         return new TableView(report);

    }

     

     

     

     

     

    var buffer = new StringWriter();

    var printer = new PrintWriter(buffer);

    var formatter = new com.cloupia.lib.util.managedreports.Formatter(new File("."), printer);

     

     

     

    //Get all the Data Centers PODS = UcsController.datacenter.table_config

    var reportName1  = "UcsController.datacenter.table_config";

    var repContext1 = util.createContext("global_admin", null, "Pods");

    var PODreport = getReportView(repContext1, reportName1);

     

     

    for (var i=0; i<PODreport.rowCount(); i++)

    {

      var pod = PODreport.getColumnValue(i, "Name");

      logger.addInfo("POD Name = "+pod);

      logger.addInfo("-------------------------------------------");

      logger.addInfo("Generating pod vlan report");

     

     

      var reportName2  = "NetworkController.report.config.vlan.dc";

      var repContext2 = util.createContext("datacenter", null, pod);

      var report2 = getReportView(repContext2, reportName2);

      var numRowsFound2 = report2.rowCount();

      logger.addInfo("Number of rows found  = "+numRowsFound2);

      if (numRowsFound2 > 0 )

      {

      logger.addInfo("Greater then Zero...............: ");

      logger.addInfo("Number of Rows found...............: " + numRowsFound2);

      //add report to other reports

      formatter.printTable(report2);

      }

    }

    logger.addInfo("-------------------------------------------");

     

     

    //

    //Get all the UCSM Accounts = AccountsFeature.infra.account.table_config

    //

    var reportName3  = "AccountsFeature.infra.account.table_config";

    var repContext3 = util.createContext("global_admin", null, "Physical Accounts");

    var UCSMreport = getReportView(repContext3, reportName3);

    //

    // looking only for UCSM accounts in the physical account table

    //

    UCSMreport = UCSMreport.filterRowsByColumn("Account Type", "UCSM", false);

     

     

    for (var i=0; i<UCSMreport.rowCount(); i++)

    {

      var ucsm = UCSMreport.getColumnValue(i, "Account Name");

      logger.addInfo("UCSM Name = "+ucsm);

      logger.addInfo("-------------------------------------------");

      logger.addInfo("Generating UCSM vlan report");

     

     

      var reportName4 = "INFRA_COMPUTING_CONFIG_VLAN";

      var repContext4 = util.createContext("ucsm", null, ucsm);

      var report4 = getReportView(repContext4, reportName4);

     

     

      var numRowsFound4 = report4.rowCount();

      logger.addInfo("Number of rows found  = "+numRowsFound4);

      if (numRowsFound4 > 0 )

      {

      logger.addInfo("Greater then Zero...............: ");

      logger.addInfo("Number of Rows found...............: " + numRowsFound4);

      //add report to other reports

      formatter.printTable(report4);

      }

     

    }

     

     

     

     

     

     

     

     

    //formatter.printTable(report);

     

    printer.close();

     

     

    var message = new EmailMessageRequest();

    message.setToAddr(toEmail);

    message.setSubject("Report All VLANS");

    message.setFromAddress("no-reply@cisco.com");

     

     

     

    var body = "<head><style type='text/css'>";

     

     

    // Specify CSS for the report

    body = body + "table { font-family: Verdana, Geneva, sans-serif; font-size: 12px; border: thin solid #039; border-spacing: 0; background: #ffffff; } ";

     

     

    body = body + " th { background-color: #6699FF; color: white; font-family: Verdana, Geneva, sans-serif; font-size: 10px; font-weight: bold; border-color: #CCF; border-style: solid; border-width: 1px 1px 0 0; margin: 0; padding: 5px; } ";

     

    body = body + " td { font-family: Verdana, Geneva, sans-serif; font-size: 10px; border-color: #CCF; border-style: solid; border-width: 1px 1px 0 0; margin: 0; padding: 5px; background: #ffffff; }";

     

    body = body + "</style></head>";

    body = body+ "<body><h1>Network VLAN(s)</h1><br>" + buffer.toString();

          

    message.setMessageBody(body);

     

    logger.addInfo("Sending email");

     

     

    // Now, send the report via email. First parameter is just a label used in the

    // internal logs

    MailManager.sendEmail("VLAN(s) Report", getMailSettings(), message);

     

     

    Another example on how to combine reports

    ===================================

     

    importPackage(java.util);

    importPackage(java.lang);

    importPackage(java.io);

    importPackage(com.cloupia.model.cEvent.notify);

    importPackage(com.cloupia.model.cIM);

    importPackage(com.cloupia.lib.util.mail);

    importPackage(com.cloupia.fw.objstore);

    importPackage(com.cloupia.lib.util.managedreports);

     

    function getMailSettings()

    {

          return ObjStoreHelper.getStore((new MailSettings()).getClass()).getSingleton();

    }

     

     

    function getReport(reportContext, reportName)

    {

         var report = null;

          try

          {

                 report = ctxt.getAPI().getConfigTableReport(reportContext, reportName);

          } catch(e)

          {

          }

     

          if (report == null)

          {

                 return ctxt.getAPI().getTabularReport(reportName, reportContext);

          } else

         {

               var source = report.getSourceReport();

               return ctxt.getAPI().getTabularReport(source, reportContext);

         }

    }

     

    function getReportView(reportContext, reportName)

    {

          var report = getReport(reportContext, reportName);

         if (report == null)

         {

               logger.addError("No such report exists for the specified context "+reportName);

               return null;

         }

         return new TableView(report);

    }

     

     

     

     

     

     

     

     

     

    var buffer = new StringWriter();

    var printer = new PrintWriter(buffer);

    var formatter = new com.cloupia.lib.util.managedreports.Formatter(new File("."), printer);

    var reportName  = "CustomAction.wf.schedule.table.report";

    var repContext = util.createContext("global_admin", null, null);

    var report1 = getReportView(repContext, reportName);

    var numRowsFound1 = report1.rowCount();

    logger.addInfo("Number of Rows found.1..............: " + numRowsFound1);

    formatter.printTable(report1);

    printer.close();

     

     

    var a = buffer.toString();

    logger.addInfo("Length.1..............: " + a.length);

     

     

    var buffer = new StringWriter();

    var printer = new PrintWriter(buffer);

    var formatter = new com.cloupia.lib.util.managedreports.Formatter(new File("."), printer);

    var reportName  = "CustomAction.configTable";

    var repContext = util.createContext("global_admin", null, null);

    var report2 = getReportView(repContext, reportName);

    var numRowsFound2 = report2.rowCount();

    logger.addInfo("Number of Rows found.2..............: " + numRowsFound2);

    formatter.printTable(report2);

    printer.close();

     

     

    var b = buffer.toString();

    logger.addInfo("Length.2..............: " + b.length);

     

     

    var c = a + b;

    logger.addInfo("Length.3..............: " + c.length);

     

     

    output.ReturnStatus = 0;

    //ctxt.exit();