ESXi 4.1/5.0 Availability Report

ESXi 4.1/5.0 Availability Report

Attached is a small application that is designed to output a basic monthly availability report for all hosts over multiple vCenter instances.  In order to run the following tool you must have .NET 2.0 and PowerCLI 4.1/5.0 installed.

The tool generates a detailed report and sends a summary/copy of the report in an email to a given address.  The tool requires that the 'Host connection and power state' alarm was enabled during the given month (which is the default setting).  Here are the guidelines that it follows:

  • If the connection to a host was lost and the host wasn't in maintenance mode, it counts against the availability percentage
  • If the connection to a host was lost and the host was in maintenance mode, it doesn't count again it

In other words, it only counts unplanned hardware downtime against the percentage (for example, when a production host crashes with a PSOD). Here is a sample of the information contained in the detailed log file:

-------------------

xenserv3.domain.com - Uptime: 90 Days 10:37:51

-------------------

-----------------------

  -----

  Lost Connection Time: 0 seconds

  Availability: 100%

  -----

-------------------

xenserv4.domain.com - Uptime: 1 Days 20:33:17

-------------------

  Host Connection Lost

    Time: 12/21/2010 1:39:41 PM

    Alarm 'Host connection and power state' on xenserv4.domain.com changed from Green to Red

  Host Connection Re-established

    Time: 12/21/2010 2:53:12 PM

    Alarm 'Host connection and power state' on xenserv4.domain.com changed from Red to Green

  Enter Maintenance Mode

    Time: 12/21/2010 3:13:05 PM

    Host xenserv4.domain.com in LAB has entered maintenance mode

  Host Connection Lost

    Time: 12/21/2010 3:16:39 PM

    Alarm 'Host connection and power state' on xenserv4.domain.com changed from Green to Red

  Host Connection Re-established

    Time: 12/21/2010 3:28:17 PM

    Alarm 'Host connection and power state' on xenserv4.domain.com changed from Red to Green

  Exit Maintenance Mode

    Time: 12/21/2010 3:28:46 PM

    Host xenserv4.domain.com in LAB has exited maintenance mode

  MM: (12/21/2010 3:13:05 PM - 12/21/2010 3:28:46 PM)

-----------------------

  CON: (12/21/2010 1:39:41 PM - 12/21/2010 2:53:12 PM)

  CON: (12/21/2010 3:16:39 PM - 12/21/2010 3:28:17 PM) - in MM

  -----

  Lost Connection Time: 4411.61 seconds

  Availability: 99.8298%

  -----

Here is how the resulting email will appear:

(Attachment:  esxi-12-2010.txt)

ESXi Availability Report - December, 2010

--------------------------

  xenserv3.domain.com

          Avail. (Month): 100%

          Current Uptime: 90 Days 10h 37m 51s

       Lost Con. (Month): 0 Days 0h 0m 0s

--------------------------

  xenserv4.domain.com

          Avail. (Month): 99.8298%

          Current Uptime: 1 Days 20h 33m 17s

       Lost Con. (Month): 0 Days 1h 13m 31s

--------------------------

We have this scheduled to run on the first of every month at 12:15am with no parameters, which will provide us (via a distribution address defined in the .config file) with a report for the previous month.  Here are the parameters that need to be entered into the .config file:

    <!-- VCs - separate the FQDNs of all vCenter servers with commas -->

         <add key="VCs" value="vc1.domain.com,vc2.domain.com" />

   <!-- Usernames - separate the usernames of each vCenter with a comma -->

         <add key="Usernames" value="vc1username,vc2username" />

    <!-- Passwords - separate the passwords of each vCenter with a comma -->

         <add key="Passwords" value="vc1userpassword,vc2userpassword" />

    <!-- OutDir - supply the output directory of the report -->

         <add key="OutDir" value="C:\ESXAR\" />

   <!-- OutFilePrefix - supply the prefix that will be appended to the log file (*prefix*[timestamp].txt) -->

         <add key="OutFilePrefix" value="esxi-" />

   <!-- ToEmail - supply the email address that the report will be sent to -->

         <add key="ToEmail" value="emailrecipient@company.com" />

    <!-- FromEmail - supply the email address that the report will appear to come from -->

         <add key="FromEmail" value="emailsender@company.com" />

   <!-- SubjectEmail - supply the subject of the email -->

         <add key="SubjectEmail" value="ESXi Availability Report - " />

   <!-- SMTPServer - supply a valid SMTP server -->

         <add key="SMTPServer" value="smtp.company.com" />

   <!-- Verbose - (t/f) enter 't' to record *all* events to the log file -->

         <add key="Verbose" value="f" />

The source code has been provided in case anyone would like to expand it or see how it works for their own projects.  The above information can also be found in the included readme file.

Thanks, and please share any suggestions or modifications with the community!

Attachments
Comments

Hey there.

The program runs fine for a few minutes, but after 20 hosts, I get an error message: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter Name: Index "

Any ideas?

I'm running Windows 7 32bit. I'm trying to run this against one of my VC's with 80 or so hosts. Ideally, I'd like it to run against my entire environment (5 VC's, 475 hosts or so.)

Thank you!

Mike

Hi Mike,

I fixed a few bugs in the program awhile back but never went back to publish the latest version.  If you get a chance, please try downloading the newest archive (I replaced the .zip files in the original post) and giving it another shot.  If it doesn't seem to fix your problem let me know and we can take another look.

Thanks Mike,

Mike

HI Mike.

Still no luck. It shows the first host and then generates an Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

at ESXAR.ESXAR.GenerateReport()

at ESXAR.ESXAR.Main(String[] args)

I don't expect you to work on this until it works for me, I already appreciate your efforts on this. Looking at it from a slightly different angle, would you be able to just share with me the PowerShell code you are using? I've looked at your sourcecode and I'm just not a programmer Smiley Sad

If you could share the basic PowerCLI calls with me, I could do the output filtering etc myself, but I've been trying to come up with it myself and have not had a lot of success...

Mike

Mike,

Do you happen to have a version of this program that works with 5.0? Just curious. Thanks in advance.

Duane

Hi Duane, I haven't touched the code for this in quite some time.  However, I believe I did add support for 5.0 late last year.  I will attach the latest binary to this document - please let me know if it works.

EDIT:  The attached ESXAR_5.ZIP archive contains the lastet version.

Thanks,

Mike

Thanks for the quick reply Mike, but when I ran that executable I get the following error:

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
   at ESXAR.ESXAR.GenerateReport()
   at ESXAR.ESXAR.Main(String[] args)

Any ideas what could be causing this?

Thanks in advance, I appreciate all the help I can get.

Duane

Hard to tell just from that info.  Could you please extract the two files in ESXAR_debug into the same directory (overwrite) and let me know what error message the console generates on the next run?

Optional usage:  ESXAR.exe 'month-num' 'year-4-digit-num' ['to-email-address']

System.NullReferenceException: Object reference not set to an instance of an ob

ect.

   at ESXAR.ESXAR.GenerateReport() in C:\Users\mxc228.SW\Documents\Visual Studi

2010\Projects\ESXAR\ESXAR\Program.cs:line 138

Unhandled Exception: System.IO.IOException: The process cannot access the file

C:\ESXAR\esxi-10-2012.txt' because it is being used by another process.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access,

nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions

ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,

FileShare share)

   at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String

mediaType)

   at System.Net.Mail.AttachmentBase..ctor(String fileName)

   at System.Net.Mail.Attachment..ctor(String fileName)

   at ESXAR.ESXAR.SendReport(ArrayList objs) in C:\Users\mxc228.SW\Documents\Vi

ual Studio 2010\Projects\ESXAR\ESXAR\Program.cs:line 365

   at ESXAR.ESXAR.Main(String[] args) in C:\Users\mxc228.SW\Documents\Visual St

dio 2010\Projects\ESXAR\ESXAR\Program.cs:line 99

The funny thing is that we never created a file with that name, so I am not sure what's going on.

Mike,

Just wondering if you had any ideas on the logs I provided. Thanks in advance,

Duane

Hi,

Do you have the source code available to share?

-Ben

First 23 host, script runs fine I see log files. But 24th host script is still waiting to be completed. How can I troubleshooot this ?

Hello,

Do you have the source code available to share?

I wish to build a version that works with ESXi 5.1

Tony

The source code is attached.

Don't you see the attachments ?


Hello Luc,

The source code isn't attached.

There is executable only with file config.

there is only the pdb file (in ESXAR_debug.zip ), no source code .Smiley Sad

I have re-attached the source code for this project and removed the debug package.  It seems that I can only attach up to three files to the post.

Please feel free to hack away at it all you want (note that this was originally written in C# - a PowerShell version would be a nice evolution).

I would have developed compatibility for 5.1 myself, but I am no longer working in the virtualization space and have no need for it.

Good luck!

Thank you conramic ,

I will build a version that works with ESXi 5.1 and i will share it .

Smiley Happy

Any luck on the 5.1 version?

Version history
Revision #:
1 of 1
Last update:
‎12-29-2010 05:32 AM
Updated by: