-
-
Save imtrinity94/4b9f9392864f5d6a48e373d1173bfd2a to your computer and use it in GitHub Desktop.
vRO task to get CDP information of a vsphere host and send email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//input: userEmail [String] | |
//input: vmHost [VC:Host] | |
var csv = "" | |
// Setup Mail Client | |
var message = new EmailMessage(); | |
message.smtpHost = "smtp-host@org.co.uk"; | |
message.fromName = "vCenter Orchestrator"; | |
message.fromAddress = "noreply@org.co.uk"; | |
message.toAddress = userEmail; | |
if (vmHost != null) { | |
var pnicInfo = vmHost.configManager.networkSystem.queryNetworkHint(); | |
csv += "<!DOCTYPE html>\n"; | |
csv += "<html>\n"; | |
csv += "<head>\n"; | |
csv += "<title>" + vmHost.name + " CDP Report</title>\n"; | |
csv += "</head>\n"; | |
csv += "<body>\n"; | |
csv += "<table style='border:1px solid black;font-family: Arial;border-collapse: collapse;'>\n"; | |
csv += "<tr style='background: #005fbf;'>\n"; | |
csv += "<td colspan='4' style='font-weight: bold;color: #FFF;font-size: 14px;text-align: center;vertical-align: middle;'>" + vmHost.name + "</td>\n"; | |
csv += "</tr>\n"; | |
csv += "<tr style='background: #005fbf;'>\n"; | |
csv += "\ | |
<th style='font-weight: bold;font-size: 12px;color: #FFF;border: 1px solid black;padding: 3px;'>VMnic </th>\ | |
<th style='font-weight: bold;font-size: 12px;color: #FFF;border: 1px solid black;padding: 3px;'>Address </th>\ | |
<th style='font-weight: bold;font-size: 12px;color: #FFF;border: 1px solid black;padding: 3px;'>DevId </th>\ | |
<th style='font-weight: bold;font-size: 12px;color: #FFF;border: 1px solid black;padding: 3px;'>PortId </th>\ | |
\n"; | |
csv +="</tr>\n"; | |
for (var i in pnicInfo) { | |
if (pnicInfo[i].connectedSwitchPort) { | |
csv +="<tr style= 'border:1px solid black;'>\n"; | |
csv +="\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 2px;'> " + pnicInfo[i].device + " </td>\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 2px;'> " + pnicInfo[i].connectedSwitchPort.address + " </td>\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 2px;'> " + pnicInfo[i].connectedSwitchPort.devId + " </td>\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 2px;'> " + pnicInfo[i].connectedSwitchPort.portId + " </td>\ | |
\n"; | |
csv += "</tr>\n"; | |
} | |
else { | |
csv += "<tr style='border:1px solid black;background-color: #aad4ff'>\n"; | |
csv += "\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 3px;'>" + pnicInfo[i].device + "</td>\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 3px;'> No CDP Information </td>\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 3px;'></td>\ | |
<td style='font-size: 12px;border: 1px solid black;padding: 3px;'></td>\ | |
\n"; | |
csv += "</tr>\n"; | |
} | |
} | |
csv += "</table>\n"; | |
csv += "<br>\n"; | |
csv += "</body>\n"; | |
csv += "</html>\n"; | |
} | |
//Build attachment | |
var report = new MimeAttachment(); | |
report.name = "CDP-" + vmHost.name +".html"; | |
report.content = csv; | |
//finalize message and send | |
message.subject = vmHost.name + " CDP Report"; | |
message.addMimePart(csv,"text/html; charset=UTF-8"); | |
message.addMimePart(report,"text/html; charset=utf8"); | |
message.sendMessage(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment