Sunday, July 26, 2015

Cisco IMC (CIMC) reporting

If you have some cisco servers and wanted to generate a report every now and then i think this is going to help you a bit.
We want to generate an html report since i personally don't like excel since the final excel can be edited to modify the report that what it actually is but an html can't be.
Thanks to @thesurlyadm1n for the header.

#style, table and some background color
$a = "<style>"
$a = $a + "BODY{background-color:DarkGray;}"
$a = $a + "TABLE{border-width: 5px;border-style: solid;border-color: Purple;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:LightSeaGreen}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:WhiteSmoke}"
$a = $a + "</style>"

After this we want to decide where we want to store the file
#define file path
$path = "C:\"

Let us start by connecting to CIMC

#connect to cimc

for our case here I just want to use only few options

$network = Get-ImcMgmtIf
$nw = $network | Select-Object DdnsDomain, DnsPreferred, DnsAlternate, DnsUsingDhcp, Mac, NicMode, NicRedundancy  | ConvertTo-HTML -Fragment -PreContent '<p4> <font face="Algerian" size="9" color="navy"><p align="center"><u><b>CISCO IMC[CIMC] AUDIT REPORT</b></u></font> </p4><p>      </p> <p3> <font color="#1A1B1C"><b>NETWORK<b></font> </p3>' | Out-String

So from the above lines you can make out that i am running the Get-ImcMgmtIf command and selecting only the following values DdnsDomain, DnsPreferred, DnsAlternate, DnsUsingDhcp, Mac, NicMode, NicRedundancy and then converting that to an html fragmet. After doing that I am putting 2 lines before (that is why the precontent command) this fragmet of the html by using the precontent command. Then some cosmetic stuff like font, color etc., Heading (title of the report) one says "CISCO IMC[CIMC] AUDIT REPORT" and the sub heading says NETWORK

Here afterwards I only need one heading per fragment of html like the following.

$syslog = Get-ImcSyslogClient
$sys = $syslog | Select-Object AdminState, Hostname, Port | ConvertTo-HTML -Fragment -PreContent '<p>      </p></p> <p3> <font color="#1A1B1C"><b>SYSLOG<b></font> </p3>' | Out-String

Now don't we want to add all these fragments into an html file?
"Yes we do".
#merge all fragments into one html
ConvertTo-HTML -head $a -body "$nw $sys" | Out-File $path\cimc.html

Now you can also use a lot of other things too in this report. Just connect to cimc and run the following few commands and see which values of that command do you want in your report and then include them in your html fragment using the select-object command.
Get-ImcNtpServer, Get-ImcSnmp, Get-ImcSsh etc.,
Here is a sample screencapture.

You can find a sample CIMCaudit here on github.