05-29-2018 07:15 AM - edited 03-01-2019 06:48 AM
Task Name | APIC reports (new) |
Description | |
Prerequisites | Tested on UCSD 6.6 |
Category | Workflow |
Components | |
User Inputs |
Instructions for Regular Workflow Use:
A thank you goes out to Sriram Sundararajan for the crucial code.
The workflow:
User Input:
The 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);
importPackage(com.cloupia.lib.util);
importPackage(com.cloupia.service.cIM.inframgr);
importPackage(org.apache.commons.httpclient);
importPackage(org.apache.commons.httpclient.cookie);
importPackage(org.apache.commons.httpclient.methods);
importPackage(org.apache.commons.httpclient.auth);
importPackage(com.cloupia.model.cEvent.notify);
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 ucsmAccountName = ctxt.getInput("Account_Name");
var reportName = ctxt.getInput("REPORT_NAME");
// New
var reportContextType=ReportContext.getDynamicContextLevel("apic_controller");
var repContext = util.createContextByType(reportContextType, null, ucsmAccountName);
var report = getReportView(repContext, reportName);
logger.addInfo("Report Context Type is ::::::::::: " + reportContextType);
//var repContext = util.createContext("apic_controller", null, ucsmAccountName);
//var report = getReportView(repContext, reportName);
var numRowsFound = report.rowCount();
logger.addInfo("Number of Rows found: " + numRowsFound);
var toEmail = [ ctxt.getInput("Email Address") ];
var message = new EmailMessageRequest();
message.setToAddrs(toEmail);
message.setSubject("APIC Report : "+ ucsmAccountName);
message.setFromAddress("no-reply@cisco.com");
var buffer = new StringWriter();
var printer = new PrintWriter(buffer);
var formatter = new com.cloupia.lib.util.managedreports.Formatter(new File("."), printer);
formatter.printTable(report);
printer.close();
var body = "<head><style type='text/css'>";
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>APIC Report</h1><br>" + buffer.toString();
message.setMessageBody(body);
logger.addInfo("Sending email");
MailManager.sendEmail("APIC Report", getMailSettings(), message);
The e-mail:
Tenant Reports:
The 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);
importPackage(com.cloupia.lib.util);
importPackage(com.cloupia.service.cIM.inframgr);
importPackage(org.apache.commons.httpclient);
importPackage(org.apache.commons.httpclient.cookie);
importPackage(org.apache.commons.httpclient.methods);
importPackage(org.apache.commons.httpclient.auth);
importPackage(com.cloupia.model.cEvent.notify);
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 AccountName = ctxt.getInput("Account_Name");
var reportName = ctxt.getInput("REPORT_NAME");
var tenant = ctxt.getInput("custom_Chopper_7150.B");
// "accountName=='CoreyACI' && name=='orfFridayv1'"
var accountANDtenant = "accountName=='"+AccountName+"' && name=='"+tenant+"'";
logger.addInfo("accountANDtenant is ::::::::::: " + accountANDtenant);
// New
//var reportContextType=ReportContext.getDynamicContextLevel("apic_controller");
var reportContextType=ReportContext.getDynamicContextLevel("apic.tenant.report");
var repContext = util.createContextByType(reportContextType, null, accountANDtenant);
//var repContext = util.createContextByType(reportContextType, null, "accountName=='CoreyACI' && name=='orfFridayv1'");
//var repContext = util.createContextByType(reportContextType, null, ucsmAccountName);
var report = getReportView(repContext, reportName);
logger.addInfo("Report Context Type is ::::::::::: " + reportContextType);
//var repContext = util.createContext("apic_controller", null, ucsmAccountName);
var report = getReportView(repContext, reportName);
var numRowsFound = report.rowCount();
logger.addInfo("Number of Rows found: " + numRowsFound);
var toEmail = [ ctxt.getInput("Email Address") ];
var message = new EmailMessageRequest();
message.setToAddrs(toEmail);
message.setSubject("APIC Report : "+ AccountName);
message.setFromAddress("no-reply@cisco.com");
var buffer = new StringWriter();
var printer = new PrintWriter(buffer);
var formatter = new com.cloupia.lib.util.managedreports.Formatter(new File("."), printer);
formatter.printTable(report);
printer.close();
var body = "<head><style type='text/css'>";
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>APIC Report</h1><br>" + buffer.toString();
message.setMessageBody(body);
logger.addInfo("Sending email");
MailManager.sendEmail("APIC Report", getMailSettings(), message);
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: