vmwarevSphereHealthCheck.pl

Version 3
    SyntaxHighlighter.config.clipboardSwf = '/scripts/clipboard.swf';    function printSnippet()                     {                            eval("SyntaxHighlighter.vars.highlighters."$$('div.syntaxhighlighter')[0].id".toolbarCommands.printSource.execute()");                     }     function viewSource()                     {                            eval("SyntaxHighlighter.vars.highlighters."$$('div.syntaxhighlighter')[0].id".toolbarCommands.viewSource.execute()");                     }     function tweetSnippet()     {         var twtTitle  = document.title;         var twtUrl    = location.href;         var maxLength = 140 - (twtUrl.length + 1);         if (twtTitle.length > maxLength) {         twtTitle = twtTitle.substr(0, (maxLength - 3))+'...';         }         var twtLink = 'http://twitter.com/home?status='+encodeURIComponent(twtTitle + ' ' + twtUrl);         window.open(twtLink);     }#!/usr/bin/perl -w ##################################################################
    1. Author: William Lam
    2. 03/03/2010
    3. http://www.engineering.ucsb.edu/~duonglt/vmware/
    ################################################################## use strict; use warnings; use Math::BigInt; use Tie::File; use POSIX qw/mktime/; use Socket; use Getopt::Long; use POSIX qw(ceil floor); use VMware::VIRuntime; use VMware::VILib; use Net::SMTP;

     

                        1. DO NOT MODIFY PAST HERE ###########

     

    ################################
    1. VERSION
    ################################ my $version = "4.0.7"; $Util::script_version = $version;

     

    my @supportedVersion = qw(4.0.0);

     

    my %opts = (      cluster => {           type => "=s",              help => "The name of a vCenter cluster to query",              required => 0,         },         datacenter => {                 type => "=s",              help => "The name of a vCenter datacenter to query",              required => 0,         },      hostlist => {                 type => "=s",                 help => "File containting list of ESX/ESXi host(s) to query",                 required => 0,         },      vmlist => {                 type => "=s",                 help => "File containting list of VM(s) to query",                 required => 0,         },         type => {              type => "=s",              help => "Type: vcenter\n",              required => 1,         },         report => {              type => "=s",              help => "The name of the report to output. Please add \".html\" extension",              required => 0,           default => "vmware_health_report.html",         },         logcount => {              type => "=s",              help => "The number of lines to output from hostd logs",              required => 0,           default => 15,         },         vmperformance => {              type => "=s",              help => "Enable VM Performance gathering yes (Can potentially double your runtime)",              required => 0,              default => "no",         },         hostperformance => {              type => "=s",              help => "Enable Host Performance gathering yes (Can potentially increase your runtime)",              required => 0,              default => "no",         },         clusterperformance => {              type => "=s",              help => "Enable Cluster Performance gathering yes (Can potentially increase your runtime)",              required => 0,              default => "no",         },         email => {              type => "=s",              help => "[yes|no]",              required => 0,              default => "no",         },      demo => {                 type => "=s",                 help => "[yes|no]",                 required => 0,                 default => "no",         },      conf => {                 type => "=s",                 help => "File containing Host and VM specific configurations to output",                 required => 0,         },      printerfriendly => {                 type => "=s",                 help => "Whether the html output will be printer friendly yes",                 required => 0,           default => "no",         }, );

     

    1. validate options, and connect to the server
    Opts::add_options(%opts);

     

    1. validate options, and connect to the server
    Opts::parse(); Opts::validate(); Util::connect();

     

    ###############
    1. GLOBAL VARS
    ###############

     

    my ($host_name,$hostlist,$vmlist,$service_content,$hostType,$apiType,$apiVersion,$report,$my_time,$start_time,$demo,$email,$printerfriendly,$logcount,$vmperformance,$hostperformance,$clusterperformance,$type,$clusterInput,$datacenterInput,$hostfileInput,$cluster_view,$cluster_views,$datacenter_views,$datacenter_view,$host_view,$conf); my (@perf_host_list,@vms_perf,@hosts_in_cluster,@portgroups_in_cluster,@hosts_seen,@datastores_seen,@hosts_in_portgroups,@dvs,@vmsnapshots,@vmdeltas) = (); my (%hostlists,%vmlists,%configurations,%vmmac_to_portgroup_mapping,%vswitch_portgroup_mappping,%lun_row_info,%luns,%datastore_row_info,%datastores,%portgroup_row_info,%seen_dvs) = (); my ($hardwareConfigurationString,$stateString,$hostString,$healthHardwareString,$healthSoftwareString,$nicString,$configString,$hbaString,$cdpString,$lunString,$datastoreString,$portgroupString,$multipathString,$dvsString,$logString,$taskString,$numaString,$hostPerfString,$vmString,$vmconfigString,$vmstatString,$vmftString,$vmtoolString,$vmstorageString,$vmnetworkString,$vmthinString,$vmPerfString,$vmsnapString,$vmcdString,$vmflpString,$vmrdmString,$vmdeltaString,$vmnpivString,$advString,$mgmtString,$vmrscString,$capString,$vmdeviceString) = ("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""); my (@cluster_jump_tags,@host_jump_tags,@vm_jump_tags) = ();

     

    ###############
    1. COLORS
    ############### my $green = "#00FF00"; my $red = "#FF0000"; my $orange = "#FF6600"; my $yellow = "#FFFF33";

     

    ############################
    1. PARSE COMMANDLINE OPTIONS
    #############################

     

    $report = Opts::get_option('report'); $demo = Opts::get_option('demo'); $email = Opts::get_option('email'); $logcount = Opts::get_option('logcount'); $vmperformance = Opts::get_option('vmperformance'); $hostperformance = Opts::get_option('hostperformance'); $clusterperformance = Opts::get_option('clusterperformance'); $type = Opts::get_option('type'); $clusterInput = Opts::get_option('cluster'); $datacenterInput = Opts::get_option('datacenter'); $conf = Opts::get_option('conf'); $hostlist = Opts::get_option('hostlist'); $vmlist = Opts::get_option('vmlist'); $printerfriendly = Opts::get_option('printerfriendly');

     

    ##########################
    1. DEFAULT CONFIGUFRATION
    ########################## my $EMAIL_HOST = 'emailserver'; my $EMAIL_DOMAIN = 'localhost.localdomain'; my @EMAIL_TO = 'william@primp-industries.com.com,tuan@primp-industries.com'; my $EMAIL_FROM = 'vMA@primp-industries.com.com'; my $YELLOW_WARN = 30; my $ORANGE_WARN = 15; my $RED_WARN = 10; my $SNAPSHOT_YELLOW_WARN = 15; my $SNAPSHOT_ORANGE_WARN = 30; my $SNAPSHOT_RED_WARN = 60; my $SYSTEM_LICENSE="yes"; my $SYSTEM_FEATURE="yes"; my $SYSTEM_PERMISSION="yes"; my $SYSTEM_SESSION="yes"; my $SYSTEM_HOST_PROFILE="yes"; my $SYSTEM_PLUGIN="yes"; my $CLUSTER_SUMMARY="yes"; my $CLUSTER_PERFORMANCE="no"; my $CLUSTER_HA="yes"; my $CLUSTER_DRS="yes"; my $CLUSTER_DPM="yes"; my $CLUSTER_AFFINITY="yes"; my $CLUSTER_RP="yes"; my $CLUSTER_VAPP="yes"; my $HOST_HARDWARE_CONFIGURATION="yes"; my $HOST_MGMT="yes"; my $HOST_STATE="yes"; my $HOST_HEALTH="yes"; my $HOST_PERFORMANCE="no"; my $HOST_NIC="yes"; my $HOST_HBA="yes"; my $HOST_CAPABILITY="yes"; my $HOST_CONFIGURATION="yes"; my $HOST_VMOTION="yes"; my $HOST_GATEWAY="yes"; my $HOST_ISCSI="yes"; my $HOST_IPV6="yes"; my $HOST_FT="yes"; my $HOST_SSL="yes"; my $HOST_DNS="yes"; my $HOST_UPTIME="yes"; my $HOST_DIAGONISTIC="yes"; my $HOST_SERVICE="yes"; my $HOST_NTP="yes"; my $HOST_VSWIF="yes"; my $HOST_VMKERNEL="yes"; my $HOST_VSWITCH="yes"; my $HOST_SNMP="yes"; my $HOST_FIREWALL="yes"; my $HOST_POWER="yes"; my $HOST_ADVOPT="yes"; my $HOST_NUMA="yes"; my $HOST_CDP="yes"; my $HOST_DVS="yes"; my $HOST_LUN="yes"; my $HOST_DATASTORE="yes"; my $HOST_MULTIPATH="yes"; my $HOST_PORTGROUP="yes"; my $HOST_LOG="yes"; my $HOST_TASK="yes"; my $VM_CONFIG="yes"; my $VM_STATS="yes"; my $VM_RESOURCE_ALLOCATION="yes"; my $VM_PERFORMANCE="no"; my $VM_FT="yes"; my $VM_THIN="yes"; my $VM_DEVICE="yes"; my $VM_STORAGE="yes"; my $VM_NETWORK="yes"; my $VM_SNAPSHOT="yes"; my $VM_DELTA="no"; my $VM_CDROM="yes"; my $VM_FLOPPY="yes"; my $VM_RDM="yes"; my $VM_NPIV="yes"; my $VM_TOOL="yes";

     

    ############################
    1. START OF SCRIPT
    ############################

     

    ($service_content,$hostType,$apiType,$apiVersion) = &getServiceInfo();

     

    &validateSystem($apiVersion); &processOptions($type,$apiType,$conf); &processAdditionalConf(); &startReport(); &startBody($apiType); &getSystemSummary($service_content,$hostType,$apiType,$apiVersion); &getCluster($type,$apiType,$apiVersion); &getHost($type,$apiType,$apiVersion,$service_content); &getVM($type,$apiType,$apiVersion,$service_content); &endBody(); &endReport(); &emailReport();

     

    ############################
    1. END OF SCRIPT
    ############################

     

    Util::disconnect();

     

    #####################
    1. HELPER FUNCTIONS
    #####################

     

    sub emailReport {      if($email eq "yes") {           my $smtp = Net::SMTP->new($EMAIL_HOST ,Hello => $EMAIL_DOMAIN,Timeout => 30,);                      unless($smtp) {                      die "Error: Unable to setup connection with email server: \"" . $EMAIL_HOST . "\"!\n";              }

     

              open(DATA, $report) || die("Could not open the file");           my @report = datasend("$boundary\n");              $smtp->dataend();              $smtp->quit;      } }

     

    sub getServiceInfo {      my $sc = Vim::get_service_content();      
    1. service content
         
    1. esx,embeddedEsx,gsx,vpx
         
    1. HostAgent,VirtualCenter
         
    1. 4.0.0
         return ($sc,$sc->about->productLineId,$sc->about->apiType,$sc->about->version); }

     

    sub getSystemSummary {      my ($sc,$htype,$atype,$aversion) = @_;

     

         my $summary_start = "
    \n";

     

         ###########################      
    1. SYSTEM BUILD INFO
         ###########################

     

         if($atype eq 'VirtualCenter') {           $summary_start .= "h2. VMware vCenter System Summary "      } else {           if($htype eq 'esx') {                $summary_start .= "h2. VMware ESX System Summary "           }elsif($htype eq 'embeddedEsx') {                $summary_start .= "h2. VMware ESXi System Summary "           }      }     

     

         $summary_start .= "\n\n";
    $summary_start .= "\n";
    $summary_start .= "\n";
    $summary_start .= "
    FULL NAMEVERSIONBUILD
    ".$sc->about->fullName."".$sc->about->version."".$sc->about->build."
    \n";

     

         ###########################      
    1. LICENSE
         ###########################      my ($features,$feature_string,$feature_info_string) = ("","","");

     

         if($SYSTEM_LICENSE eq "yes") {           my $licenseMgr = Vim::get_view (mo_ref => $sc->licenseManager);     

     

              $summary_start .= "h3. Licenses: \n";           $summary_start .= "\n";
    $summary_start .= "\n";

    my $licenses = $licenseMgr->licenses;
    foreach(@$licenses) {
    if($demo eq "no") {
    $summary_start .= "\n";
    my $licenseProperties = $_->properties;
    if($licenseProperties) {
    $feature_info_string .= "\n";
    $feature_info_string .= "\n";
    }
    foreach(@$licenseProperties) {
    if($_->key ne 'feature') {
    if($_->key eq 'expirationHours' ) { $feature_info_string .= ""; }
    if($_->key eq 'expirationMinutes' ) { $feature_info_string .= ""; }
    if($_->key eq 'expirationDate' ) { $feature_info_string .= "\n"; }
    } else {
    my $feature = $_->value;
    $features .= "\n";
    }
    }
    } else {
    $summary_start .= "\n";
    }
    $feature_string .= $feature_info_string . $features;
    ($features,$feature_info_string) = ("","");
    }
    $summary_start .= "
    NAMEEDITIONLICENSECOST UNITTOTALCONSUMEDAVAILABLE
    ".$_->name."".$_->editionKey."".$_->licenseKey."".$_->costUnit."".$_->total."".$_->used."".($_->total - $_->used)."
    EDITION w/FEATURESEXPIRATION (HOURS)EXPIRATION (MINS)EXPIRATION DATE
    ".$_->editionKey."".$_->value."".$_->value."".$_->value."
    ".$feature->value."
    DEMO_MODEDEMO_MODEDEMO_MODEDEMO_MODEDEMO_MODEDEMO_MODEDEMO_MODE
    \n";      }

     

         ###########################      
    1. FEATURES
         ###########################      if($SYSTEM_FEATURE eq "yes" && $SYSTEM_LICENSE eq "yes") {           $summary_start .= "h3. Features: \n";           $summary_start .= "\n";

    if($demo eq "no") {
    $summary_start .= $feature_string;
    } else {
    $summary_start .= "\n";
    }
    $summary_start .= "
    DEMO_MODE
    \n";      }

     

         ###########################      
    1. PERMISSIONS
         ###########################      if($SYSTEM_PERMISSION eq "yes") {                $summary_start .= "h3. Permissions: \n";           $summary_start .= "\n";
    $summary_start .= "\n";

    my $authMgr = Vim::get_view (mo_ref => $sc->authorizationManager);
    my $roleLists = $authMgr->roleList;
    my %rolemapping;
    foreach(@$roleLists) {
    $rolemapping{$_->roleId} = $_->name;
    }

    if($demo eq "no") {
    eval {
    my $permissions = $authMgr->RetrieveAllPermissions();
    foreach(@$permissions) {
    my $ent = Vim::get_view(mo_ref => $_->entity, properties => );
    $summary_start .= "\n";
    }
    };
    if($@) { print "ERROR: Unable to query for permissions: " . $@ . "\n"; }
    } else {
    $summary_start .= "\n";
    }
    $summary_start .= "
    USER/GROUPROLEDEFINED INPROPAGATEIS GROUP
    " . $_->principal . "" . $rolemapping{$_->roleId} . "" . $ent->{'name'} . "" . (($_->propagate) ? "YES" : "NO") . "" . (($_->group) ? "YES" : "NO") . "
    DEMO_MODEDEMO_MODEDEMO_MODEDEMO_MODEDEMO_MODE
    \n";      }

     

         ###########################      
    1. SESSIONS
         ###########################      if($SYSTEM_SESSION eq "yes") {           $summary_start .= "h3. Active Session(s): \n";           $summary_start .= "\n";
    $summary_start .= "\n";

    if($demo eq "no") {
    my $sessionMgr = Vim::get_view (mo_ref => $sc->sessionManager);
    my $sess_list = $sessionMgr->sessionList;
    foreach(sort {$a->userName cmp $b->userName} @$sess_list) {
    $summary_start .= "\n";
    }
    } else {
    $summary_start .= "\n";
    }
    $summary_start .= "
    USERNAMEFULL NAMELOGON TIMELAST ACTIVE
    ".$_->userName."".$_->fullName."".$_->loginTime."".$_->lastActiveTime."
    DEMO_MODEDEMO_MODEDEMO_MODEDEMO_MODE
    \n";      }

     

         ###########################      
    1. HOST PROFILES
         ###########################      if($SYSTEM_HOST_PROFILE eq "yes") {           my $hostProfileMgr;           eval {                $hostProfileMgr = Vim::get_view (mo_ref => $sc->hostProfileManager);           };           if(!$@) {                my $profiles = Vim::get_views (mo_ref_array => $hostProfileMgr->profile);                my $hasProfile = 0;                my $profile_string = "";                foreach(sort {$a->name cmp $b->name} @$profiles) {                     $hasProfile = 1;                     my $profileDescription = "N/A";                     if($_->config->annotation) { $profileDescription = $_->config->annotation; }                     $profile_string .= "\n";
    }
    if($hasProfile eq 1) {
    $summary_start .= "h3. Host Profile(s):
    \n";
    $summary_start .= "\n";
    $summary_start .= "\n";
    $summary_start .= $profile_string;
    }
    }
    $summary_start .= "
    ".$_->name."".$profileDescription."".$_->createdTime."".$_->modifiedTime."".(($_->config->enabled) ? "YES" : "NO")."".$_->complianceStatus."
    PROFILE NAMEDESCRIPTIONCREATION TIMELAST MODIFIEDENABLEDCOMPLIANCE STATUS
    \n";      }      ###########################      
    1. PLUGIN
         ###########################      if($SYSTEM_PLUGIN eq "yes") {           my $extMgr;           eval {                $extMgr = Vim::get_view (mo_ref => $sc->extensionManager);           };           if(!$@) {                my $extList = $extMgr->extensionList;                my $ext_string = "";                                foreach(sort {$a->description->label cmp $b->description->label} @$extList) {                     $ext_string .= "";
    $ext_string .= "";
    $ext_string .= "";
    $ext_string .= "";
    $ext_string .= "\n";
    }
    $summary_start .= "h3. Plugin(s):
    \n";
    $summary_start .= "\n";
    $summary_start .= "\n";
    $summary_start .= $ext_string;
    $summary_start .= "
    ".$_->description->label."".($_->version ? $_->version : "N/A")."".($_->company ? $_->company : "N/A")."
    PLUGIN NAMEVERSIONCOMPANY
    \n";
    }
    }

    $summary_start .= "\n";
    print REPORT_OUTPUT $summary_start;
    }

    sub getCluster {
    my ($type,$atype,$aversion) = @_;

    my $cluster_count = 0;

    if($type eq 'cluster') {
    print REPORT_OUTPUT "
    ";
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    $cluster_count++;
    &printClusterSummary($cluster_view,$cluster_count);
    print REPORT_OUTPUT "
    \n";
    }elsif($type eq 'datacenter') {
    $cluster_views = Vim::find_entity_views(view_type => 'ClusterComputeResource',begin_entity => $datacenter_view);
    if($cluster_views) {
    print REPORT_OUTPUT "
    ";
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    foreach(sort {$a->name cmp $b->name} @$cluster_views) {
    $cluster_count++;
    &printClusterSummary($_,$cluster_count);
    }
    print REPORT_OUTPUT "
    \n";
    }
    }elsif($type eq 'vcenter') {
    if($cluster_views) {
    print REPORT_OUTPUT "
    ";
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    foreach(sort {$a->name cmp $b->name} @$cluster_views) {
    $cluster_count++;
    &printClusterSummary($_,$cluster_count);
    }
    }
    print REPORT_OUTPUT "
    \n";
    }
    }

    sub getHost {
    my ($type,$atype,$aversion,$sc) = @_;

    print REPORT_OUTPUT "
    \n";

    my $cluster_count = 0;

    if($type eq 'host') {
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    &printHostSummary($host_view,undef,$cluster_count,$type,$atype,$aversion,$sc);
    }elsif($type eq 'datacenter') {
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    foreach my $cluster(sort {$a->name cmp $b->name} @$cluster_views) {
    $cluster_count++;
    my $clusterTag = "host-".$cluster->name."-$cluster_count";
    my $clusterShortTag = $cluster->name;
    push @host_jump_tags,"   Cluster: $clusterShortTag
    \n";
    print REPORT_OUTPUT "
    \n";
    print REPORT_OUTPUT "h2. Cluster: $clusterShortTag
    \n";
    my $hosts = Vim::get_views (mo_ref_array => $cluster->host);
    &printHostSummary($hosts,$cluster->name,$cluster_count,$type,$atype,$aversion,$sc);
    }
    }elsif($type eq 'cluster') {
    $cluster_count++;
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    my $clusterTag = "host-".$cluster_view->name."-$cluster_count";
    my $clusterShortTag = $cluster_view->name;
    push @host_jump_tags,"   Cluster: $clusterShortTag
    \n";
    print REPORT_OUTPUT "
    \n";
    print REPORT_OUTPUT "h2. Cluster: $clusterShortTag
    \n";
    my $hosts = Vim::get_views (mo_ref_array => $cluster_view->host);
    &printHostSummary($hosts,$cluster_view->name,$cluster_count,$type,$atype,$aversion,$sc);
    }elsif($type eq 'vcenter') {
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    foreach my $cluster(sort {$a->name cmp $b->name} @$cluster_views) {
    $cluster_count++;
    my $clusterTag = "host-".$cluster->name."-$cluster_count";
    my $clusterShortTag = $cluster->name;
    push @host_jump_tags,"   Cluster: $clusterShortTag
    \n";
    print REPORT_OUTPUT "
    \n";
    print REPORT_OUTPUT "h2. Cluster: $clusterShortTag
    \n";

    my $hosts = Vim::get_views (mo_ref_array => $cluster->host);
    &printHostSummary($hosts,$cluster->name,$cluster_count,$type,$atype,$aversion,$sc);
    }
    }
    print REPORT_OUTPUT "
    \n";
    }

    sub getVM {
    my ($type,$atype,$aversion,$sc) = @_;

    print REPORT_OUTPUT "
    \n";

    my $cluster_count = 0;

    if($type eq 'host') {
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    &printVMSummary($host_view,undef,$cluster_count,$type,$atype,$aversion,$sc);
    }elsif($type eq 'datacenter') {
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    foreach my $cluster(sort {$a->name cmp $b->name} @$cluster_views) {
    $cluster_count++;
    my $clusterTag = "vm-".$cluster->name."-$cluster_count";
    my $clusterShortTag = $cluster->name;
    push @vm_jump_tags,"   Cluster: $clusterShortTag
    \n";
    print REPORT_OUTPUT "
    \n";
    print REPORT_OUTPUT "h2. Cluster: $clusterShortTag
    \n";
    my $hosts = Vim::get_views (mo_ref_array => $cluster->host);
    &printVMSummary($hosts,$cluster->name,$cluster_count,$type,$atype,$aversion,$sc);
    }
    }elsif($type eq 'cluster') {
    $cluster_count++;
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    my $clusterTag = "vm-".$cluster_view->name."-$cluster_count";
    my $clusterShortTag = $cluster_view->name;
    push @vm_jump_tags,"   Cluster: $clusterShortTag
    \n";
    print REPORT_OUTPUT "
    \n";
    print REPORT_OUTPUT "h2. Cluster: $clusterShortTag
    \n";
    my $hosts = Vim::get_views (mo_ref_array => $cluster_view->host);
    &printVMSummary($hosts,$cluster_view->name,$cluster_count,$type,$atype,$aversion,$sc);
    }elsif($type eq 'vcenter') {
    #please do not touch this, else the jump tags will break
    print REPORT_OUTPUT "\n//\n";
    foreach my $cluster(sort {$a->name cmp $b->name} @$cluster_views) {
    $cluster_count++;
    my $clusterTag = "vm-".$cluster->name."-$cluster_count";
    my $clusterShortTag = $cluster->name;
    push @vm_jump_tags,"   Cluster: $clusterShortTag
    \n";
    print REPORT_OUTPUT "
    \n";
    print REPORT_OUTPUT "h2. Cluster: $clusterShortTag
    \n";
    my $hosts = Vim::get_views (mo_ref_array => $cluster->host);
    &printVMSummary($hosts,$cluster->name,$cluster_count,$type,$atype,$aversion,$sc);
    }
    }
    print REPORT_OUTPUT "
    \n";
    }

    sub printVMSummary {
    my ($local_hosts,$cluster_name,$cluster_count,$type,$atype,$aversion,$sc) = @_;

    if(@$local_hosts) {
    foreach my $local_host(sort {$a->summary->config->name cmp $b->summary->config->name} @$local_hosts) {
    if($demo eq "no") {
    $host_name = $local_host->name;
    }

    #skip if host is not accessible
    next if($local_host->runtime->connectionState->val ne "connected");

    #skip if VM is not in valid list
    if($hostlist) {
    next if(!$hostlists{$local_host->name});
    }

    my $vms = Vim::get_views(mo_ref_array => $local_host->vm);
    foreach my $vm (sort {$a->name cmp $b->name} @$vms) {
    #skip if vm is disconnected
    next if(!defined($vm->config));

    #skip if VM is not in valid list
    if($vmlist) {
    my $vmname = $vm->name;                          next if(!$vmlists{$vmname});                     }

     

                        ######################                     
    1. VM CONFIG
                        ######################                     if($VM_CONFIG eq "yes") {                          $vmconfigString .= "
    ";

     

                             
      1. ESX/ESXi host ##
                             $vmconfigString .= "
    ".$host_name."
    ";

     

                             
      1. DISPLAY NAME ##
                             $vmconfigString .= "
    ".$vm->name."
    ";

     

                             
      1. GUEST HOSTNAME ##
                             $vmconfigString .= "
    ".($vm->guest->hostName ? $vm->guest->hostName : "N/A")."
    ";

     

                             
      1. UUID ##
                             $vmconfigString .= "
    ".($vm->summary->config->uuid ? $vm->summary->config->uuid : "N/A")."
    ";

     

                             
      1. BOOT TIME ##
                             $vmconfigString .= "
    ".($vm->runtime->bootTime ? $vm->runtime->bootTime : "N/A")."
    ";

     

                             
      1. OS ##     
                             $vmconfigString .= "
    ".($vm->config->guestFullName ? $vm->config->guestFullName : "N/A")."
    ";                                               
      1. OVERALL STATUS ##
                             my $vm_health = $vm->summary->overallStatus->val;                          if ($vm_health eq 'green') { $vmconfigString .= ""; }     

     

                             
      1. CONNECTION STATE ##
                             $vmconfigString .= "
    ".$vm->runtime->connectionState->val."
    ";

     

                             
      1. POWER STATE ##
                                            $vmconfigString .= "
    ".$vm->runtime->powerState->val."
    ";

     

                             
      1. vCPU ##
                             $vmconfigString .= "
    ".($vm->summary->config->numCpu ? $vm->summary->config->numCpu : "N/A")."
    ";                                                   
      1. vMEM ##
                             $vmconfigString .= "
    ".($vm->summary->config->memorySizeMB ? &prettyPrintData($vm->summary->config->memorySizeMB,'M') : "N/A")."
    ";                                                    
      1. vDISK ##
                                            $vmconfigString .= "
    ".($vm->summary->config->numVirtualDisks ? $vm->summary->config->numVirtualDisks : "N/A")."
    ";

     

                             
      1. DISK CAPACITY ##
                             if($vm->summary->storage) {                               my ($commit,$uncommit) = (0,0);                               if(defined($vm->summary->storage->committed)) { $commit = $vm->summary->storage->committed; }                               if(defined($vm->summary->storage->uncommitted)) { $uncommit = $vm->summary->storage->uncommitted; }                               $vmconfigString .= "";
    } else {
    $vmconfigString .= "
    ".&prettyPrintData(($commit + $uncommit),'B')."N/A
    ";                          }

     

                             
      1. vNIC ##
                             $vmconfigString .= "";

    if(!$vm->config->
    ".($vm->summary->config->numEthernetCards ? $vm->summary->config->numEthernetCards : "N/A")."
    template) {                               
      1. CPU RESERV ##
                                  $vmconfigString .= "
    ".($vm->summary->config->cpuReservation ? &prettyPrintData($vm->summary->config->cpuReservation,'MHZ') : "N/A")."
    ";

     

                                  
      1. MEM RESERV ##
                                  $vmconfigString .= "";
    } else {
    $vmconfigString .= "";
    $vmconfigString .= "
    ".($vm->summary->config->memoryReservation ? &prettyPrintData($vm->summary->config->memoryReservation,'M') : "N/A")."N/AN/A
    ";                          }               

     

                             
      1. TEMPLATE ##
                             $vmconfigString .= "";

    $vmconfigString .= "
    ".($vm->config->template ? "YES" : "NO")."
    \n";                     }                     ######################                     
    1. STATISTICS
                        ######################                     if($VM_STATS eq "yes") {                          if(!$vm->config->template) {                               $vmstatString .= "
    ";

     

                                  
      1. ESX/ESXi host ##
                                                 $vmstatString .= "
    ".$host_name."
    ";

     

                                                
      1. DISPLAY NAME ##
                                                 $vmstatString .= "
    ".$vm->name."
    ";

     

                                  
      1. CPU USAGE ##
                                  $vmstatString .= "
    ".($vm->summary->quickStats->overallCpuUsage ? &prettyPrintData($vm->summary->quickStats->overallCpuUsage,'MHZ') : "N/A" )."
    ";

     

                                  
      1. MEM USAGE ##
                                  $vmstatString .= "
    ".($vm->summary->quickStats->guestMemoryUsage ? &prettyPrintData($vm->summary->quickStats->guestMemoryUsage,'M') : "N/A")."
    ";                                                              
      1. MAX CPU USAGE ##
                                  $vmstatString .= "
    ".($vm->runtime->maxCpuUsage ? &prettyPrintData($vm->runtime->maxCpuUsage,'MHZ') : "N/A")."
    ";

     

                                  
      1. MAX MEM USAGE ##
                                  $vmstatString .= "
    ".($vm->runtime->maxMemoryUsage ? &prettyPrintData($vm->runtime->maxMemoryUsage,'M') : "N/A")."
    ";

     

                                  
      1. ACTIVE MEM ##
                                  $vmstatString .= "
    ".($vm->summary->quickStats->guestMemoryUsage ? &prettyPrintData($vm->summary->quickStats->guestMemoryUsage,'M') : "N/A")."
    ";

     

                                  
      1. CONSUMED MEM ##
                                  $vmstatString .= "
    ".($vm->summary->quickStats->hostMemoryUsage ? &prettyPrintData($vm->summary->quickStats->hostMemoryUsage,'M') : "N/A")."
    ";

     

                                  
      1. MEM OVERHEAD ##
                                  $vmstatString .= "
    ".($vm->summary->quickStats->consumedOverheadMemory ? &prettyPrintData($vm->summary->quickStats->consumedOverheadMemory,'M') : "N/A")."
    ";                                                              
      1. MEM BALLON ##
                                  $vmstatString .= "";

    $vmstatString .= "
    ".($vm->summary->quickStats->balloonedMemory ? &prettyPrintData($vm->summary->quickStats->balloonedMemory,'M') : "N/A")."
    \n";                          }                     }                     ######################                     
    1. VM RESOURCE
                        ######################                     if($VM_RESOURCE_ALLOCATION eq "yes") {                          if(!$vm->config->template && $vm->resourceConfig) {                               $vmrscString .= "
    ";                                               
      1. ESX/ESXi host ##
                                  $vmrscString .= "
    ".$host_name."
    ";

     

                                  
      1. DISPLAY NAME ##
                                  $vmrscString .= "
    ".$vm->name."
    ";

     

                                  
      1. MODIFIED ##
                                  $vmrscString .= "
    my $cpuAllocation = $vm->resourceConfig->cpuAllocation;
    my $memAllocation = $vm->resourceConfig->
    ".($vm->resourceConfig->lastModified ? $vm->resourceConfig->lastModified : "N/A")."
    memoryAllocation;

     

                                                            #cpu                                                              
      1. RESERVATION ##
                                  $vmrscString .= "
    ".($cpuAllocation->reservation ? &prettyPrintData($cpuAllocation->reservation,'MHZ') : "N/A")."
    ";

     

                                  
      1. LIMIT ##
                                  $vmrscString .= "
    ".($cpuAllocation->reservation ? &prettyPrintData($cpuAllocation->limit,'MHZ') : "N/A")."
    ";

     

                                  
      1. SHARES ##

     

                                  
    1. SHARES VALUE
                                  $vmrscString .= "
    ".($cpuAllocation->shares->shares ? $cpuAllocation->shares->shares : "N/A")."
    ";

     

                                  
    1. SHARES LEVEL
                                  $vmrscString .= "
    ".($cpuAllocation->shares->level->val ? $cpuAllocation->shares->level->val : "N/A")."
    ";

     

                                  
      1. EXPAND RESERVATION ##
                                  $vmrscString .= "
    ".($cpuAllocation->expandableReservation ? "YES" : "NO")."
    ";

     

                                  
      1. OVERHEAD LIMIT ##
                                  $vmrscString .= "
    ".($cpuAllocation->overheadLimit ? &prettyPrintData($cpuAllocation->overheadLimit,'MHZ') : "N/A")."
    ";

     

                                  #mem

     

                                  
      1. RESERVATION ##
                                                    $vmrscString .= "
    ".($memAllocation->reservation ? &prettyPrintData($memAllocation->reservation,'M') : "N/A")."
    ";

     

                                                   
      1. LIMIT ##
                                                    $vmrscString .= "
    ".($memAllocation->reservation ? &prettyPrintData($memAllocation->limit,'M') : "N/A")."
    ";

     

                                                   
      1. SHARES ##

     

                                                   
    1. SHARES VALUE
                                                    $vmrscString .= "
    ".($memAllocation->shares->shares ? $memAllocation->shares->shares : "N/A")."
    ";

     

                                                   
    1. SHARES LEVEL
                                                    $vmrscString .= "
    ".($memAllocation->shares->level->val ? $memAllocation->shares->level->val : "N/A")."
    ";

     

                                                   
      1. EXPAND RESERVATION ##
                                                    $vmrscString .= "
    ".($memAllocation->expandableReservation ? "YES" : "NO")."
    ";

     

                                                   
      1. OVERHEAD LIMIT ##
                                                    $vmrscString .= "";

    $vmrscString .= "
    ".($memAllocation->overheadLimit ? &prettyPrintData($memAllocation->overheadLimit,'M') : "N/A")."
    \n";                          }                     }                     ######################                                
    1. VM PERFORMANCE
                                    ######################                     if($VM_PERFORMANCE eq "yes" || $vmperformance eq "yes") {                          if($vm->runtime->powerState->val eq 'poweredOn') {                                           my $vmperf = &getCpuAndMemPerf($vm);                                           $vmPerfString .= $vmperf;                          }                     }                     ######################                     
    1. FT
                        ######################                     if($VM_FT eq "yes") {                                         if(!$vm->config->template && defined($vm->summary->config->ftInfo)) {                                              $vmftString .= "
    ";

     

                                  
      1. ESX/ESXi host ##
                                                    $vmftString .= "
    ".$host_name."
    ";

     

                                                   
      1. DISPLAY NAME ##
                                                    $vmftString .= "
    ".$vm->name."
    ";

     

                                  
      1. FT STATE ##
                                  $vmftString .= "
    ".$vm->runtime->faultToleranceState->val."
    ";

     

                                  
      1. FT ROLE ##
                                  my $role = "";                               if($vm->summary->config->ftInfo->role eq 1) { $role = "PRIMARY"; } else { $role = "SECONDARY"; }                               $vmftString .= "
    ".$role."
    ";

     

                                  
      1. FT INSTANCE UUIDS ##
                                  my $ftuuids = $vm->summary->config->ftInfo->instanceUuids;                               my $instanceuuids = "";                               if($vm->summary->config->ftInfo->role eq 1) {                                    $instanceuuids = $ftuuids->[0];                               } else {                                    $instanceuuids = $ftuuids->[1];                               }                               $vmftString .= "
    ".$instanceuuids."
    ";     

     

                                  
      1. FT SECONDARY LATENCY ##
                                                 $vmftString .= "
    ".($vm->summary->quickStats->ftSecondaryLatency ? $vm->summary->quickStats->ftSecondaryLatency : "N/A")."
    ";

     

                                  
      1. FT BW ##
                                                 $vmftString .= "";
    $vmftString .= "
    ".($vm->summary->quickStats->ftLogBandwidth ? $vm->summary->quickStats->ftLogBandwidth : "N/A")."
    \n";                          }                     }                     ######################                     
    1. THIN
                        ######################                     if($VM_THIN eq "yes") {                                         if(!$vm->config->template) {                               my $devices = $vm->config->hardware->device;                               my ($thin_disk_string,$thin_size_string,$thin_label_string) = ("","","");                               my $hasThin = 0;                               foreach(@$devices) {                                    if($_->isa('VirtualDisk') && $_->backing->isa('VirtualDiskFlatVer2BackingInfo')) {                                         my $diskName = $_->backing->fileName;                                         my $label = ($_->deviceInfo->label ? $_->deviceInfo->label : "N/A");                                         if($_->backing->thinProvisioned) {                                              $hasThin = 1;                                              $thin_label_string .= $label."
    ";
    $thin_disk_string .= $diskName."
    ";
    $thin_size_string .= &prettyPrintData($_->capacityInKB,'K')."
    ";
    }
    }
    }
    if($hasThin eq 1) {
    $vmthinString .= "
    ";                                                         
      1. ESX/ESXi host ##
                                                         $vmthinString .= "
    ".$host_name."
    ";

     

                                       
      1. DISPLAY NAME ##
                                       $vmthinString .= "
    ".$vm->name."
    ";

     

                                       
      1. THIN LABEL ##
                                       $vmthinString .= "
    ".$thin_label_string."
    ";

     

                                       
      1. THIN DISKS ##
                                       $vmthinString .= "
    ".$thin_disk_string."
    ";

     

                                       
      1. THIN DISKS SIZE ##
                                       $vmthinString .= "";

    $vmthinString .= "\n";
    }
    }
    }

    if($VM_DEVICE eq "yes") {
    if(!$vm->config->template) {
    $vmdeviceString .= "
    ".$thin_size_string."
    ";

     

                                                   
      1. ESX/ESXi host ##
                                                    $vmdeviceString .= "
    ".$host_name."
    ";

     

                                                   
      1. DISPLAY NAME ##
                                                    $vmdeviceString .= "";

    my %deviceMapper = ();

    my $devices = $vm->config->hardware->device;
    #foreach(@$devices) {
    # $deviceMapper{$_->key} = $_->deviceInfo->label;
    #}

    my ($cdrom,$idecontroller,$pcicontroller,$ps2controller,$paracontroller,$buscontroller,$lsicontroller,$lsilogiccontroller,$siocontroller,$usbcontroller,$disk,$e1000ethernet,$pcnet32ethernet,$vmxnet2ethernet,$vmxnet3ethernet,$floppy,$keyboard,$videocard,$vmci,$vmi,$parallelport,$pcipassthrough,$pointingdevice,$scsipassthrough,$serialport,$ensoniqsoundcard,$blastersoundcard,$usb) = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);

    foreach my $device (@$devices) {
    if($device->isa('VirtualCdrom')) {
    $cdrom++;
    }elsif($device->isa('VirtualController')) {
    if($device->isa('VirtualIDEController')) {
    $idecontroller++;
    }elsif($device->isa('VirtualPCIController')) {
    $pcicontroller++;
    }elsif($device->isa('VirtualPS2Controller')) {
    $ps2controller++;
    }elsif($device->isa('VirtualSCSIController')) {
    if($device->isa('ParaVirtualSCSIController')) {
    $paracontroller++;
    }elsif($device->isa('VirtualBusLogicController')) {
    $buscontroller++;
    }elsif($device->isa('VirtualLsiLogicController')) {
    $lsicontroller++;
    }elsif($device->isa('VirtualLsiLogicSASController')) {
    $lsilogiccontroller++;
    }
    }elsif($device->isa('VirtualSIOController')) {
    $siocontroller++;
    }elsif($device->isa('VirtualUSBController')) {
    $usbcontroller++;
    }
    }elsif($device->isa('VirtualDisk')) {
    $disk++;
    }elsif($device->isa('VirtualEthernetCard')) {
    if($device->isa('VirtualE1000')) {
    $e1000ethernet++;
    }elsif($device->isa('VirtualPCNet32')) {
    $pcnet32ethernet++;
    }elsif($device->isa('VirtualVmxnet')) {
    if($device->isa('VirtualVmxnet2')) {
    $vmxnet2ethernet++;
    }elsif($device->isa('VirtualVmxnet3')) {
    $vmxnet3ethernet++;
    }
    }
    }elsif($device->isa('VirtualFloppy')) {
    $floppy++;
    }elsif($device->isa('VirtualKeyboard')) {
    $keyboard++;
    }elsif($device->isa('VirtualMachineVideoCard')) {
    $videocard++;
    }elsif($device->isa('VirtualMachineVMCIDevice')) {
    $vmci++;
    }elsif($device->isa('VirtualMachineVMIROM')) {
    $vmi++;
    }elsif($device->isa('VirtualParallelPort')) {
    $parallelport++;
    }elsif($device->isa('VirtualPCIPassthrough')) {
    $pcipassthrough++;
    }elsif($device->isa('VirtualPointingDevice')) {
    $pointingdevice++;
    }elsif($device->isa('VirtualSCSIPassthrough')) {
    $scsipassthrough++;
    }elsif($device->isa('VirtualSerialPort')) {
    $serialport++;
    }elsif($device->isa('VirtualSoundCard')) {
    if($device->isa('VirtualEnsoniq1371')) {
    $ensoniqsoundcard++;
    }elsif($device->isa('VirtualSoundBlaster16')) {
    $blastersoundcard++;
    }
    }elsif($device->
    ".$vm->name."
    isa('VirtualUSB')) {                                         $usb++;                                    }                               }                                                              
      1. OS ##
                                                 $vmdeviceString .= "
    ".($vm->config->guestFullName ? $vm->config->guestFullName : "N/A")."
    ";

     

                                  
      1. CDROM ##
                                  $vmdeviceString .= "
    ".$cdrom."
    ";

     

                                  
      1. CONTROLER ##
                                  my $controllerString = "";                               if($idecontroller != 0) {                                    $controllerString .= $idecontroller . " x IDE Controller
    ";
    }
    if($pcicontroller != 0) {
    $controllerString .= $pcicontroller . " x PCI Controller
    ";
    }
    if($ps2controller != 0) {
    $controllerString .= $ps2controller . " x PS2 Controller
    ";
    }
    if($paracontroller != 0) {
    $controllerString .= $paracontroller . " x PARA-VIRT Controller
    ";
    }
    if($buscontroller != 0) {
    $controllerString .= $buscontroller . " x BUS Controller
    ";
    }
    if($lsicontroller != 0) {
    $controllerString .= $lsicontroller . " x LSI LOGIC Controller
    ";
    }
    if($lsilogiccontroller != 0) {
    $controllerString .= $lsilogiccontroller . " x LSI LOGIC SAS Controller
    ";
    }
    if($siocontroller != 0) {
    $controllerString .= $siocontroller . " x SIO Controller
    ";
    }
    if($usbcontroller != 0) {
    $controllerString .= $usbcontroller . " x USB Controller
    ";
    }
    if($controllerString eq "") { $controllerString = "N/A"; }
    $vmdeviceString .= "
    ".$controllerString."
    ";

     

                                  
      1. DISK ##
                                  $vmdeviceString .= "
    ".$disk."
    ";                                                              
      1. ETHERNET CARD ##
                                  my $ethString = "";                               if($e1000ethernet != 0) {                                    $ethString .= $e1000ethernet . " x e1000";                              

     

                                  
      1. FLOPPY ##
                                  $vmdeviceString .= "
    ".$floppy."
    ";                              

     

                                  
      1. KEYBOARD ##
                                  $vmdeviceString .= "
    ".$keyboard."
    ";

     

                                  
      1. VIDEO CARD ##
                                  $vmdeviceString .= "
    ".$videocard."
    ";

     

                                  
      1. VMCI ##
                                  $vmdeviceString .= "
    ".$vmci."
    ";          

     

                                  
      1. VMIROM ##
                                  $vmdeviceString .= "
    ".$vmi."
    ";

     

                                  
      1. PARALLEL PORT ##
                                  $vmdeviceString .= "
    ".$parallelport."
    ";

     

                                  
      1. PCI PASS THROUGH ##
                                  $vmdeviceString .= "
    ".$pcipassthrough."
    ";

     

                                  
      1. POINTING DEVICE ##
                                  $vmdeviceString .= "
    ".$pointingdevice."
    ";

     

                                  
      1. SCSI PASS THROUGH ##
                                  $vmdeviceString .= "
    ".$scsipassthrough."
    ";                                                    
      1. SERIAL PORT ##
                                  $vmdeviceString .= "
    ".$serialport."
    ";

     

                                  
      1. SOUND CARD ##
                                  my $soundString = "";                               if($ensoniqsoundcard != 0) {                                    $soundString .= $ensoniqsoundcard . " x Ensoiq1373 Sound Card
    ";
    }
    if($blastersoundcard != 0) {
    $soundString .= $blastersoundcard . " x Soundblaster Sound Card
    ";
    }
    if($soundString eq "") { $soundString = "N/A"; }
    $vmdeviceString .= "
    ".$soundString."
    ";

     

                                  
      1. USB ##
                                  $vmdeviceString .= "";

    $vmdeviceString .= "
    ".$usb."
    \n";                          }                     }                     ######################                     
    1. VM STORAGE
                        ######################                     if($VM_STORAGE eq "yes") {                                         if(!$vm->config->template && $vm->guest->disk) {                                                 $vmstorageString .= "
    ";

     

                                                   
      1. ESX/ESXi host ##
                                                    $vmstorageString .= "
    ".$host_name."
    ";

     

                                                   
      1. DISPLAY NAME ##
                                                    $vmstorageString .= "";

    my $vdisks = $vm->guest->disk;
    my $disk_string = "";
    foreach my $disk (@$vdisks) {
    my $vm_disk_path = $disk->diskPath;
    my $vm_disk_free = prettyPrintData($disk->freeSpace,'B');
    my $vm_disk_cap = prettyPrintData($disk->capacity,'B');
    my $vm_perc_free = &restrict_num_decimal_digits((($disk->freeSpace / $disk->capacity) * 100),2);
    my $perc_string = getColor($vm_perc_free);
    $disk_string .= "";
    }
    $vmstorageString .= $disk_string;
    $vmstorageString .= "
    ".$vm->name."$perc_string
    $vm_disk_path$vm_disk_free$vm_disk_cap
    \n";                                         }                                 }                     ######################                                
    1. VM NETWORK
                                    ######################                     if($VM_NETWORK eq "yes" && $vm->guest->net) {                                         if(!$vm->config->template) {                                                 $vmnetworkString .= "
    ";

     

                                                   
      1. ESX/ESXi host ##
                                                    $vmnetworkString .= "
    ".$host_name."
    ";

     

                                                   
      1. DISPLAY NAME ##
                                                    $vmnetworkString .= "";

    my ($vm_ip_string,$vm_mac_string,$vm_pg_string,$vm_connect_string) = ("","","","");

    my $vnics = $vm->guest->
    ".$vm->name."
    net;                               foreach(@$vnics) {                                    
      1. IP ADDRESS ##
                                       if($_->ipAddress) {                                         my $ips = $_->ipAddress;                                         foreach(@$ips) {                                              if($demo eq "no") {                                                   $vm_ip_string .= $_."
    ";
    } else {
    $vm_ip_string .= "demo_mode
    ";
    }
    }
    } else {
    $vm_ip_string .= "N/A
    ";                                    }

     

                                       
      1. MAC ADDRESS ##
                                       if($_->macAddress) {                                         if($demo eq "no") {                                              $vm_mac_string .= $_->macAddress."
    ";
    } else {
    $vm_mac_string .= "demo_mode
    ";
    }
    } else {
    $vm_mac_string .= "N/A
    ";                                    }                                          
      1. PORTGROUP ##
                                       if($_->network) {                                         if($demo eq "no") {                                              $vm_pg_string .= $_->network."
    ";
    } else {
    $vm_pg_string .= "demo_mode
    ";
    }
    } else {
    $vm_pg_string .= "N/A
    ";                                    }

     

                                       
      1. CONNECTED ##
                                       $vm_connect_string .= ($_->connected ? "YES
    " : "NO
    ");
    }
    $vmnetworkString .= "";
    $vmnetworkString .= "
    ".$vm_ip_string."".$vm_mac_string."".$vm_pg_string."".$vm_connect_string."
    \n";                                         }                                 }                     ######################                     
    1. SNAPSHOT
                        ######################                     if($VM_SNAPSHOT eq "yes") {                                         if(!$vm->config->template) {                               if($vm->snapshot) {                                    &getSnapshotTree($host_name,$vm->name,$vm->snapshot->currentSnapshot,$vm->snapshot->rootSnapshotList);                                    foreach(@vmsnapshots) {                                         $vmsnapString .= "".$_."
    \n";                                    }                                    @vmsnapshots = ();                               }                                         }                                 }                     ######################                     
    1. CDROM
                        ######################                     if($VM_CDROM eq "yes") {                                         if(!$vm->config->template) {                               my $devices = $vm->config->hardware->device;                                                 my ($cd_string) = ("");                                                 my $hasCD = 0;                                                 foreach(@$devices) {                                                         if($_->isa('VirtualCdrom') && $_->connectable->connected) {                                         $hasCD = 1;                                         if($_->deviceInfo->summary) {                                              $cd_string .= $_->deviceInfo->summary."
    ";
    } else {
    $cd_string .= "N/A";
    }
    }
    }
    if($hasCD eq 1) {
    $vmcdString .= "
    ";

     

                                                           
      1. ESX/ESXi host ##
                                                            $vmcdString .= "
    ".$host_name."
    ";

     

                                                           
      1. DISPLAY NAME ##
                                                            $vmcdString .= "
    ".$vm->name."
    ";

     

                                       
      1. ISO ##
                                       $vmcdString .= "";

    $vmcdString .= "
    ".$cd_string."
    \n";                                                 }

     

                                            }                                 }                     ######################                     
    1. FLOPPY
                        ######################                     if($VM_FLOPPY eq "yes") {                                         if(!$vm->config->template) {                               my $devices = $vm->config->hardware->device;                                                 my ($flp_string) = ("");                                                 my $hasFLP = 0;                                                 foreach(@$devices) {                                                         if($_->isa('VirtualFloppy') && $_->connectable->connected) {                                                                 $hasFLP = 1;                                                                 if($_->deviceInfo->summary) {                                                                         $flp_string .= $_->deviceInfo->summary."
    ";
    } else {
    $flp_string .= "N/A";
    }
    }
    }
    if($hasFLP eq 1) {
    $vmflpString .= "
    ";

     

                                                           
      1. ESX/ESXi host ##
                                                            $vmflpString .= "
    ".$host_name."
    ";

     

                                                           
      1. DISPLAY NAME ##
                                                            $vmflpString .= "
    ".$vm->name."
    ";

     

                                                           
      1. FLP ##
                                                            $vmflpString .= "";

    $vmflpString .= "
    ".$flp_string."
    \n";                                                 }                                         }                                 }                     ######################                                
    1. TOOLS
                                    ######################                     if($VM_TOOL eq "yes") {                                         if(!$vm->config->template) {                               $vmtoolString .= "
    ";

     

                                  
      1. ESX/ESXi host ##
                                                    $vmtoolString .= "
    ".$host_name."
    ";

     

                                                   
      1. DISPLAY NAME ##
                                                    $vmtoolString .= "";

    if($vm->
    ".$vm->name."
    guest) {                                    
      1. TOOLS VERSION ##
                                                            $vmtoolString .= "
    ".($vm->guest->toolsVersion ? $vm->guest->toolsVersion : "N/A")."
    ";

     

                                       
      1. TOOLS RUNNING STATUS ##
                                       $vmtoolString .= "
    ".($vm->guest->toolsRunningStatus ? $vm->guest->toolsRunningStatus : "N/A")."
    ";                                                                       
      1. TOOLS VERSION STATUS ##
                                       $vmtoolString .= "";
    } else {
    $vmtoolString .= "";
    $vmtoolString .= "";
    $vmtoolString .= "";
    }
    if($vm->config->
    ".($vm->guest->toolsVersionStatus ? $vm->guest->toolsVersionStatus : "N/A")."N/AN/AN/A
    tools) {                                    
      1. TOOLS UPGRADE POLICY ##     
                                       $vmtoolString .= "
    ".($vm->config->tools->toolsUpgradePolicy ? $vm->config->tools->toolsUpgradePolicy : "N/A")."
    ";

     

                                       
      1. SYNC TIME ##
                                       $vmtoolString .= "";
    } else {
    $vmtoolString .= "";
    $vmtoolString .= "";
    }
    $vmtoolString .= "
    ".($vm->config->tools->syncTimeWithHost ? "YES" : "NO")."N/AN/A
    \n";                                         }                                 }                     ######################                     
    1. RDM
                        ######################                     if($VM_RDM eq "yes") {                                         if(!$vm->config->template) {                               my $devices = $vm->config->hardware->device;                                                 my ($rdm_string) = ("");                                                 my $hasRDM = 0;                                                 foreach(@$devices) {                                                         if($_->isa('VirtualDisk') && ($_->backing->isa('VirtualDiskRawDiskVer2BackingInfo') || $_->backing->isa('VirtualDiskRawDiskMappingVer1BackingInfo'))) {                                                                 $hasRDM = 1;                                         my $compat_mode = ($_->backing->compatibilityMode ? $_->backing->compatibilityMode : "N/A");                                         my $vmhba = ($_->backing->deviceName ? $_->backing->deviceName : "N/A");                                                           my $disk_mode = ($_->backing->diskMode ? $_->backing->diskMode : "N/A");                                                           my $lun_uuid = ($_->backing->lunUuid ? $_->backing->lunUuid : "N/A");                                                           my $vm_uuid = ($_->backing->uuid ? $_->backing->uuid : "N/A");                                                                 $rdm_string .= "";
    }
    }
    if($hasRDM eq 1) {
    $vmrdmString .= "
    ".$compat_mode."".$vmhba."".$disk_mode."".$lun_uuid."".$vm_uuid."
    ";

     

                                                           
      1. ESX/ESXi host ##
                                                            $vmrdmString .= "
    ".$host_name."
    ";

     

                                                           
      1. DISPLAY NAME ##
                                                            $vmrdmString .= "
    ".$vm->name."
    ";

     

                                                           
      1. RDM ##
                                                            $vmrdmString .= $rdm_string;

     

                                                            $vmrdmString .= "</tr>\n";                                                 }                                         }                                 }                     ######################                     
    1. NPIV
                        ######################                     if($VM_NPIV eq "yes") {                                         if(!$vm->config->template) {                               if($vm->config->npivNodeWorldWideName && $vm->config->npivPortWorldWideName) {                                                      $vmnpivString .= "
    ";                                                           
      1. ESX/ESXi host ##
                                                         $vmnpivString .= "
    ".$host_name."
    ";

     

                                                        
      1. DISPLAY NAME ##
                                                         $vmnpivString .= "";

    my $nwwns = $vm->config->npivNodeWorldWideName;
    my $pwwns = $vm->config->npivPortWorldWideName;
    my $type = ($vm->config->npivWorldWideNameType ? $vm->config->npivWorldWideNameType : "N/A");
    my $desirednwwn = ($vm->config->npivDesiredNodeWwns ? $vm->config->npivDesiredNodeWwns : "N/A");
    my $desiredpwwn = ($vm->config->npivDesiredPortWwns ? $vm->config->npivDesiredPortWwns : "N/A");
    my $npiv_string = "";

    $vmnpivString .= $npiv_string;
    $vmnpivString .= "\n";
    }
    }
    }


    if($VM_STATS eq "yesaaaaa") {
    if(!$vm->config->template) {
    $vmstatString .= "
    ".$vm->name."";
    foreach(@$nwwns) {
    my $nwwn = (Math::BigInt->new($_))->as_hex();
    $nwwn =~ s/^..//;
    $nwwn = join(':', unpack('A2' x 8, $nwwn));
    if($demo eq "no") {
    $npiv_string .= "$nwwn
    ";
    } else {
    $npiv_string .= "XX:XX:XX:XX:XX:XX:XX:XX
    ";
    }
    }
    $npiv_string .= "
    ";
    foreach(@$pwwns) {
    my $pwwn = (Math::BigInt->new($_))->as_hex();
    $pwwn =~ s/^..//;
    $pwwn = join(':', unpack('A2' x 8, $pwwn));
    if($demo eq "no") {
    $npiv_string .= "$pwwn
    ";
    } else {
    $npiv_string .= "XX:XX:XX:XX:XX:XX:XX:XX
    ";
    }
    }
    my $npivtype = "";
    if($type eq "vc") { $npivtype = "Virtual Center"; }
    elsif($type eq "external") { $npivtype = "External Source"; }
    elsif($type eq "host") { $npivtype = "ESX or ESXi"; }
    $npiv_string .= "
    ".$npivtype."".$desirednwwn."".$desiredpwwn."
    ";

     

                                  
      1. ESX/ESXi host ##
                                                    $vmstatString .= "
    ".$host_name."
    ";

     

                                                   
      1. DISPLAY NAME ##
                                                    $vmstatString .= "";


    $vmstatString .= "
    ".$vm->name."
    \n";                                         }                                 }                                
      1. STOP ###               
                   }           }

     

              ######################                
    1. DLETA
                    ######################                 if($VM_DELTA eq "yes") {                foreach(@vmdeltas) {                     $vmdeltaString .= "".$_."\n";
    }
    @vmdeltas = ();
    }
    &buildVMReport($cluster_name,$cluster_count,$type,$atype,$aversion);
    }
    }

    sub printHostSummary {
    my ($local_hosts,$cluster_name,$cluster_count,$type,$atype,$aversion,$sc) = @_;

    if(@$local_hosts) {
    foreach my $local_host(sort {$a->summary->config->name cmp $b->summary->config->name} @$local_hosts) {
    if($demo eq "no") {
    $host_name = $local_host->name;
    }

    #skip if host is not accessible
    next if($local_host->runtime->connectionState->val ne "connected");

    #skip if VM is not in valid list
    if($hostlist) {
    next if(!$hostlists{$local_host->
    name});                         }

     

                   #capture unique hosts for later use                push @hosts_seen,$host_name;

     

                   ######################                
    1. HARDWARE
                   ######################                if($HOST_HARDWARE_CONFIGURATION eq "yes") {                     $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";

    my $additional_vendor_info = "";
    if($local_host->summary->hardware->otherIdentifyingInfo) {
    my $add_info = $local_host->summary->hardware->otherIdentifyingInfo;
    foreach (@$add_info) {
    $additional_vendor_info .= $_->identifierType->key.": ".$_->identifierValue." ";
    }
    if($additional_vendor_info eq '') {
    $additional_vendor_info = "UNKNOWN";
    }
    }
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "";
    $hardwareConfigurationString .= "
    ".$host_name."".$local_host->summary->hardware->vendor."".$additional_vendor_info."".$local_host->summary->hardware->model."".$local_host->summary->hardware->cpuModel."".(($local_host->config->hyperThread->available) ? "YES" : "NO")."".prettyPrintData($local_host->summary->hardware->numCpuCores*$local_host->summary->hardware->cpuMhz,'MHZ')."".prettyPrintData($local_host->summary->quickStats->overallCpuUsage,'MHZ')."".$local_host->summary->hardware->numCpuPkgs."".($local_host->summary->hardware->numCpuCores/$local_host->summary->hardware->numCpuPkgs)."".$local_host->summary->hardware->numCpuThreads."".prettyPrintData($local_host->summary->hardware->memorySize,'B')."".prettyPrintData($local_host->summary->quickStats->overallMemoryUsage,'M')."".$local_host->summary->hardware->numNics."".$local_host->summary->hardware->numHBAs."
    \n";                }                ######################                
    1. MGMT
                   ######################                if($HOST_MGMT eq "yes") {                     $mgmtString .= "";

    $mgmtString .= "";

    my $mgmtIp = "N/A";
    if($local_host->summary->managementServerIp) {
    if($demo eq "no") {
    my ($ipaddress,$dnsname);
    eval {
    $ipaddress = inet_aton($local_host->summary->managementServerIp);
    $dnsname = gethostbyaddr($ipaddress, AF_INET);
    };
    if(!$@) {
    $mgmtIp = $local_host->summary->managementServerIp . " ( $dnsname )";
    } else {
    $mgmtIp = $local_host->summary->managementServerIp . " ( UNKNOWN )";
    }
    } else {
    $mgmtIp = "demo_mode";
    }
    }

    $mgmtString .= "";

    if($atype eq "VirtualCenter" ) {
    if($local_host->summary->config->product) {
    $mgmtString .= "";
    }
    }

    $mgmtString .= "";
    $mgmtString .= "";

    $mgmtString .= "
    ".$host_name."".$mgmtIp."".($local_host->config->adminDisabled ? "YES" : "NO")."".$local_host->summary->hardware->uuid."".($local_host->config->consoleReservation ? $local_host->config->consoleReservation : "N/A")."
    \n";                     }                ######################                
    1. STATE
                   ######################                     if($HOST_STATE eq "yes") {                     $stateString .= "";
    $stateString .= "";
    my $host_health .= $local_host->overallStatus->val;
    if ($host_health eq 'green') { $stateString .= ""; }
    elsif ($host_health eq 'red') { $stateString .= ""; }
    elsif ($host_health eq 'yellow') { $stateString .= ""; }
    else { $stateString .= ""; }
    $stateString .= "";
    if($local_host->runtime->bootTime) { $stateString .= ""; }
    else { $stateString .= ""; }
    $stateString .= "";
    $stateString .= "";
    $stateString .= "";
    $stateString .= "";
    $stateString .= "
    ".$host_name."HOST is OKHOST has a problemHOST might have a problemUNKNOWN".$local_host->runtime->powerState->val."".$local_host->runtime->bootTime."UNKNOWN".$local_host->runtime->connectionState->val."".(($local_host->summary->runtime->inMaintenanceMode) ? "YES" : "NO")."".(($local_host->summary->config->vmotionEnabled) ? "YES" : "NO")."".${$local_host->summary->config->product}{'fullName'}."
    \n";                }                ######################                
    1. HEALTH
                   ######################                if($HOST_HEALTH eq "yes") {                     if($local_host->runtime->healthSystemRuntime) {                          if($local_host->runtime->healthSystemRuntime->hardwareStatusInfo) {                               my $hardwareStatusInfo = $local_host->runtime->healthSystemRuntime->hardwareStatusInfo;                               my ($cpuInfo,$memInfo,$storageInfo);                               $healthHardwareString .= "\n";
    my ($sensor_health_color,$sensor_health) = ("","");;

    if($hardwareStatusInfo->cpuStatusInfo) {
    $cpuInfo = $hardwareStatusInfo->cpuStatusInfo;
    foreach(@$cpuInfo) {
    $sensor_health = $_->status->key;
    if ($sensor_health =~ m/green/i) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/red/i) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/yellow/i) { $sensor_health_color=""; }
    else { $sensor_health_color=""; }
    $healthHardwareString .= "".$sensor_health_color."\n";
    }
    }
    if($hardwareStatusInfo->memoryStatusInfo) {
    $memInfo = $hardwareStatusInfo->memoryStatusInfo;
    foreach(@$memInfo) {
    $sensor_health = $_->status->key;
    if ($sensor_health =~ m/green/i) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/red/i) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/yellow/i) { $sensor_health_color=""; }
    else { $sensor_health_color=""; }
    $healthHardwareString .= "".$sensor_health_color."\n";
    }
    }
    if($hardwareStatusInfo->storageStatusInfo) {
    $storageInfo = $hardwareStatusInfo->storageStatusInfo;
    foreach(@$storageInfo) {
    $sensor_health = $_->status->key;
    if ($sensor_health =~ m/green/i) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/red/i) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/yellow/i) { $sensor_health_color=""; }
    else { $sensor_health_color=""; }
    $healthHardwareString .= "".$sensor_health_color."\n";
    }
    }
    }
    if($local_host->runtime->healthSystemRuntime->systemHealthInfo) {
    my $sensors = $local_host->runtime->healthSystemRuntime->systemHealthInfo->numericSensorInfo;
    $healthSoftwareString .= "\n";
    my $sensor_health_color = "";
    foreach(sort {$a->name cmp $b->name} @$sensors) {
    my $sensor_health = $_->healthState->key;
    if ($sensor_health =~ m/green/) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/red/) { $sensor_health_color=""; }
    elsif ($sensor_health_color =~ m/yellow/) { $sensor_health_color=""; }
    else { $sensor_health_color=""; }

    my $reading;
    if(defined($_->rateUnits)) {
    $reading = &restrict_num_decimal_digits(($_->currentReading * (10 ** $_->unitModifier)),3) . " " . $_->baseUnits . "/" . $_->rateUnits;
    } else {
    $reading = &restrict_num_decimal_digits(($_->currentReading * (10 ** $_->unitModifier)),3) . " " . $_->baseUnits;
    }
    $healthSoftwareString .= "".$sensor_health_color."
    ".$host_name."
    OKPROBLEMWARNINGUNKNOWN
    ".$_->name."
    OKPROBLEMWARNINGUNKNOWN
    ".$_->name."
    OKPROBLEMWARNINGUNKNOWN
    ".$_->name."
    ".$host_name."
    OKPROBLEMWARNINGUNKNOWN
    ".$_->name."".$reading."
    \n";                               }                               }                     }                }                ######################                
    1. PERFORMANCE
                   ######################                if($HOST_PERFORMANCE eq "yes" || $hostperformance eq "yes") {                     my $hostperf = &getCpuAndMemPerf($local_host);                     $hostPerfString .= $hostperf;                }                ######################                
    1. NIC
                   ######################                if($HOST_NIC eq "yes") {                     my $nics = $local_host->config->network->pnic;                     foreach my $nic (@$nics) {                          $nicString .= "";
    $nicString .= "";
    if($nic->linkSpeed) {
    $nicString .= "";
    } else {
    $nicString .= "";
    }
    $nicString .= "";
    if($demo eq "no") {
    $nicString .= "\n";
    } else {
    $nicString .= "
    ".$host_name."".$nic->device."".$nic->pci."".$nic->driver."".(($nic->linkSpeed->duplex) ? "FULL DUPLEX" : "HALF-DUPLEX")."".$nic->linkSpeed->speedMb." MBUNKNOWNUNKNOWN".(($nic->wakeOnLanSupported) ? "YES" : "NO")."".$nic->mac."
    demo_mode
    \n";                          }                     }                   }                ######################                
    1. HBA
                   ######################                if($HOST_HBA eq "yes") {                     my $hbas;                     eval { $hbas = $local_host->config->storageDevice->hostBusAdapter; };                     if(!$@) {                          foreach my $hba (@$hbas) {                               $hbaString .= "";
    if($hba->isa("HostFibreChannelHba")) {
    my $nwwn = (Math::BigInt->new($hba->nodeWorldWideName))->as_hex();
    my $pwwn = (Math::BigInt->new($hba->portWorldWideName))->as_hex();
    $nwwn =~ s/^..//;
    $pwwn =~ s/^..//;
    $nwwn = join(':', unpack('A2' x 8, $nwwn));
    $pwwn = join(':', unpack('A2' x 8, $pwwn));
    if($demo eq "no") {
    $hbaString .= "";
    } else {
    $nwwn = "XX:XX:XX:XX:XX:XX:XX:XX";
    $pwwn = "XX:XX:XX:XX:XX:XX:XX:XX";
    }
    } elsif($hba->isa("HostInternetScsiHba")) {
    $hbaString .= "";
    } elsif($hba->isa("HostParallelScsiHba")) {
    $hbaString .= "";
    } elsif($hba->isa("HostBlockHba")) {
    $hbaString .= "";
    }
    $hbaString .= "
    ".$host_name."FC".$hba->device."".$hba->pci."".$hba->model."".$hba->driver."".$hba->status."NWWN ".$nwwn."PWWN ".$pwwn."PORT TYPE ".$hba->portType->val."SPEED ".$hba->speed."iSCSI".$hba->device."".$hba->pci."".$hba->model."".$hba->driver."".$hba->status."".(($hba->authenticationProperties->chapAuthEnabled) ? "CHAP ENABLED" : "CHAP DISABLED")."SCSI".$hba->device."".$hba->pci."".$hba->model."".$hba->driver."".$hba->status."BLOCK".$hba->device."".$hba->pci."".$hba->model."".$hba->driver."".$hba->status."
    \n";                          }                     }                }                ######################                
    1. CAPABILITY
                   ######################                if($HOST_CAPABILITY eq "yes") {                     if($local_host->capability) {                          $capString .= "";
    $capString .= "
    ".$host_name."
    ";

     

                             
      1. FT ##
                             $capString .= "
    ".($local_host->capability->ftSupported ? "YES" : "NO")."
    ";                                                    
      1. IPMI ##
                             if($local_host->capability->ipmiSupported) {                               $capString .= "";
    } else {
    $capString .= "
    ".($local_host->capability->ipmiSupported ? "YES" : "NO")."N/A
    ";                          }

     

                             
      1. TPM ##
                             $capString .= "
    ".($local_host->capability->tpmSupported ? "YES" : "NO")."
    ";

     

                             
      1. HV ##
                             $capString .= "
    ".($local_host->capability->virtualExecUsageSupported ? "YES" : "NO")."
    ";                                     
      1. SSL THUMBPRINT ##
                             if($local_host->capability->loginBySSLThumbprintSupported) {                               $capString .= "";
    } else {
    $capString .= "";
    }

    $capString .= "
    ".($local_host->capability->loginBySSLThumbprintSupported ? "YES" : "NO")."N/A
    \n";                     }                }                ######################                
    1. CONFIGURATIONS
                   ######################                if($HOST_CONFIGURATION eq "yes") {                     my $netMgr = Vim::get_view(mo_ref => $local_host->configManager->networkSystem);                                     $configString .= "\n\n
    ".$host_name."
    \n";                           #############                     
      1. VMOTION ##
                        #############                     if($HOST_VMOTION eq "yes") {                          if($local_host->summary->config->vmotionEnabled) {                               $configString .= "\n";
    if($demo eq "no") {
    $configString .= "\n";
    $configString .= "\n";
    } else {
    $configString .= "\n";
    $configString .= "
    VMOTION ENABLEDYES
    IP ADDRESS".$local_host->config->vmotion->ipConfig->ipAddress." => ".$local_host->summary->config->name."
    NETMASK".$local_host->config->vmotion->ipConfig->subnetMask."
    IP ADDRESSX.X.X.X
    NETMASKX.X.X.X
    \n";                               }                               }                     }

     

                        #############                     
      1. GATEWAY ##
                        #############                     if($HOST_GATEWAY eq "yes") {                          if($demo eq "no") {                               if($netMgr->consoleIpRouteConfig->defaultGateway) {                                    $configString .= "\n";
    } else {
    $configString .= "\n";
    }
    if($netMgr->consoleIpRouteConfig->ipV6DefaultGateway) {
    $configString .= "\n";
    } else {
    $configString .= "\n";
    }
    if($netMgr->ipRouteConfig->defaultGateway) {
    $configString .= "\n";
    } else {
    $configString .= "\n";
    }
    if($netMgr->ipRouteConfig->ipV6DefaultGateway) {
    $configString .= "\n";
    } else {
    $configString .= "\n";
    }
    } else {
    $configString .= "
    GATEWAY".$netMgr->consoleIpRouteConfig->defaultGateway."
    GATEWAY0.0.0.0
    IPv6 GATEWAY".$netMgr->consoleIpRouteConfig->ipV6DefaultGateway."
    IPv6 GATEWAY0.0.0.0
    VMKERNEL GATEWAY".$netMgr->ipRouteConfig->defaultGateway."
    VMKERNEL GATEWAY0.0.0.0
    VMKERNEL IPv6 GATEWAY".$netMgr->ipRouteConfig->ipV6DefaultGateway."
    VMKERNEL IPv6 GATEWAY0.0.0.0
    GATEWAYX.X.X.X
    \n";                          }                     }

     

                        #####################                     
      1. SOFTWARE iSCSI  ##
                        #####################                     if($HOST_ISCSI eq "yes") {                          $configString .= "
    SOFTWAE iSCSI ENABLED".($local_host->config->storageDevice->softwareInternetScsiEnabled ? "YES" : "NO")."
    \n";                          }                    

     

                        #############                     
      1. IPV6    ##
                        #############                     if($HOST_IPV6 eq "yes") {                          $configString .= "
    IPv6 ENABLED".($local_host->config->network->ipV6Enabled ? "YES" : "NO")."
    \n";                                    }

     

                        #############                     
    1. FT       ##
                        #############                     if($HOST_FT eq "yes") {                          $configString .= "
    FT ENABLED".($local_host->summary->config->faultToleranceEnabled ? "YES" : "NO")."
    \n";                                    }

     

                        #############                     
    1. SSL      ##
                        #############                     if($HOST_SSL eq "yes") {                          $configString .= "
    SSL THUMBPRINT".($local_host->summary->config->sslThumbprint ? $local_host->summary->config->sslThumbprint : "N/A")."
    \n";                     }           

     

                        #############                     
      1. DNS     ##
                        #############                     if($HOST_DNS eq "yes") {                          my $searchDomains = $local_host->config->network->dnsConfig->searchDomain;                          my $searchString = "";                          foreach(@$searchDomains) {                               $searchString .= "search ".$_."
    ";
    }
    my $dnsAddress = $local_host->config->network->dnsConfig->address;
    my $dnsString = "";
    foreach(@$dnsAddress) {
    $dnsString .= "nameserver ".$_."
    ";
    }
    if($demo eq "no") {
    $configString .= "\n";
    } else {
    $configString .= "
    DNS"."domain ".($local_host->config->network->dnsConfig->domainName ? $local_host->config->network->dnsConfig->domainName : "N/A")."
    ".$searchString.$dnsString."
    DNSdomain demo_mode
    search demo_mode
    nameserver demo_mode
    \n";                          }                     }

     

                        #############                     
      1. UPTIME  ##
                        #############                     if($HOST_UPTIME eq "yes") {                          my ($host_date,$host_time) = split('T',$local_host->runtime->bootTime);                          my $todays_date = giveMeDate('YMD');                          chomp($todays_date);                          $configString .= "
    UPTIME".&days_between($host_date, $todays_date)." Days - ".$local_host->runtime->bootTime."
    \n";                     }

     

                        #################                     
      1. DIAGONISTIC ##
                        #################                     if($HOST_DIAGONISTIC eq "yes") {                          if($local_host->config->activeDiagnosticPartition) {                               my $diag_string .= "";
    $configString .= "
    ".$local_host->config->activeDiagnosticPartition->diagnosticType."".$local_host->config->activeDiagnosticPartition->id->diskName.$local_host->config->activeDiagnosticPartition->id->partition."".$local_host->config->activeDiagnosticPartition->storageType."
    DIAGNOSTIC PARTITION".$diag_string."
    TYPEPARITIONSTORAGE TYPE
    \n";                          }                     }

     

                        ###############                     
      1. SERVICES  ##
                        ###############                     if($HOST_SERVICE eq "yes") {                          my $services = $local_host->config->service->service;                          if($services) {                               my $serviceString = "";                               foreach(@$services) {                                    $serviceString .= ""
    }
    $configString .= "
    ".$_->label."".$_->policy."".(($_->running) ? "YES" : "NO")."
    SERVICE(s)".$serviceString."
    NAMEPOLICY TYPERUNNING
    \n";                          }                          }

     

                        #############                     
      1. NTP     ##     
                        #############                     if($HOST_NTP eq "yes") {                          if($local_host->config->dateTimeInfo) {                               my $ntps;                               eval { $ntps = $local_host->config->dateTimeInfo->ntpConfig->server; };                               if(!$@) {                                    my $ntpString = "";                                             if($ntps) {                                                     foreach (@$ntps) {                                                             $ntpString .= "$_
    ";
    }
    } else { $ntpString = "NONE CONFIGURED"; }
    $ntpString = "";
    $ntpString .= "";
    $configString .= "
    ".$ntpString."".$local_host->config->dateTimeInfo->timeZone->description."".$local_host->config->dateTimeInfo->timeZone->gmtOffset."".$local_host->config->dateTimeInfo->timeZone->name."
    NTP".$ntpString."
    NTP SERVERSTIME ZONEGMT OFFSETLOCATION
    \n";                               }                          }                     }

     

                        ###########                     
      1. VSWIF ##
                        ###########                     if($HOST_VSWIF eq "yes") {                          if($local_host->config->network->consoleVnic) {                               my $vswifString = "";                               my $console_vnics = $local_host->config->network->consoleVnic;                               foreach(@$console_vnics) {                                    if($demo eq "no") {                                         $vswifString .= "";
    } else {
    $vswifString .= "";
    }
    }
    $configString .= "
    ".$_->device."".$_->portgroup."".$_->spec->ip->ipAddress."".$_->spec->ip->subnetMask."".$_->spec->mac."".(($_->spec->ip->dhcp) ? "YES" : "NO")."
    ".$_->device."demo_modeX.X.X.XX.X.X.Xdemo_mode".(($_->spec->ip->dhcp) ? "YES" : "NO")."
    VSWIF(s)".$vswifString."
    NAMEPORTGROUPIP ADDRESSNETMASKMACDHCP
    \n";                                    }                     }

     

                        ##############                     
      1. VMKERNEL ##
                        ##############                     if($HOST_VMKERNEL eq "yes") {                          if($local_host->config->network->vnic) {                               my $vmkString = "";                               my $vmks = $local_host->config->network->vnic;                               foreach(@$vmks) {                                    if($demo eq "no") {                                         $vmkString .= "";
    } else {
    $vmkString .= "";
    }
    }
    $configString .= "
    ".$_->device."".$_->portgroup."".$_->spec->ip->ipAddress."".$_->spec->ip->subnetMask."".$_->spec->mac."".(($_->spec->ip->dhcp) ? "YES" : "NO")."
    ".$_->device."demo_modeX.X.X.XX.X.X.XX.X.X.X".(($_->spec->ip->dhcp) ? "YES" : "NO")."
    VMKERNEL(s)".$vmkString."
    INTERFACEPORTGROUPIP ADDRESSNETMASKMACDHCP
    \n";                          }                     }

     

                        #############                     
      1. VSWITCH ##
                        #############                     if($HOST_VSWITCH eq "yes") {                          my %vmmac_to_portgroup_mapping = ();                          my %cdp_enabled = ();                          my $vswitches = $local_host->config->network->vswitch;                                          my $vswitchString = "";                                      foreach my $vSwitch(@$vswitches) {                               my ($pNicName,$mtu,$cdp_vswitch,$pNicKey) = ("","","","");                                              my $vswitch_name = $vSwitch->name;                               my $pNics = $vSwitch->pnic;

     

                                  foreach (@$pNics) {                                                $pNicKey = $_;                                                if ($pNicKey ne "") {                                                        $pNics = $netMgr->networkInfo->pnic;                                                        foreach my $pNic (@$pNics) {                                                                if ($pNic->key eq $pNicKey) {                                                                        $pNicName = $pNicName ? ("$pNicName," . $pNic->device) : $pNic->device;                                                                        if($cdp_enabled{$pNic->device}) {                                                                                $cdp_vswitch = $cdp_enabled{$pNic->device};                                                                             } else {                                                                                $cdp_vswitch = "N/A";                                                                        }                                                                }                                                        }                                                }                                        }                               $mtu = $vSwitch-> if defined($vSwitch->);                               $vswitchString .= "
    VSWITCH NAMENUM OF PORTSUSED PORTSMTUUPLINKSCDP ENABLED
    ".$vSwitch->name."".$vSwitch->numPorts."".($vSwitch->numPorts - $vSwitch->numPortsAvailable)."".$vSwitch->
    ."\n";
    $vswitchString .= "\n";
    my $portGroups = $vSwitch->portgroup;
    foreach my $portgroup(@$portGroups) {
    my $pg = FindPortGroupbyKey ($netMgr, $vSwitch->key, $portgroup);
    next unless (defined $pg);
    my $usedPorts = (defined $pg->port) ? $#{$pg->port} + 1 : 0;
    if($demo eq "no") {
    $vswitchString .= "\n";
    } else {
    $vswitchString .= "\n";
    }
    $vswitch_portgroup_mappping{$pg->spec->name} = $vswitch_name;
    }
    }
    $configString .= "\n";

    my $networks = Vim::get_views(mo_ref_array => $local_host->network);
    foreach my $portgroup(@$networks) {
    my $vms_device = Vim::get_views(mo_ref_array => $portgroup->vm, properties => );
    foreach(@$vms_device) {
    my $vmname = $_->{'config.name'};
    my $devices = $_->{'config.hardware.device'};

    foreach(@$devices) {
    if($_->isa("VirtualEthernetCard")) {
    $vmmac_to_portgroup_mapping{$vmname} = $portgroup->
    ".$pNicName."".$cdp_vswitch."
    PORTGROUP NAMEVLAN IDUSED PORTSUPLINKS
    ".$pg->spec->name."".$pg->spec->vlanId."".$usedPorts."".$pNicName."
    demo_modedemo_mode".$usedPorts."".$pNicName."
    VSWITCH(s)".$vswitchString."
    name;                                         }                                    }                               }                          }                     }

     

                        ##########                     
      1. SNMP ##
                        ##########                     if($HOST_SNMP eq "yes") {                          my $snmp_system;                          eval { $snmp_system = Vim::get_view (mo_ref => $local_host->configManager->snmpSystem); };                          if(!$@) {                               if($snmp_system->configuration->enabled) {                                    my $snmpString = "";                                    $snmpString .= "";
    $configString .= "
    ".$snmp_system->configuration->port."";
    my $ro_community = $snmp_system->configuration->readOnlyCommunities;
    foreach(@$ro_community) {
    $snmpString .= $_ . ", ";
    }
    $snmpString .= "
    ";
    my $trap_targets = $snmp_system->configuration->trapTargets;
    foreach(@$trap_targets) {
    $snmpString .= "Community: " . $_->community . " Hostname: " . $_->hostName . " Port: " . $_->port . "
    \n";
    }
    $snmpString .= "
    SNMP".$snmpString."
    SNMP PORTRO COMMUNITIESTRAP TARGETS
    \n";                               }                               }                     }

     

                        ##############                     
      1. FIREWALL ##
                        ##############                     if($HOST_FIREWALL eq "yes") {                          if($local_host->config->firewall) {                               my $fw_sys = $local_host->config->firewall;                               my $fw_rules = $fw_sys->ruleset;                                        my $fw_known_string = "";                                        my $fw_rule_string = "";                                        foreach(@$fw_rules) {                                                if($_->enabled) {                                                        $fw_known_string .= "\n";
    }
    }
    $configString .= "\n";
    my $defaultPolicy = "\n";
    $configString .= "
    ".$_->label."
    FIREWALL
    KNOWN SERVICES ENABLED
    ".$fw_known_string."
    ".($fw_sys->defaultPolicy->incomingBlocked ? "YES" : "NO")."".($fw_sys->defaultPolicy->outgoingBlocked ? "YES" : "NO")."
    FIREWALL POLICY".$defaultPolicy."
    INCOMING ENABLEDOUTGOING ENABLED
    \n";                          }                     }

     

                        ###########                     
      1. POWER ##
                        ###########                     if($HOST_POWER eq "yes") {                          if($local_host->hardware->cpuPowerManagementInfo) {                               my $cpu_power_info = "";                               $cpu_power_info .= "";
    $configString .= "\n";
    }
    }

    $configString .= "
    ".($local_host->hardware->cpuPowerManagementInfo->currentPolicy)."".($local_host->hardware->cpuPowerManagementInfo->hardwareSupport)."
    CPU POWER MGMT INFO".$cpu_power_info."
    CURRENT POLICYHARDWARE SUPPORT
    \n";                }                ######################                
    1. ADVANCED OPTIONS
                   ######################                if($HOST_ADVOPT eq "yes") {                     my $advopts = Vim::get_view(mo_ref => $local_host->configManager->advancedOption);                     my $advSettings = $advopts->setting;

     

                        my ($diskUDR,$diskULR,$diskSNRO,$scsiCR,$nfsMV,$SBS,$RBS,$netTHS,$nfsHF,$nfsHT,$nfsHMF,$vmkernelBSM) = ("N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A");

     

                        foreach(@$advSettings) {                          my $key = $_->key;                          my $value = $_->value;

     

                             if($key eq "Disk.UseDeviceReset") { $diskUDR = $value; }                          if($key eq "Disk.UseLunReset") { $diskULR = $value; }                          if($key eq "Disk.SchedNumReqOutstanding") { $diskSNRO = $value; }                          if($key eq "Scsi.ConflictRetries") { $scsiCR = $value; }                          if($key eq "NFS.MaxVolumes") { $nfsMV = $value; }                          if($key eq "SendBufferSize") { $SBS = $value; }                          if($key eq "ReceiveBufferSize") { $RBS = $value; }                          if($key eq "Net.TcpipHeapSize") { $netTHS = $value; }                          if($key eq "NFS.HeartbeatFrequency") { $nfsHF = $value; }                          if($key eq "NFS.HeartbeatTimeout") { $nfsHT = $value; }                          if($key eq "NFS.HeartbeatMaxFailures") { $nfsHMF = $value; }                          if($key eq "VMkernel.Boot.techSupportMode") { $vmkernelBSM = $value; }                     }                     $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "";
    $advString .= "
    ".$host_name."".$diskUDR."".$diskULR."".$diskSNRO."".$scsiCR."".$nfsMV."".$SBS."".$RBS."".$netTHS."".$nfsHF."".$nfsHT."".$nfsHMF."".$vmkernelBSM."
    \n";                }                ######################                
    1. NUMA
                   ######################                if($HOST_NUMA eq "yes") {                     if($local_host->hardware->numaInfo) {                          my $numaInfo = $local_host->hardware->numaInfo;                          if($numaInfo->numNodes == 0) {                               $numaString .= "";
    } else {
    $numaString .= ""
    }
    $numaString .= "
    ".$host_name."NUMA-incapable".$numaInfo->type."N/A
    ".$host_name."".$numaInfo->numNodes."".$numaInfo->type."";
    if($numaInfo->numaNode) {
    my $nodes = $numaInfo->numaNode;
    $numaString .= "";
    foreach(@$nodes) {
    my $cpuID = $_->cpuID;
    my $idString = "";
    foreach(@$cpuID) {
    $idString = $_ . " " . $idString;
    }
    $numaString .= "";
    }
    $numaString .= "
    NODE IDCPU IDMEM RANGE BEGINMEM RANGE LENGTH
    ".$_->typeId."  ".&prettyPrintData($_->memoryRangeBegin,'B')."".&prettyPrintData($_->memoryRangeLength,'B')."
    ";
    } else {
    $numaString .= "N/A
    \n";                               }                     }                }                ######################                
    1. CDP
                   ######################                     if($HOST_CDP eq "yes") {                     my $netMgr = Vim::get_view(mo_ref => $local_host->configManager->networkSystem);                     my ($device,$port,$address,$cdp_ver,$devid,$duplex,$platform,$prefix,$location,$mgmt_addr,$cdpMtu,$samples,$sys_ver,$sys_name,$sys_oid,$timeout,$ttl,$vlan);                     my @physicalNicHintInfo = $netMgr->QueryNetworkHint();                     foreach (@physicalNicHintInfo){                          foreach ( @{$_} ){                               if($_->connectedSwitchPort) {                                    if($demo eq "no") {                                         $device = $_->device;                                         $port = $_->connectedSwitchPort->portId;                                         $address = ($_->connectedSwitchPort->address ? $_->connectedSwitchPort->address : "N/A");                                         $cdp_ver = ($_->connectedSwitchPort->cdpVersion ? $_->connectedSwitchPort->cdpVersion : "N/A");                                         $devid = ($_->connectedSwitchPort->devId ? $_->connectedSwitchPort->devId : "N/A");                                         $duplex = ($_->connectedSwitchPort->fullDuplex ? ($_->connectedSwitchPort->fullDuplex ? "YES" : "NO") : "N/A");                                         $platform = ($_->connectedSwitchPort->hardwarePlatform ? $_->connectedSwitchPort->hardwarePlatform : "N/A");                                         $prefix = ($_->connectedSwitchPort->ipPrefix ? $_->connectedSwitchPort->ipPrefix : "N/A");                                         $location = ($_->connectedSwitchPort->location ? $_->connectedSwitchPort->location : "N/A");                                         $mgmt_addr = ($_->connectedSwitchPort->mgmtAddr ? $_->connectedSwitchPort->mgmtAddr : "N/A");                                         $cdpMtu = ($_->connectedSwitchPort->mtu ? $_->connectedSwitchPort->mtu : "N/A");                                         $samples = ($_->connectedSwitchPort->samples ? $_->connectedSwitchPort->samples : "N/A");                                         $sys_ver = ($_->connectedSwitchPort->softwareVersion ? $_->connectedSwitchPort->softwareVersion : "N/A");                                         $sys_name = ($_->connectedSwitchPort->systemName ? $_->connectedSwitchPort->systemName : "N/A");                                         $sys_oid = ($_->connectedSwitchPort->systemOID ? $_->connectedSwitchPort->systemOID : "N/A");                                         $timeout = ($_->connectedSwitchPort->timeout ? $_->connectedSwitchPort->timeout : "N/A");                                         $ttl = ($_->connectedSwitchPort->ttl ? $_->connectedSwitchPort->ttl : "N/A");                                         $vlan = ($_->connectedSwitchPort->vlan ? $_->connectedSwitchPort->vlan : "N/A");                                    } else {                                         ($device,$address,$cdp_ver,$devid,$duplex,$platform,$prefix,$location,$mgmt_addr,$cdpMtu,$samples,$sys_ver,$sys_name,$sys_oid,$timeout,$ttl,$vlan) = ("demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode","demo_mode");                                    }                                    $cdpString .= "
    ".$host_name."".$device."".$mgmt_addr."".$address."".$prefix."".$location."".$sys_name."".$sys_ver."".$sys_oid."".$platform."".$devid."".$cdp_ver."".$duplex."".$cdpMtu."".$timeout."".$ttl."".$vlan."".$samples."
    \n";                                    }                          }                     }                }                ######################                
    1. DVS
                   ######################                if($HOST_DVS eq "yes") {                     if($atype eq 'VirtualCenter') {                          my ($dvsMgr,$dvs,$dvpg,$dvs_string);                          eval { $dvsMgr = Vim::get_view(mo_ref => $sc->dvSwitchManager); };                          if(!$@) {                               my $dvs_target = $dvsMgr->QueryDvsConfigTarget(host => $local_host);                               if($dvs_target) {                                    $dvs = $dvs_target->distributedVirtualSwitch;                                    $dvpg = $dvs_target->distributedVirtualPortgroup;                               }                               if($dvpg) {                                    foreach(@$dvpg) {                                         $vswitch_portgroup_mappping{$_->portgroupName} = $_->switchName;                                    }                               }                               if($dvs) {                                    foreach(@$dvs) {                                         my $sName = defined $_->switchName ? $_->switchName : "N/A";                                         if(!$seen_dvs{$sName}) {                                              my $sUuid = ($_->switchUuid ? $_->switchUuid : "N/A");                                              my $dv_switch = Vim::get_view(mo_ref => $_->distributedVirtualSwitch);                                              my $desc = ($dv_switch->summary->description ? $dv_switch->summary->description : "N/A");                                              my $contact_name = ($dv_switch->summary->contact->name ? $dv_switch->summary->contact->name : "N/A");                                              my $contact_con = ($dv_switch->summary->contact->contact ? $dv_switch->summary->contact->contact : "");                                              my $contact_info = $contact_name . " " . $contact_con;                                              my $build = ($dv_switch->summary->productInfo->build ? $dv_switch->summary->productInfo->build : "N/A");                                              my $bid = ($dv_switch->summary->productInfo->bundleId ? $dv_switch->summary->productInfo->bundleId : "N/A");                                              my $burl = ($dv_switch->summary->productInfo->bundleUrl ? $dv_switch->summary->productInfo->bundleUrl: "N/A");                                              my $fclass = ($dv_switch->summary->productInfo->forwardingClass ? $dv_switch->summary->productInfo->forwardingClass : "N/A");                                              my $vendor = ($dv_switch->summary->productInfo->vendor ? $dv_switch->summary->productInfo->vendor : "N/A");                                              my $version = ($dv_switch->summary->productInfo->version ? $dv_switch->summary->productInfo->version : "N/A");                                              my $ports = ($dv_switch->summary->numPorts ? $dv_switch->summary->numPorts : "N/A");                                              $dvs_string = "
    ".$sName."".$desc."".$contact_info."".$vendor."".$version."".$sUuid."".$build."".$bid."".$build."".$burl."".$fclass."".$ports."
    \n";                                              push @dvs, $dvs_string;                                         }                                         $seen_dvs{$sName} = 1;                                    }                               }                          }                               }                     }                ######################                        
    1. LUN
                            ######################                if($HOST_LUN eq "yes") {                     my $ss = Vim::get_view(mo_ref => $local_host->configManager->storageSystem);                     my $fsmount = $ss->fileSystemVolumeInfo->mountInfo;                     my $luns = $ss->storageDeviceInfo->scsiLun;                                          my ($volume,$extents,$diskName,$partition,$deviceName,$lunname,$volumename,$vendor,$model,$queuedepth,$states) = ('','','','','','','','','','','');

     

                        foreach my $fsm (@$fsmount) {                          $volume = $fsm->volume;                          if ($volume->type eq 'VMFS') {                               $extents = $volume->extent;                               my $i = 0;                               foreach my $extent (@$extents) {                                    $diskName = $extent->diskName;                                    my $lun_row = "";                                    foreach my $lun (sort {$a->canonicalName cmp $b->canonicalName} @$luns) {                                         if ($diskName eq $lun->canonicalName) {                                              $deviceName = $lun->deviceName;                                              $volumename = $volume->name;                                              $lunname = $lun->canonicalName;                                              $vendor = $lun->vendor;                                              $model = $lun->model;                                              $queuedepth = $lun->queueDepth;                                              $states = $lun->operationalState;                                              last;                                         }                                    }                                    $partition = $extent->partition;                                    $luns{$volume->uuid} .= $host_name . "_" . $lunname . ",";                                    $lun_row .= "";
    $lun_row .= "";
    $lun_row .= "";
    if($queuedepth) { $lun_row .= "N/A"; }
    my $state_string = "";
    foreach (@$states) {
    $state_string .= $_." ";
    }
    $lun_row .= "";
    $lun_row_info{$volume->
    ".$volumename.""."$diskName:$partition".""."$deviceName:$partition"."".$queuedepth."".$state_string."".$vendor."".$model."
    uuid} = $lun_row;                               }                          }                     }                }                ######################                        
    1. DATASTORE
                            ######################                if($HOST_DATASTORE eq "yes") {                     my $ds_views = Vim::get_views (mo_ref_array => $local_host->datastore);                     my $ctr = 0;                     foreach my $ds (sort {$a->info->name cmp $b->info->name} @$ds_views) {                          my $ds_row = "";                          if($ds->summary->accessible) {                               #capture unique datastores seen in cluster                               if (!grep {$_ eq $ds->info->name} @datastores_seen) {                                    push @datastores_seen,$ds->info->name;                                    my ($perc_free,$perc_string,$ds_used,$ds_free,$ds_cap,$ds_block,$ds_ver) = ("","","","","","N/A","N/A");                                    if ( ($ds->summary->freeSpace gt 0) || ($ds->summary->capacity gt 0) ) {                                         $ds_cap = &restrict_num_decimal_digits($ds->summary->capacity/1024/1000,2);                                         $ds_used = prettyPrintData(($ds->summary->capacity - $ds->summary->freeSpace),'B');                                         $ds_free = &restrict_num_decimal_digits(($ds->summary->freeSpace/1024/1000),2);                                         $perc_free = &restrict_num_decimal_digits(( 100 * $ds_free / $ds_cap),2);                                         $perc_string = getColor($perc_free);                                         if($ds->summary->type eq 'VMFS') {                                              $ds_block = $ds->info->vmfs->blockSizeMb;                                              $ds_ver = $ds->info->vmfs->version;                                         }                                    } else {                                         ($perc_free,$ds_used,$ds_free) = ("UNKNOWN","UNKNOWN","UNKNOWN");                                    }                                    $ds_row = "$perc_string";

    $datastore_row_info{$ds->info->name} = $ds_row;
    }
    $datastores{$ds->info->
    ".(prettyPrintData($ds->summary->capacity,'B'))."".$ds_used."".prettyPrintData($ds->summary->freeSpace,'B')."$ds_block".$ds_ver."".$ds->summary->type."
    name} .= $host_name. "_" . $ctr++ .",";                          }                     }                }                ######################                        
    1. PORTGROUP
                            ######################                if($HOST_PORTGROUP eq "yes") {                     my $portgroup_views = Vim::get_views (mo_ref_array => $local_host->network);                     foreach my $portgroup (sort {$a->summary->name cmp $b->summary->name} @$portgroup_views) {                          my $pg_row = "";                          if($portgroup->summary->accessible) {                               push @hosts_in_portgroups,$host_name;                                                              #logic to figure out which hosts can not see this portgroup                                           my @intersection = ();                                           my @difference = ();                                           my %count = ();                                           foreach my $element (@hosts_in_portgroups, @hosts_seen) { $count{$element}++ }                                           foreach my $element (keys %count) {                                                   push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;                                           }                               if(@difference) {                                    my $hosts_not_accessible = "";                                    foreach (@difference) {                                         $hosts_not_accessible .= $_." ";                                    }                                    if($demo eq "no") {                                         $pg_row .= "";
    } else {
    $pg_row .= "";
    }
    } else {
    $pg_row .= "";
    }
    $portgroup_row_info{$portgroup->
    $hosts_not_accessibledemo_modeAccessible by all hosts in this cluster
    name} = $pg_row;                          }                     }                }

     

                   ######################                        
    1. MULTIPATH
                            ######################                if($HOST_MULTIPATH eq "yes") {                     my $storageSys;                     eval { $storageSys = Vim::get_view (mo_ref => $local_host->configManager->storageSystem); };                     if(!$@) {                                my $luns = $storageSys->storageDeviceInfo->scsiLun;                                my $hbas = $storageSys->storageDeviceInfo->hostBusAdapter;                                my $mpLuns = $storageSys->storageDeviceInfo->multipathInfo->lun;                                          $multipathString .= "\n";

    my $verbose;
    foreach my $mpLun (@$mpLuns) {
    my $paths = $mpLun->path;
    my $numPaths = scalar(@$paths);
    my $lun = find_by_key($luns, $mpLun->lun);

    my $pol = $mpLun->policy;
    my $polPrefer;
    if (defined($pol) && defined($pol->{prefer})) {
    $polPrefer = $pol->prefer;
    }
    my $cap = $lun->
    ".$local_host->name."
    ;                               my $deviceUuidPath = defined($lun->) ? ("vml." . $lun->uuid) : "";                               $multipathString .= "\n";
    $multipathString .= "
    ".(defined($lun->
    ) ? $lun->lunType : "")." ".(defined($lun->) ? $lun->canonicalName : "").($verbose ? " $deviceUuidPath" : "")." ".(defined($cap) ? " ( " . int($cap->block * $cap->blockSize / (1024*1024)) . " MB )" : " ( 0 MB )")." ==  # of Paths: ".$numPaths." Policy: ".((defined($pol) && defined($pol->)) ? $pol->policy : "")."\n";

    foreach my $path (@$paths) {
    my $hba = find_by_key($hbas, $path->adapter);
    my $isFC = $hba->isa("HostFibreChannelHba");
    my $state = ($path->{pathState} ? (($path->pathState eq "active") ? "On active" : $path->pathState) : "");
    my $pciString = get_pci_string($hba);
    if($demo eq "no") {
    $multipathString .= "\n";
    } else {
    $multipathString .= "\n";
    }
    }
    $multipathString .= "
    ".($isFC ? "FC" : "Local")." ".$pciString." ".($isFC ? $hba->nodeWorldWideName . "<->" . $hba->portWorldWideName : "")." ".$path->name." ".$state." ".((defined($polPrefer) && ($path->name eq $polPrefer)) ? "preferred" : "")."
    ".($isFC ? "FC" : "Local")." ".$pciString." "."demo_mode <-> demo_mode "." ".$path->name." ".$state." ".((defined($polPrefer) && ($path->name eq $polPrefer)) ? "preferred" : "")."

    \n";                          }                     }                }                ######################                        
    1. LOG
                            ######################                         if($HOST_LOG eq "yes") {                     my $logKey = "hostd";                     my ($diagMgr,$logData);                     eval { $diagMgr = Vim::get_view(mo_ref => $sc->diagnosticManager); };                     if($atype eq 'VirtualCenter') {                          $logData = $diagMgr->BrowseDiagnosticLog(key => $logKey, host => $local_host, start => "999999999");                     } else {                          $logData = $diagMgr->BrowseDiagnosticLog(key => $logKey, start => "999999999");                     }                     my $lineEnd = $logData->lineEnd;                     my $start = $lineEnd - $logcount;                     if($atype eq 'VirtualCenter') {                          $logData = $diagMgr->BrowseDiagnosticLog(key => $logKey, host => $local_host, start => $start,lines => $logcount);                     } else {                          $logData = $diagMgr->BrowseDiagnosticLog(key => $logKey, start => $start,lines => $logcount);                     }                     $logString .= "\n";
    if ($logData->lineStart != 0) {
    my $logConcat = "";
    foreach my $line (@{$logData->lineText}) {
    if($demo eq "no") {
    $logConcat .= $line."
    ";
    } else {
    $logConcat = "demo_mode";
    }
    }
    $logString .= "
    ".$host_name."
    ".$logConcat."
    \n";                          }                }

     

                   
      1. END OF HOSTS ##
              }                      ###############################################           
      1. HACK TO PRINT DVS,LUN,DATASTORE and PORTGRUP  ##
              ###############################################           if($HOST_DVS eq "yes") {                foreach(@dvs) {                     $dvsString .= $_;                }                @dvs = ();           }           if($HOST_LUN eq "yes") {                #logic to check which hosts can see all luns                while ( my ($uuid, $value) = each(%luns) ) {                     my @pairs = split(',',$value);                           my $pair_count = @pairs;                     my @hosts_to_luns = ();                     for (my $x=0;$x < $pair_count;$x++) {
    (my $hostname,my $vmhba) = split('_',$pairs[$x],2);
    push @hosts_to_luns, $hostname;
    }
    #logic to figure out which hosts can not see this lun
    my @intersection = ();
    my @difference = ();
    my %count = ();
    foreach my $element (@hosts_to_luns, @hosts_seen) { $count{$element}++ }
    foreach my $element (keys %count) {
    push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
    }

    my $print_string = "";
    if(@difference) {
    foreach (@difference) {
    $print_string .= $_." ";
    }
    }
    if($print_string eq '') {
    $print_string = "";
    } else {
    $print_string = "";
    }
    $lun_row_info{$uuid} .= $print_string;
    @hosts_to_luns = ();
    }

    foreach my $lun ( sort keys %lun_row_info ) {
    my $value = $lun_row_info{$lun};
    $lunString .= "".$value."\n";
    }
    (%luns,%lun_row_info) = ();
    }
    if($HOST_DATASTORE eq "yes") {
    #logic to check which hosts can see all datastores
    while ( my ($ds, $value) = each(%datastores) ) {
    my @pairs = split(',',$value);
    my $pair_count = @pairs;
    my @hosts_to_datastores = ();
    for (my $x=0;$x < $pair_count;$x++) {
    (my $hostname,my $count) = split('_',$pairs[$x],2);
    push @hosts_to_datastores, $hostname;
    }
    #logic to figure out which hosts can not see this datastore
    my @intersection = ();
    my @difference = ();
    my %count = ();
    foreach my $element (@hosts_to_datastores, @hosts_seen) { $count{$element}++ }
    foreach my $element (keys %count) {
    push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
    }

    my $print_string = "";
    if(@difference) {
    foreach (@difference) {
    $print_string .= $_." ";
    }
    }
    if($print_string eq '') {
    $print_string = "";
    } else {
    $print_string = "";
    }
    $datastore_row_info{$ds} .= $print_string;
    @hosts_to_datastores = ();
    }

    for my $datastore ( sort keys %datastore_row_info ) {
    my $value = $datastore_row_info{$datastore};
    $datastoreString .= "".$value."\n";
    }
    (%datastores,%datastore_row_info) = ();
    }
    if($HOST_PORTGROUP eq "yes") {
    for my $portgroup ( sort keys %portgroup_row_info ) {
    my $value = $portgroup_row_info{$portgroup};
    if($demo eq "no") {
    $portgroupString .= "".$value."\n";
    } else {
    $portgroupString .= "".$value."
    Accessible by all hosts in this cluster".$print_string."
    ".$lun."
    Accessible by all hosts in this cluster".$print_string."
    ".$datastore."
    ".$portgroup."
    demo_mode
    \n";                     }                }                               (%portgroup_row_info) = ();           }

     

              
      1. Executed outside of the hosts ##

     

              ######################                
    1. TASK
                    ######################                 if($HOST_TASK eq "yes") {                      my $taskMgr;                         eval { $taskMgr = Vim::get_view(mo_ref => $sc->taskManager); };                         if(!$@) {                              my $tasks = Vim::get_views(mo_ref_array => $taskMgr->recentTask);                                 foreach(@$tasks) {                                      my $progress = $_->info->progress;                                         if(!defined($progress)) {                                              $progress = "COMPLETED";                                         }                                         $taskString .= "\n";
    }
    }
    }

    @hosts_seen = ();
    @datastores_seen = ();
    @hosts_in_portgroups = ();
    &buildHostReport($cluster_name,$cluster_count,$type,$atype,$aversion);
    }
    }

    sub buildHostReport {
    my ($cluster_name,$cluster_count,$type,$atype,$aversion) = @_;

    my ($hostTag,$hostTagShort,$table_host_conf) = ("","","");

    if($HOST_HARDWARE_CONFIGURATION eq "yes" && $hardwareConfigurationString ne "") {
    $hostTag = "ESX/ESXi Hardware Configuration-$cluster_count";
    $hostTagShort = "ESX/ESXi Hardware Configuration";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $hardwareConfigurationString;
    $table_host_conf .= "
    ".$_->info->descriptionId."".$_->info->queueTime."".($_->info->startTime ? $_->info->startTime : "N/A")."".($_->info->completeTime ? $_->info->completeTime : "N/A")."".$progress."".$_->info->state->val."
    HOSTNAMEVENDORADDITIONAL VENDOR INFOMODELCPU INFOHT AVAILABLECPU SPEEDCPU USAGEPROCESSOR SOCKETSCORES PER SOCKETLOGICAL CORESMEMORYMEMORY USAGENIC(s)HBA(s)
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$hardwareConfigurationString) = ("","");
    }
    if($HOST_MGMT eq "yes" && $mgmtString ne "") {
    $hostTag = "ESX/ESXi Management Info-$cluster_count";
    $hostTagShort = "ESX/ESXi Management Info";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $mgmtString;
    $table_host_conf .= "
    HOSTNAMEvCenterLOCKDOWN MODE ENABLEDUUIDSERVICE CONSOLE MEM
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$mgmtString) = ("","");
    }
    if($HOST_STATE eq "yes" && $stateString ne "") {
    $hostTag = "ESX/ESXi State-$cluster_count";
    $hostTagShort = "ESX/ESXi State";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $stateString;
    $table_host_conf .= "
    HOSTNAMEOVERALL STATUSPOWER STATEBOOT TIMECONNECTION STATEMAINTENANCE MODEVMOTION ENABLEDVERSION
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$stateString) = ("","");
    }
    if($HOST_HEALTH eq "yes" && $healthHardwareString ne "") {
    $hostTag = "ESX/ESXi Health Hardware Status-$cluster_count";
    $hostTagShort = "ESX/ESXi Health Hardware Status";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $healthHardwareString;
    $table_host_conf .= "
    COMPONENTSTATUS
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$healthHardwareString) = ("","");
    }
    if($HOST_HEALTH eq "yes" && $healthSoftwareString ne "") {
    $hostTag = "ESX/ESXi Health Software Status-$cluster_count";
    $hostTagShort = "ESX/ESXi Health Software Status";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "Click here for more detail info\n";
    $table_host_conf .= "
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $healthSoftwareString;
    $table_host_conf .= "
    SENSOR NAMEREADINGSTATUS
    \n";
    $table_host_conf .= "
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$healthSoftwareString) = ("","");
    }
    if($HOST_PERFORMANCE eq "yes" || $hostperformance eq "yes" && $hostPerfString ne "") {
    $hostTag = "ESX/ESXi Performance-$cluster_count";
    $hostTagShort = "ESX/ESXi Performance";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $hostPerfString;
    $table_host_conf .= "
    HOSTcpu.usagemhz.averagecpu.usage.averagemem.active.averagemem.usage.average
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$hostPerfString) = ("","");
    }
    if($HOST_NIC eq "yes" && $nicString ne "") {
    $hostTag = "ESX/ESXi NIC(s)-$cluster_count";
    $hostTagShort = "ESX/ESXi NIC(s)";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $nicString;
    $table_host_conf .= "
    HOSTDEVICEPCIDRIVERDUPLEXSPEEDWOL ENABLEDMAC
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$nicString) = ("","");
    }
    if($HOST_HBA eq "yes" && $hbaString ne "") {
    $hostTag = "ESX/ESXi HBA(s)-$cluster_count";
    $hostTagShort = "ESX/ESXi HBA(s)";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $hbaString;
    $table_host_conf .= "
    HOSTHBA TYPEDEVICEPCIMODELDRIVERSTATUSADDITIONAL INFO
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$hbaString) = ("","");
    }
    if($HOST_CAPABILITY eq "yes" && $capString ne "") {
    $hostTag = "ESX/ESXi Capabilitie(s)-$cluster_count";
    $hostTagShort = "ESX/ESXi Capabilitie(s)";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $capString;
    $table_host_conf .= "
    HOSTFT SUPPORTIPMI SUPPORTTPM SUPPORTHV SUPPORTSSL THUMBPRINT AUTH SUPPORT
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$capString) = ("","");
    }
    if($HOST_CONFIGURATION eq "yes" && $configString ne "") {
    $hostTag = "ESX/ESXi Configuration(s)-$cluster_count";
    $hostTagShort = "ESX/ESXi Configuration(s)";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";

    $table_host_conf .= $configString;
    #$table_host_conf .= "\n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$configString) = ("","");
    }
    if($HOST_ADVOPT eq "yes" && $advString ne "") {
    $hostTag = "ESX/ESXi Advanced Options-$cluster_count";
    $hostTagShort = "ESX/ESXi Advanced Options";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $advString;
    $table_host_conf .= "
    HOSTDisk.UseDeviceResetDisk.UseLunResetDisk.SchedNumReqOutstandingScsi.ConflictRetriesNFS.MaxVolumesSendBufferSizeReceiveBufferSizeNet.TcpipHeapSizeNFS.HeartbeatFrequencyNFS.HeartbeatTimeoutNFS.HeartbeatMaxFailuresVMkernel.Boot.techSupportMode
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$advString) = ("","");
    }
    if($HOST_NUMA eq "yes" && $numaString ne "") {
    $hostTag = "ESX/ESXi NUMA-$cluster_count";
    $hostTagShort = "ESX/ESXi NUMA";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $numaString;
    $table_host_conf .= "
    HOST# NODESTYPENUMA NODE INFO
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$numaString) = ("","");
    }
    if($HOST_CDP eq "yes" && $cdpString ne "") {
    $hostTag = "ESX/ESXi CDP-$cluster_count";
    $hostTagShort = "ESX/ESXi CDP";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $cdpString;
    $table_host_conf .= "
    HOSTDEVICEMGMT ADDRESSDEVICE ADDRESSIP PREFIXLOCATIONSYSTEM NAMESYSTEM VERSIONSYSTEM OIDPLATFORMDEVICE IDCDP VERFULL DUPLEXMTUTIMEOUTTTLVLAN IDSAMPLES
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$cdpString) = ("","");
    }
    if($HOST_DVS eq "yes" && $atype eq "VirtualCenter" && $dvsString ne "") {
    $hostTag = "ESX/ESXi Distributed vSwitch-$cluster_count";
    $hostTagShort = "ESX/ESXi Distributed vSwitch";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $dvsString;
    $table_host_conf .= "
    NAMEDESCRIPTIONCONTACT INFOVENDORVERSIONUUIDBUILD
    BUNDLE ID
    BUNDLE BUILDBUNDLE URLFORWARDING CLASSPORTS
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$numaString) = ("","");
    }
    if($HOST_LUN eq "yes" && $lunString) {
    $hostTag = "ESX/ESXi LUN(s)-$cluster_count";
    $hostTagShort = "ESX/ESXi LUN(s)";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $lunString;
    $table_host_conf .= "
    VOLUME UUIDDATASTOREDISK_NAMEDEVICE_NAMEQUEUE DEPTHSTATUSVENDORMODELHOST(s) NOT ACCESSIBLE TO LUN
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$lunString) = ("","");
    }
    if($HOST_DATASTORE eq "yes" && $datastoreString ne "") {
    $hostTag = "ESX/ESXi Datastore(s)-$cluster_count";
    $hostTagShort = "ESX/ESXi Datastore(s)";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "
    COLOR LEGENDYELLOW < $YELLOW_WARN %ORANGE < $ORANGE_WARN %RED < $RED_WARN %
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $datastoreString;
    $table_host_conf .= "
    DATASTORECAPACITYCONSUMEDFREE% FREEBLOCK SIZEVERSIONDS TYPEHOST(s) NOT ACCESSIBLE TO DATASTORE
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$datastoreString) = ("","");
    }
    if($HOST_PORTGROUP eq "yes" && $portgroupString ne "") {
    $hostTag = "ESX/ESXi Portgroup(s)-$cluster_count";
    $hostTagShort = "ESX/ESXi Portgroup(s)";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $portgroupString;
    $table_host_conf .= "
    PORTGROUPHOST(s) NOT ACCESSIBLE TO PORTGROUP
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$portgroupString) = ("","");
    }
    if($HOST_MULTIPATH eq "yes" && $multipathString ne "") {
    $hostTag = "ESX/ESXi Multipathing-$cluster_count";
    $hostTagShort = "ESX/ESXi Multipathing";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";

    $table_host_conf .= $multipathString;
    $table_host_conf .= "
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$multipathString) = ("","");
    }
    if($HOST_LOG eq "yes" && $logString ne "") {
    $hostTag = "ESX/ESXi Hostd Logs-$cluster_count - Last $logcount lines";
    $hostTagShort = "ESX/ESXi Hostd Logs - Last $logcount lines";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";

    $table_host_conf .= $logString;
    $table_host_conf .= "
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$logString) = ("","");
    }
    if($HOST_TASK eq "yes" && $taskString ne "") {
    $hostTag = "ESX/ESXi Recent Tasks-$cluster_count";
    $hostTagShort = "ESX/ESXi Recent Tasks";

    push @host_jump_tags,"            $hostTagShort
    \n";

    $table_host_conf .= "\n";
    $table_host_conf .= "h3. $hostTagShort:
    \n";
    $table_host_conf .= "\n";
    $table_host_conf .= "\n";

    $table_host_conf .= $taskString;
    $table_host_conf .= "
    DESCRIPTIONQUEUE TIMESTART TIMECOMPLETION TIMEPROGRESSSTATE
    \n";
    $hostString .= "
    ".$table_host_conf;
    ($table_host_conf,$numaString) = ("","");
    }

    print REPORT_OUTPUT $hostString;
    $hostString = "";
    }

    sub buildVMReport {
    my ($cluster_name,$cluster_count,$type,$atype,$aversion) = @_;
    my ($hostTag,$hostTagShort,$table_vm_conf) = ("","","");

    if($VM_CONFIG eq "yes" && $vmconfigString ne "") {
    $hostTag = "VM Configuration-$cluster_count";
    $hostTagShort = "VM Configuration";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmconfigString;
    $table_vm_conf .= "
    HOSTVMHOSTNAMEUUIDBOOTTIMEOSOVERALL STATUSCONNECTION STATEPOWER STATE# of vCPUvMEM# of vDISKvDISK# of vNICCPU RESERVMEM RESERVIS TEMPLATE
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmconfigString) = ("","");
    }
    if($VM_STATS eq "yes" && $vmstatString ne "") {
    $hostTag = "VM Statistics-$cluster_count";
    $hostTagShort = "VM Statistics";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmstatString;
    $table_vm_conf .= "
    HOSTVMCPU USAGEMEM USAGEMAX CPU USAGEMAX MEM USAGEACTIVE MEMHOST CONSUMED MEMMEM OVERHEADMEM BALLON
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmstatString) = ("","");
    }
    if($VM_RESOURCE_ALLOCATION eq "yes" && $vmrscString ne "") {
    $hostTag = "VM Resource Allocation-$cluster_count";
    $hostTagShort = "VM Resource Allocation";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmrscString;
    $table_vm_conf .= "
    HOSTVMLAST MODIFIEDCPU RESERVATIONCPU LIMITSCPU SHARECPU SHARE LEVELCPU EXPANDABLE RESERVATIONCPU OVERHEAD LIMITMEM RESERVATIONMEM LIMITSMEM SHAREMEM SHARE LEVELMEM EXPANDABLE RESERVATIONMEM OVERHEAD LIMIT
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmrscString) = ("","");
    }
    if($VM_PERFORMANCE eq "yes" || $vmperformance eq "yes" && $vmPerfString ne "") {
    $hostTag = "VM Performance-$cluster_count";
    $hostTagShort = "VM Performance";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmPerfString;
    $table_vm_conf .= "\n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmPerfString) = ("","");
    }
    if($VM_FT eq "yes" && $vmftString ne "") {
    $hostTag = "VM Fault Tolerance-$cluster_count";
    $hostTagShort = "VM Fault Tolerance";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmftString;
    $table_vm_conf .= "
    VMcpu.usagemhz.averagecpu.usage.averagecpu.ready.summationmem.active.averagemem.usage.averagecpu.vmmemctl.average
    HOSTVMFT STATEROLEINSTANCE UUIDSFT SECONDARY LATENCYFT BANDWIDTH
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmftString) = ("","");
    }
    if($VM_THIN eq "yes" && $vmthinString ne "") {
    $hostTag = "VM Thin Provisioned-$cluster_count";
    $hostTagShort = "VM Thin Provisioned";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmthinString;
    $table_vm_conf .= "
    HOSTVMLABELTHIN VMDK(s)CAPACITY
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmthinString) = ("","");
    }
    if($VM_DEVICE eq "yes" && $vmdeviceString ne "") {
    $hostTag = "VM Device(s)-$cluster_count";
    $hostTagShort = "VM Device(s)";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmdeviceString;
    $table_vm_conf .= "
    HOSTVMOSCDROMCONTROLLERDISKETHERNET CARDFLOPPYKEYBOARDVIDEO CARDVMCIVMIROMPARALLEL PORTPCI PASSTHROUGHPOINTING DEVICESCSI PASSTHROUGHSERIAL PORTSOUND CARDUSB
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmdeviceString) = ("","");
    }
    if($VM_STORAGE eq "yes" && $vmstorageString ne "") {
    $hostTag = "VM Storage-$cluster_count";
    $hostTagShort = "VM Storage";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "
    COLOR LEGENDYELLOW < $YELLOW_WARN %ORANGE < $ORANGE_WARN %RED < $RED_WARN %
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmstorageString;
    $table_vm_conf .= "
    HOSTVM
    DISK INFOFREE SPACECAPACITY% FREE
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmstorageString) = ("","");
    }
    if($VM_NETWORK eq "yes" && $vmnetworkString ne "") {
    $hostTag = "VM Network-$cluster_count";
    $hostTagShort = "VM Network";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmnetworkString;
    $table_vm_conf .= "
    HOSTVMIP ADDRESS(s)MAC ADDRESS(s)PORTGROUP(s)CONNECTED
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmnetworkString) = ("","");
    }
    if($VM_SNAPSHOT eq "yes" && $vmsnapString ne "") {
    $hostTag = "VM Snapshots-$cluster_count";
    $hostTagShort = "VM Snapshots";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmsnapString;
    $table_vm_conf .= "
    HOSTVMSNAPSHOT NAMESNAPSHOT DESCCREATEDSTATEQUIESCED
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmsnapString) = ("","");
    }
    if($VM_DELTA eq "yes" && $vmdeltaString ne "") {
    $hostTag = "VM Deltas-$cluster_count";
    $hostTagShort = "VM Deltas";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "
    COLOR LEGENDYELLOW > $SNAPSHOT_YELLOW_WARN daysORANGE > $SNAPSHOT_ORANGE_WARN daysRED > $SNAPSHOT_RED_WARN days
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmdeltaString;
    $table_vm_conf .= "
    DATASTOREVM DELTAAGESIZECREATED
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmdeltaString) = ("","");
    }
    if($VM_CDROM eq "yes" && $vmcdString ne "") {
    $hostTag = "VM Mounted CD-ROM-$cluster_count";
    $hostTagShort = "VM Mounted CD-ROM";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmcdString;
    $table_vm_conf .= "
    HOSTVMISO
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmcdString) = ("","");
    }
    if($VM_FLOPPY eq "yes" && $vmflpString ne "") {
    $hostTag = "VM Mounted Floppy-$cluster_count";
    $hostTagShort = "VM Mounted Floppy";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmflpString;
    $table_vm_conf .= "
    HOSTVMIMG
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmflpString) = ("","");
    }
    if($VM_TOOL eq "yes" && $vmtoolString) {
    $hostTag = "VM VMware Tools-$cluster_count";
    $hostTagShort = "VM VMware Tools";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmtoolString;
    $table_vm_conf .= "
    HOSTVMVERSIONRUNNING STATUSVERSION STATUSUPGRADE POLICYSYNC TIME W/HOST
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmtoolString) = ("","");
    }
    if($VM_RDM eq "yes" && $vmrdmString ne "") {
    $hostTag = "VM RDMs-$cluster_count";
    $hostTagShort = "VM RDMs";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmrdmString;
    $table_vm_conf .= "
    HOSTVMCOMPAT MODEDEVICEDISK MODELUN UUIDVIRTUAL DISK UUID
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmrdmString) = ("","");
    }
    if($VM_NPIV eq "yes" && $vmnpivString ne "") {
    $hostTag = "VM NPIV-$cluster_count";
    $hostTagShort = "VM NPIV";

    push @vm_jump_tags,"            $hostTagShort
    \n";

    $table_vm_conf .= "\n";
    $table_vm_conf .= "h3. $hostTagShort:
    \n";
    $table_vm_conf .= "\n";
    $table_vm_conf .= "\n";

    $table_vm_conf .= $vmnpivString;
    $table_vm_conf .= "
    HOSTVMNODE WWNPORT WWNGENERATED FROMDESIRED NODE WWNDESIRED PORT WWN
    \n";
    $vmString .= "
    ".$table_vm_conf;
    ($table_vm_conf,$vmnpivString) = ("","");
    }

    print REPORT_OUTPUT $vmString;
    $vmString = "";
    }

    sub printClusterSummary {
    my ($local_cluster,$cluster_count) = @_;

    my $cluster_name = $local_cluster->name;
    my $cluster_health = $local_cluster->overallStatus->val;
    my $cluster_host_cnt = $local_cluster->summary->numHosts;
    my $cluster_avail_host = $local_cluster->summary->numEffectiveHosts;
    my $cluster_cpu_cnt = prettyPrintData($local_cluster->summary->totalCpu,'MHZ');
    my $cluster_mem_cnt = prettyPrintData($local_cluster->summary->totalMemory,'B');
    my $cluster_avail_cpu = prettyPrintData($local_cluster->summary->effectiveCpu,'MHZ');
    my $cluster_avail_mem = prettyPrintData($local_cluster->summary->effectiveMemory,'M');
    my $cluster_drs = $local_cluster->configuration->drsConfig->enabled;
    my $cluster_ha = $local_cluster->configuration->dasConfig->enabled;
    my $cluster_dpm = $local_cluster->configurationEx->dpmConfigInfo->enabled;
    my $cluster_vm_mon = $local_cluster->configuration->dasConfig->vmMonitoring;
    my $cluster_host_mon = $local_cluster->configuration->dasConfig->hostMonitoring;
    my $vmotions = $local_cluster->summary->numVmotions;
    my ($mem_perc_string,$cpu_perc_string,$evc) = ("","","DISABLED");
    my $curr_bal = ($local_cluster->summary->currentBalance ? ($local_cluster->summary->currentBalance/1000) : "N/A");
    my $tar_bal = ($local_cluster->summary->targetBalance ? ($local_cluster->summary->targetBalance/1000) : "N/A");

    if($local_cluster->summary->currentEVCModeKey) {
    $evc = $local_cluster->summary->currentEVCModeKey;      }

     

         ###########################        
    1. CLUSTER SUMMARY
            ###########################

     

         push @cluster_jump_tags,"CLCluster: $cluster_name
    \n";

    my $cluster_start .= "\n";      $cluster_start .= "h2. Cluster: $cluster_name \n";      my ($hostTag,$hostTagShort) = ("","");

     

         ###########################        
    1. SUMMARY
            ###########################         if($CLUSTER_SUMMARY eq "yes") {           $hostTag = "Cluster Summary-$cluster_name";           $hostTagShort = "Cluster Summary";           push @cluster_jump_tags,"            $hostTagShort
    \n";

    $cluster_start .= "\n";
    $cluster_start .= "h3. Cluster Summary:
    \n";
    $cluster_start .= "\n";
    $cluster_start .= "\n";

    $cluster_start .= "";
    if($cluster_health eq 'gray' ) { $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "\n
    CLUSTER HEALTHAVAILABLE HOST(s)CURRENT BALANCETARGET BALANCEAVAILABLE CPUAVAILABLE MEMDRS ENABLEDHA ENABLEDDPM ENABLEDEVC ENABLED# OF vMOTIONS
    UNKNOWN"; }
    if($cluster_health eq 'green' ) { $cluster_start .= "
    CLUSTER OK"; }
    if($cluster_health eq 'red' ) { $cluster_start .= "
    CLUSTER HAS PROBLEM"; }
    if($cluster_health eq 'yellow' ) { $cluster_start .= "
    CLUSTER MIGHT HAVE PROBLEM"; }
    $cluster_start .= "
    ".$cluster_avail_host."/".$cluster_host_cnt."".$curr_bal."".$tar_bal."".$cluster_avail_cpu."".$cluster_avail_mem."".(($cluster_drs) ? "YES" : "NO")."".(($cluster_ha) ? "YES" : "NO")."".(($cluster_dpm) ? "YES" : "NO")."".$evc."".$vmotions."
    \n";      }

     

         ###########################      
    1. CLUSTER PERFORMANCE
         ###########################      if($CLUSTER_PERFORMANCE eq "yes" || $clusterperformance eq "yes") {           my $clusterPerfString = &getCpuAndMemPerf($local_cluster);           $cluster_start .= $clusterPerfString;      }

     

         ###########################        
    1. PRINT HA INFO
            ###########################      if($cluster_ha && $CLUSTER_HA eq "yes") {           $hostTag = "HA Configurations-$cluster_name";                 $hostTagShort = "HA Configurations";

     

                    push @cluster_jump_tags,"            $hostTagShort
    \n";

    $cluster_start .= "\n";
    $cluster_start .= "h3. HA Configurations
    \n";
    $cluster_start .= "\n";
    $cluster_start .= "\n";

    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "\n";

    my $haAdvInfo;
    eval { $haAdvInfo = $local_cluster->
    FAILOVER LEVELADMISSION CONTROLED ENABLEDISOLATION RESPONSERESTART PRIORITYVM MONITORINGHOST MONITORING
    ".($local_cluster->configuration->dasConfig->failoverLevel ? $local_cluster->configuration->dasConfig->failoverLevel : "N/A")."".(($local_cluster->configuration->dasConfig->admissionControlEnabled) ? "YES" : "NO")."".$local_cluster->configuration->dasConfig->defaultVmSettings->isolationResponse."".$local_cluster->configuration->dasConfig->defaultVmSettings->restartPriority."".$cluster_vm_mon."".$cluster_host_mon."
    RetrieveDasAdvancedRuntimeInfo(); };           if(!$@) {                
      1. HA ADV INFO ##
                   if($haAdvInfo) {                     $cluster_start .= "h3. HA Advanced Runtime Info \n";                     $cluster_start .= "\n";
    $cluster_start .= "\n";

    if($haAdvInfo->slotInfo) {
    $cluster_start .= "";
    } else {
    $cluster_start .= "";
    }
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "
    SLOT SIZETOTAL SLOTS IN CLUSTERUSED SLOTSAVAILABLE SLOTSTOTAL POWERED ON VMSTOTAL HOSTSTOTAL GOOD HOSTS
    ".($haAdvInfo->slotInfo->cpuMHz ? $haAdvInfo->slotInfo->cpuMHz : "N/A"). " MHz -- ".($haAdvInfo->slotInfo->numVcpus ? $haAdvInfo->slotInfo->numVcpus : "N/A"). " vCPUs -- ".($haAdvInfo->slotInfo->memoryMB ? $haAdvInfo->slotInfo->memoryMB : "N/A")." MBN/A".$haAdvInfo->totalSlots."".$haAdvInfo->usedSlots."".$haAdvInfo->unreservedSlots."".$haAdvInfo->totalVms."".$haAdvInfo->totalHosts."".$haAdvInfo->totalGoodHosts."
    \n";

     

                                             
      1. HA HOSTS INFO ##
                        if($haAdvInfo->dasHostInfo && $haAdvInfo->dasHostInfo->hostDasState) {                          $cluster_start .= "h3. HA Host Info \n";                                   $cluster_start .= "\n";
    $cluster_start .= "\n";

    my ($nodeStates,$primHosts,$secondHosts,$dasstring) = ("","","","");
    my %primary = ();

    $cluster_start .= "";
    if($haAdvInfo->dasHostInfo->primaryHosts) {
    my $dashosts = $haAdvInfo->dasHostInfo->primaryHosts;
    foreach my $dasHost (@$dashosts) {
    if($demo eq "yes") {
    $dasHost = $host_name;
    }
    $primHosts .= $dasHost."
    ";
    $primary{$dasHost} = "yes";
    }
    $cluster_start .= "";
    }

    if($haAdvInfo->dasHostInfo->hostDasState) {
    $dasstring .= "
    HA PRIMARY HOSTSHA SECONDARY HOSTSNODE STATES
    ".$primHosts."";
    my $dasstates = $haAdvInfo->dasHostInfo->hostDasState;
    foreach(@$dasstates) {
    my $dasHost;
    if($demo eq "yes") {
    $dasHost = $host_name;
    } else {
    $dasHost = $_->name;
    }
    $dasstring .= "\n";
    if(!$primary{$dasHost}) {
    $secondHosts .= $dasHost."
    ";
    }
    }

    $cluster_start .= "";
    $cluster_start .= $dasstring;
    $cluster_start .= "";
    }
    $cluster_start .= "";

    $cluster_start .= "
    NODECONFIG STATERUN STATE
    ".$dasHost."".$_->configState."".$_->runtimeState."
    ".$secondHosts."
    \n";                          %primary = ();                                 }

     

                        
      1. HA ADV OPTIONS ##
                        if($local_cluster->configurationEx->dasConfig->option) {                          $cluster_start .= "h3. HA Advanced Configurations \n";                                   $cluster_start .= "\n";
    $cluster_start .= "\n";

    my $haadv_string = "";

    my $advHAOptions = $local_cluster->configurationEx->dasConfig->option;
    foreach(@$advHAOptions) {
    $haadv_string .= "\n";
    }
    $cluster_start .= $haadv_string;
    $cluster_start .= "
    ATTRIBUTEVALUE
    ".$_->key."".$_->value."
    \n";                     }                }           }

     

         }

     

         ###########################        
    1. PRINT DRS INFO
            ###########################         if($cluster_drs && $CLUSTER_DRS eq "yes") {           $hostTag = "DRS Configurations-$cluster_name";                 $hostTagShort = "DRS Configurations";

     

                    push @cluster_jump_tags,"            $hostTagShort
    \n";

    $cluster_start .= "\n";
    $cluster_start .= "h3. DRS Configurations
    \n";
    $cluster_start .= "\n";
    $cluster_start .= "\n";

    $cluster_start .= "";
    $cluster_start .= "";
    $cluster_start .= "
    DRS BEHAVIORVMOTION RATE
    ".$local_cluster->configuration->drsConfig->defaultVmBehavior->val."".$local_cluster->configuration->drsConfig->vmotionRate."
    \n";

     

              
      1. DRS ADV OPTIONS ##
                      if($local_cluster->configurationEx->drsConfig->option) {                             $cluster_start .= "h3. DRS Advanced Configurations \n";                             $cluster_start .= "\n";
    $cluster_start .= "\n";

    my $drsadv_string = "";

    my $advHAOptions = $local_cluster->configurationEx->drsConfig->option;
    foreach(@$advHAOptions) {
    $drsadv_string .= "\n";
    }
    $cluster_start .= $drsadv_string;
    $cluster_start .= "
    ATTRIBUTEVALUE
    ".$_->key."".$_->value."
    \n";                 }      }

     

         ###########################        
    1. PRINT DPM INFO
            ###########################         if($cluster_dpm && $CLUSTER_DPM eq "yes") {           $hostTag = "DPM Configurations-$cluster_name";                 $hostTagShort = "DPM Configurations";

     

                    push @cluster_jump_tags,"            $hostTagShort
    \n";

    $cluster_start .= "\n";
    $cluster_start .= "h3. DPM Configurations
    \n";
    $cluster_start .= "\n";
    $cluster_start .= "\n";

    $cluster_start .= "";
    $cluster_start .= "
    DPM BEHAVIOR
    ".$local_cluster->configurationEx->dpmConfigInfo->defaultDpmBehavior->val."
    \n";      }

     

         ###########################      
    1. AFFINITY RULES
         ###########################      if($CLUSTER_AFFINITY eq "yes") {           my $rules = $local_cluster->configurationEx->rule;           if($rules) {                $hostTag = "Affinity Rules-$cluster_name";                      $hostTagShort = "Affinity Rules";

     

                         push @cluster_jump_tags,"            $hostTagShort
    \n";

    $cluster_start .= "\n";
    $cluster_start .= "h3. Affinity Rules:
    \n";
    $cluster_start .= "\n";
    $cluster_start .= "\n";

    foreach(sort {$a->name cmp $b->name} @$rules) {
    my $rule = $_;
    my $is_enabled = $rule->enabled;
    my $rule_name = $rule->name;
    my $rule_type;
    if(ref($rule) eq 'ClusterAffinityRuleSpec') {
    $rule_type = "AFFINITY";
    }
    elsif (ref($rule) eq 'ClusterAntiAffinityRuleSpec') {
    $rule_type = "ANTI-AFFINITY";
    }
    my $listOfVMs = Vim::get_views(mo_ref_array => $_->vm, properties => );
    my $listOfVmsString = "";
    foreach(@$listOfVMs) {
    $listOfVmsString .= $_->{'name'}."
    ";
    }
    $cluster_start .= "\n";
    }
    $cluster_start .= "
    RULE NAMERULE TYPEENABLEDVM(s)
    ".$rule_name."".$rule_type."".(($is_enabled) ? "YES" : "NO")."".$listOfVmsString."
    \n";           }      }

     

         ###########################      
    1. RESOURCE POOLS
         ###########################      my ($resource_pool_string,$vapp_string) = ("","");

     

         if($CLUSTER_VAPP eq "yes" || $CLUSTER_RP eq "yes") {           my $root_rp = Vim::get_view (mo_ref => $local_cluster->resourcePool);           my $resourcePools = $root_rp->resourcePool;                           foreach(@$resourcePools) {                my $rp = Vim::get_view(mo_ref => $_);

     

                   if($rp->isa('VirtualApp')) {                           my $vapp_name = $rp->name;                              my $anno = ($rp->vAppConfig->annotation ? $rp->vAppConfig->annotation : "N/A");

     

                                 my $ec = $rp->vAppConfig->entityConfig;                              my $vm_vapp_string = "";                              foreach(@$ec) {                                         my $order = $_->startOrder;                                      my $tag = $_->tag;                                   $vm_vapp_string .= "\n";
    }
    $vapp_string .= "\n";
    $vapp_string .= "\n";
    $vapp_string .= $vm_vapp_string."\n";
    } else {
    my $rp_name = $rp->name;
    my $rp_status = $rp->summary->runtime->overallStatus->val;
    if($rp_status eq 'gray') { $rp_status = ""; }
    elsif($rp_status eq 'green') { $rp_status = ""; }
    elsif($rp_status eq 'red') { $rp_status = ""; }
    elsif($rp_status eq 'yellow') { $rp_status = ""; }
    my $rp_cpu_use = prettyPrintData($rp->summary->runtime->cpu->overallUsage,'MHZ');
    my $rp_cpu_max = prettyPrintData($rp->summary->runtime->cpu->maxUsage,'MHZ');
    my $rp_cpu_lim = prettyPrintData($rp->summary->config->cpuAllocation->limit,'MHZ');
    my $rp_cpu_rsv = prettyPrintData($rp->summary->config->cpuAllocation->reservation,'MHZ');
    my $rp_mem_use = prettyPrintData($rp->summary->runtime->memory->overallUsage,'B');
    my $rp_mem_max = prettyPrintData($rp->summary->runtime->memory->maxUsage,'B');
    my $rp_mem_lim = prettyPrintData($rp->summary->config->cpuAllocation->limit,'M');
    my $rp_mem_rsv = prettyPrintData($rp->summary->config->cpuAllocation->reservation,'M');
    my ($rp_cpu_shares,$rp_mem_shares) = ("N/A","N/A");
    if($rp->summary->config->cpuAllocation) {
    $rp_cpu_shares = ($rp->summary->config->cpuAllocation->shares->shares ? $rp->summary->config->cpuAllocation->shares->shares : "N/A");
    }
    if($rp->summary->config->memoryAllocation) {
    $rp_mem_shares = ($rp->summary->config->memoryAllocation->shares->shares ? $rp->summary->config->memoryAllocation->shares->shares : "N/A");
    }

    my $vmInRp = 0;
    if($rp->vm) {
    my $vmsInRp = Vim::get_views(mo_ref_array => $rp->vm, properties => );
    $vmInRp = scalar(@$vmsInRp);
    }

    my ($cpuUnitsPerVM,$memUnitsPerVM) = ("N/A","N/A");

    if($vmInRp != 0 && $rp_cpu_shares ne "N/A") {
    $cpuUnitsPerVM = floor($rp_cpu_shares/$vmInRp);
    }
    if($vmInRp != 0 && $rp_mem_shares ne "N/A") {
    $memUnitsPerVM = floor($rp_mem_shares/$vmInRp);
    }

    $resource_pool_string .= "";
    $resource_pool_string .= $rp_status;
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "";
    $resource_pool_string .= "\n";
    }
    }
    }

    if($CLUSTER_RP eq "yes") {
    if($resource_pool_string ne "") {
    $hostTag = "Resource Pool(s)-$cluster_name";
    $hostTagShort = "Resource Pool(s)";

    push @cluster_jump_tags,"            $hostTagShort
    \n";

    $cluster_start .= "\n";
    $cluster_start .= "h3. Resource Pool(s):
    \n";
    $cluster_start .= "\n";
    $cluster_start .= "\n";

    $cluster_start .= $resource_pool_string;
    $cluster_start .= "
    ".$tag."".$order."
    ".$vapp_name."
    VMSTART ORDER
    UNKNOWNGREENREDYELLOW
    ".$rp_name."".$vmInRp."".$rp_cpu_shares."".$cpuUnitsPerVM."".$rp_mem_shares."".$memUnitsPerVM."".$rp_cpu_lim."".$rp_cpu_rsv."".$rp_mem_lim."".$rp_mem_rsv."".$rp_cpu_use."".$rp_cpu_max."".$rp_mem_use."".$rp_mem_max."
    POOL NAMESTATUS# of VM(s)CPU SHARESCPU UNITS PER/VMMEM SHARESMEM UNITS PER/VMCPU LIMITCPU RESERVATIONMEM LIMITMEM RESERVATIONCPU USAGECPU MAXMEM USAGEMEM MAX
    \n";           }      }

     

         ###########################      
    1. VAPPS
         ###########################      if($CLUSTER_VAPP eq "yes") {           if($vapp_string ne "") {                $hostTag = "vApp(s)-$cluster_name";                         $hostTagShort = "vApp(s)";

     

                            push @cluster_jump_tags,"            $hostTagShort
    \n";

    $cluster_start .= "\n";
    $cluster_start .= "h3. vApp(s):
    \n";
    $cluster_start .= "\n";

    $cluster_start .= $vapp_string;
    $cluster_start .= "
    \n";
    }
    }

    #search datastore for delta files
    if($VM_DELTA eq "yes") {
    my $datastores = Vim::get_views(mo_ref_array => $local_cluster->datastore);
    foreach my $datastore (@$datastores) {
    my $dsbrowser = Vim::get_view(mo_ref => $datastore->browser);
    my $ds_path = "";
    my $file_query = FileQueryFlags->new(fileOwner => 0, fileSize => 1,fileType => 0,modification => 1);
    my $searchSpec = HostDatastoreBrowserSearchSpec->new(details => $file_query,matchPattern => );
    my $search_res = $dsbrowser->SearchDatastoreSubFolders(datastorePath => $ds_path,searchSpec => $searchSpec);
    if ($search_res) {
    foreach my $result (@$search_res) {
    my $files = $result->file;
    if($files) {
    foreach my $file (@$files) {
    if($file->path =~ /-delta.vmdk/ ) {
    my ($vm_snapshot_date,$vm_snapshot_time) = split('T',$file->modification);
    my $todays_date = giveMeDate('YMD');
    chomp($todays_date);
    my $diff = days_between($vm_snapshot_date, $todays_date);
    my $snap_time = $vm_snapshot_date." ".$vm_snapshot_time;
    my $size = &prettyPrintData($file->fileSize,'B');

    my $snap_color_string = "";
    $snap_color_string = "";
    if($diff > $SNAPSHOT_YELLOW_WARN) {
    if($diff > $SNAPSHOT_RED_WARN) {
    $snap_color_string .= "";
    }elsif($diff > $SNAPSHOT_ORANGE_WARN) {
    $snap_color_string .= "";
    }elsif($diff > $SNAPSHOT_YELLOW_WARN) {
    $snap_color_string .= "";
    }
    $snap_color_string .= "";
    push @vmdeltas,$snap_color_string;
    }
    }
    }
    }
    }
    }
    }
    }

    print REPORT_OUTPUT "
    ".$cluster_start;
    }

    sub processOptions {
    my ($type,$hostType,$conf) = @_;

    if(defined($conf)) {
    &processConf($conf);
    &setConf();
    }

    if($type eq 'host' && $hostType eq 'HostAgent') {
    $host_view = Vim::find_entity_views(view_type => 'HostSystem');
    unless($host_view) {
    Util::disconnect();
    die "ESX/ESXi host was not found\n";
    }
    }elsif($type eq 'cluster' && $hostType eq 'VirtualCenter') {
    $cluster_view = Vim::find_entity_view(view_type => 'ClusterComputeResource',filter => { name =>
    ".$result->folderPath."".$file->path."".$diff." days old".$diff." days old".$diff." days old".$size."".$snap_time."
    $clusterInput });           unless($cluster_view)      }elsif($type eq 'datacenter' && $hostType eq 'VirtualCenter') {           $datacenter_view = Vim::find_entity_view(view_type => 'Datacenter',filter => { name => $datacenterInput});           unless($datacenter_view)      }elsif($type eq 'vcenter' && $hostType eq 'VirtualCenter') {           $cluster_views = Vim::find_entity_views(view_type => 'ClusterComputeResource');           $datacenter_views = Vim::find_entity_views(view_type => 'Datacenter');      } }

     

    sub processConf {      my ($conf) = @_;            my @goodparams = qw( EMAIL_HOST EMAIL_DOMAIN EMAIL_TO EMAIL_FROM YELLOW_WARN ORANGE_WARN RED_WARN SNAPSHOT_YELLOW_WARN SNAPSHOT_ORANGE_WARN SNAPSHOT_RED_WARN SYSTEM_LICENSE SYSTEM_FEATURE SYSTEM_PERMISSION SYSTEM_SESSION SYSTEM_HOST_PROFILE SYSTEM_PLUGIN CLUSTER_SUMMARY CLUSTER_PERFORMANCE CLUSTER_HA CLUSTER_DRS CLUSTER_DPM CLUSTER_AFFINITY CLUSTER_RP CLUSTER_VAPP HOST_HARDWARE_CONFIGURATION HOST_MGMT HOST_STATE HOST_HEALTH HOST_PERFORMANCE HOST_NIC HOST_HBA HOST_CAPABILITY HOST_CONFIGURATION HOST_VMOTION HOST_GATEWAY HOST_ISCSI HOST_IPV6 HOST_FT HOST_SSL HOST_DNS HOST_UPTIME HOST_DIAGONISTIC HOST_SERVICE HOST_NTP HOST_VSWIF HOST_VMKERNEL HOST_VSWITCH HOST_SNMP HOST_FIREWALL HOST_POWER HOST_ADVOPT HOST_NUMA HOST_CDP HOST_LUN HOST_DATASTORE HOST_MULTIPATH HOST_PORTGROUP HOST_DVS HOST_LOG HOST_TASK VM_CONFIG VM_STATS VM_RESOURCE_ALLOCATION VM_PERFORMANCE VM_FT VM_THIN VM_DEVICE VM_STORAGE VM_NETWORK VM_SNAPSHOT VM_DELTA VM_CDROM VM_FLOPPY VM_RDM VM_NPIV VM_TOOL );

     

         open(CONFIG, "$conf") || die "Error: Couldn't open the $conf!";         while ( );         };         if(!$@) {                 my %uniqueInstances = ();                 foreach(@$metrics) {                         my $perfValues = $_->value;                         foreach(@$perfValues) {                                 my $object = $_->id->instance ? $_->id->instance : "TOTAL";                                 #if($object eq "TOTAL") {                                         my ($numOfCounters,$sumOfCounters,$res) = (0,0,0);                                         my $values = $_->value;                                         my $metricRef = $allCounterDefintions{$_->id->counterId};                                         my $unitString = $metricRef->unitInfo->label;                                         my $unitInfo = $metricRef->unitInfo->key;                                         my $groupInfo = $metricRef->groupInfo->key;                                         my $nameInfo = $metricRef->nameInfo->key;                                         my $rollupType = $metricRef->rollupType->val;                                         my $factor = 1;                                         if($unitInfo eq 'percent') { $factor = 100; }

     

                                            foreach(@$values) {                                                 #if($rollupType eq 'average') {                                                         $res = &average($_)/$factor;                                                         $res = &restrict_num_decimal_digits($res,3);                                                 #}                                         }                                         my $internalID = $groupInfo . "." . $nameInfo . "." . $rollupType;                                         $metricResults{$internalID} = $res . "\t" . $unitString . "\n";                                 #}                         }                 }         }

     

            my ($cpuAvg,$cpuAvgPer,$memAvg,$memAvgPer,$ballonAvg,$readyAvg) = (0,0,0,0,0,0);

     

            for my $key ( sort keys %metricResults ) {                 if($key eq 'cpu.usage.average') {                         $cpuAvgPer = $metricResults{$key};                 }elsif($key eq 'cpu.usagemhz.average') {                         $cpuAvg = $metricResults{$key};                 }elsif($key eq 'mem.usage.average' || $key eq 'mem.consumed.average') {                if($entity_view->isa('ClusterComputeResource') && $key eq 'mem.consumed.average') {                              $memAvgPer = $metricResults{$key};                }elsif(!$entity_view->isa('ClusterComputeResource') && $key eq 'mem.usage.average'){                     $memAvgPer = $metricResults{$key};                }                 }elsif($key eq 'mem.active.average') {                         $memAvg = $metricResults{$key};                 }elsif($key eq 'cpu.ready.summation') {                         $readyAvg = $metricResults{$key};                 }elsif($key eq 'cpu.vmmemctl.average') {                         $ballonAvg = $metricResults{$key};                 }         }

     

         my ($perfString,$hostTag,$hostTagShort) = ("","","");

     

         if($entity_view->isa('ClusterComputeResource')) {              $perfString .= "h3. Cluster Performance \n";              $perfString .= "\n";
    $perfString .= "\n";

    #my $clusterTotalMemory = &prettyPrintData($entity_view->summary->
    cpu.usagemhz.averagecpu.usage.averagemem.active.averagemem.consumed.average
    effectiveMemory,'M');           #my $clusterConsumedMemory = &prettyPrintData($memAvgPer,'K');

     

              #$clusterTotalMemory =~ s/[a-zA-z]*//g;           #$clusterConsumedMemory =~ s/[a-zA-z]*//g;           #$clusterTotalMemory *= 1024;           #$clusterTotalMemory /= 1024;

     

              #my $clusterMemoryAvg = 0;           #if($memAvgPer != 0 && $clusterTotalMemory != 0) {           #     print $clusterConsumedMemory . "\n";           #     print $clusterTotalMemory . "\n\n";           
    1.      $clusterMemoryAvg = ($clusterConsumedMemory/$clusterTotalMemory)*100;
              #}

     

                        $perfString .= "\n";
    $perfString .= "\n";
    $perfString .= "\n";
    $perfString .= "\n";
    $perfString .= "\n";
    } elsif($entity_view->isa('HostSystem')) {
    my $hostsystem_name = $entity_view->name;
    if($demo eq "yes") { $hostsystem_name = $host_name; }
    $perfString .= "\n";
    } else {
    $perfString .= "
    " . $cpuAvg . "" . $cpuAvgPer . "" . $memAvg . "" . $memAvgPer . "
    " . $hostsystem_name . "" . $cpuAvg . "" . $cpuAvgPer . "" . $memAvg . "" . $memAvgPer . "
    " . $entity_view->name . "" . $cpuAvg . "" . $cpuAvgPer . "" . $readyAvg . "" . $memAvg . "" . $memAvgPer . "" . $ballonAvg . "
    \n";         }      return $perfString; }

     

    #VMware's viperformance.pl function sub get_available_intervals {    my %args = @_;    my $perfmgr_view = $args{perfmgr_view};    my $entity = $args;

     

       my $historical_intervals = $perfmgr_view->historicalInterval;    my $provider_summary = $perfmgr_view->QueryPerfProviderSummary(entity => $entity);    my @intervals;    if ($provider_summary->refreshRate) {       if($provider_summary->refreshRate != -1) {         push @intervals, $provider_summary->refreshRate;       }    }    foreach (@$historical_intervals) {       if($_->samplingPeriod != -1) {         push @intervals, $_->samplingPeriod;       }    }    return \@intervals; }

     

    sub average {    my @arr = @_;    my $n = 0;    my $avg = 0;

     

       foreach(@arr) {         $avg += $_;         $n += 1;    }    return $avg ? $avg/$n : 0; }

     

    sub FindPortGroupbyKey {    my ($network, $vSwitch, $key) = @_;    my $portGroups = $network->networkInfo->portgroup;    foreach my $pg (@$portGroups) {       return $pg if (($pg->vswitch eq $vSwitch) && ($key eq $pg->key));    }    return undef; }

     

    sub find_by_key {    my ($list, $key) = @_;

     

       foreach my $item (@$list) {       if ($key eq $item->key) {          return $item;       }    }

     

       return undef; }

     

    sub get_pci_string {    my $hba = shift;    my $pciString = defined($hba) ? $hba->pci : "";   
    1. defect 173631
       if ($pciString =~ /(+):(+)\.(+)$/) {       $pciString = hexstr_to_int($1)                    . ":" . hexstr_to_int($2)                    . "." . hexstr_to_int($3);    }    return $pciString }

     

    sub hexstr_to_int {     my ($hexstr) = @_;     die "Invalid hex string: $hexstr"     if $hexstr !~ /^[0-9A-Fa-f]{1,8}$/;     my $num = hex($hexstr);     return $num >> 31 ? $num - 2 ** 32 : $num; }

     

    sub getSnapshotTree {      my ($host,$vm,$ref,$tree) = @_;

     

         my $head = " ";      foreach my $node (@$tree) {           $head = ($ref->value eq $node->snapshot->value) ? " " : " " if (defined $ref);           my $quiesced = ($node->quiesced) ? "YES" : "NO";                 my $desc = $node->description;           if($desc eq "" ) { $desc = "NO DESCRIPTION"; }           push @vmsnapshots,"";

    &getSnapshotTree($host, $vm, $ref, $node->childSnapshotList);
    }
    return;
    }

    sub startReport {
    print "Generating VMware vSphere Health Report $version \"$report\" ...\n\n";
    print "This can take a few minutes depending on environment size. \nGet a cup of coffee/tea and check out http://www.engineering.ucsb.edu/~duonglt/vmware/\n\n";

    if($demo eq "yes") {
    $host_name = "DEMO-HOST.primp-industries.com";
    }


    $start_time = time();
    open(REPORT_OUTPUT, ">$report");

    $my_time = "Date: ".giveMeDate('MDYHMS');
    my $html_start = <<HTML_START;
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





    ".$host."".$vm."".$node->name."".$desc."".$node->createTime."".$node->state->val."".$quiesced."
    <!-- body a:link a:visited a:hover a:active th { font-weight:bold; background-color:#CCCCCC; } h1 {      font-size: 3em;      margin: 20px 0;      color: white; } div.tabcontainer ul.tabnav {      list-style-type: none;      margin: 0;      padding: 0;      width: 100%;      overflow: hidden;      border-top: none;      clear: both;      float: left;      width: 100%;      -moz-border-radius-bottomright: 5px;      -khtml-border-radius-bottomright: 5px;      -webkit-border-bottom-right-radius: 5px;      -moz-border-radius-bottomleft: 5px;      -khtml-border-radius-bottomleft: 5px;      -webkit-border-bottom-left-radius: 5px; }

     

    ul.tabnav li ul.tabnav li a {      text-decoration: none;      color: #000;      display: block;      font-size: 1.2em;      padding: 0 20px;      border: 1px solid #fff;      outline: none; }

     

    ul.tabnav a:hover

     

    div.tabcontents { HTML_START

     

    if($printerfriendly eq "no") {      $html_start .= <<HTML_START;         height: 550px; HTML_START }

     

    $html_start .= <<HTML_START;      background: #fff;      overflow: hidden;      border-top: 1px solid #011;      padding: 20px;      padding-bottom:30px; }

     

    div.tabcontents div.content

     

    div.tabcontents div.content h2 {      margin-top: 3px;      font-weight: normal;      padding-bottom: 10px;      border-bottom: 1px dashed #ddd;      font-size: 1.8em; } .author {      font-weight: bold;     font-size: small;      clear: both;     display: block;     padding: 10px 0;     text-align:center;     color:white; } //-->

    visibleDiv = "";
    function showHide(elementid,qstring){
    if (document.getElementById(elementid).style.display == 'none'){
    document.getElementById(elementid).style.display = '';
    if(visibleDiv != ""){
    if(visibleDiv != elementid){
    document.getElementById(visibleDiv).style.display = 'none';
    }
    }
    visibleDiv = elementid;
    } else {
    document.getElementById(elementid).style.display = 'none';
    }
    }




    HTML_START

    print REPORT_OUTPUT $html_start;
    }

    sub endReport {
    my $html_end = <<HTML_END;
    http://engineering.ucsb.edu/~duonglt/vmware

    Generated using: vmwarevSphereHealthCheck.pl

    ™Primp Industries

    HTML_END

    print REPORT_OUTPUT $html_end;
    close(REPORT_OUTPUT);

    my @lines;
    my ($cluster_jump_string,$host_jump_string,$vm_jump_string) = ("","","");
    tie @lines, 'Tie::File', $report or die;
    for(@lines) {
    if (//) {
    foreach (@cluster_jump_tags) {
    if( ($_ =~ /^CL/) ) {
    my $tmp_cluster_string = substr($_,2);
    $cluster_jump_string .= $tmp_cluster_string;
    }
    else {
    $cluster_jump_string .= $_;
    }
    }
    $_ = "\n$cluster_jump_string";
    last;
    }
    }
    for(@lines) {
    if (//) {
    foreach (@host_jump_tags) {
    if( ($_ =~ /^CL/) ) {
    my $tmp_host_string = substr($_,2);
    $host_jump_string .= $tmp_host_string;
    }
    else {
    $host_jump_string .= $_;
    }
    }
    $_ = "\n$host_jump_string";
    last;
    }
    }
    for(@lines) {
    if (//) {
    foreach (@vm_jump_tags) {
    if( ($_ =~ /^CL/) ) {
    my $tmp_host_string = substr($_,2);
    $vm_jump_string .= $tmp_host_string;
    }
    else {
    $vm_jump_string .= $_;
    }
    }
    $_ = "\n$vm_jump_string";
    last;
    }
    }

    untie @lines;


    my $end_time = time();
    my $run_time = $end_time - $start_time;
    print "\nStart Time: ",&formatTime(str => scalar localtime($start_time)),"\n";
    print "End Time: ",&formatTime(str => scalar localtime($end_time)),"\n";

    if ($run_time < 60) {
    print "Duration : ",$run_time," Seconds\n\n";
    }
    else {
    print "Duration : ",&restrict_num_decimal_digits($run_time/60,2)," Minutes\n\n";
    }
    }

    sub startBody {
    my ($type) = @_;

    my $body_start = <<BODY_START;



         

    VMware vSphere Health Check Report $version

     

         
      • [System Summary | #tab1]

      • BODY_START

        if($type eq 'VirtualCenter') {
        $body_start .= <<BODY_START;
      • [Cluster | #tab2]

      • BODY_START
        }
        $body_start .= <<BODY_START;
      • [Host | #tab3]

      • [Virtual Machines | #tab4]



    BODY_START

    print REPORT_OUTPUT $body_start;
    }

    sub endBody {
    my $body_end = <<BODY_END;



    BODY_END

     

         print REPORT_OUTPUT $body_end; }

     

    sub validateSystem {      my ($ver) = @_;

     

         if(!grep(/$ver/,@supportedVersion)) {           Util::disconnect();           print "Error: This script only supports vSphere ".@supportedVersion." or greater!\n\n";           exit 1;      }
    1. restrict the number of digits after the decimal point
    }

     

    #http://guymal.com/mycode/perl_restrict_digits.shtml sub restrict_num_decimal_digits {         my $num=shift;#the number to work on         my $digs_to_cut=shift;# the number of digits after

     

            if ($num=~/\d+\.(\d){$digs_to_cut,}/) {                 $num=sprintf("%.".($digs_to_cut-1)."f", $num);         }         return $num; }

     

    #http://www.infocopter.com/perl/format-time.html sub formatTime(%) {         my %args = @_;         $args{'str'} ||= ''; # e.g. Mon Jul 3 12:59:28 2006

     

            my @elems = ();         foreach (split / /, $args{'str'}) {                 next unless $_;                 push(@elems, $_);         }

     

            my ($weekday, $month, $mday, $time, $yyyy) = split / /, join(' ', @elems);

     

            my %months = (  Jan => 1, Feb => 2, Mar => 3, Apr =>  4, May =>  5, Jun =>  6,                         Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, Dec => 12 );

     

            my $s  = substr($time, 6,2);         my $m  = substr($time, 3,2);         my $h  = substr($time, 0, 2);         my $dd = sprintf('%02d', $mday);

     

            my $mm_num = sprintf('%02d', $months{$month});

     

            my $formatted = "$mm_num\-$dd\-$yyyy $h:$m:$s";         #my $formatted = "$yyyy$mm_num$dd$h$m$s";

     

            $formatted; }

     

    #http://www.bryantmcgill.com/Shazam_Perl_Module/Subroutines/utils_convert_bytes_to_optimal_unit.html sub prettyPrintData{         my($bytes,$type) = @_;

     

            return '' if ($bytes eq '' || $type eq '');         return 0 if ($bytes <= 0);

    my($size);

    if($type eq 'B') {
    $size = $bytes . ' Bytes' if ($bytes < 1024);
    $size = sprintf("%.2f", ($bytes/1024)) . ' KB' if ($bytes >= 1024 && $bytes < 1048576);
    $size = sprintf("%.2f", ($bytes/1048576)) . ' MB' if ($bytes >= 1048576 && $bytes < 1073741824);
    $size = sprintf("%.2f", ($bytes/1073741824)) . ' GB' if ($bytes >= 1073741824 && $bytes < 1099511627776);
    $size = sprintf("%.2f", ($bytes/1099511627776)) . ' TB' if ($bytes >= 1099511627776);
    }
    elsif($type eq 'K') {
    $bytes = $bytes * (1024);
    $size = sprintf("%.2f", ($bytes/1048576)) . ' MB' if ($bytes >= 1048576 && $bytes < 1073741824);
    $size = sprintf("%.2f", ($bytes/1073741824)) . ' GB' if ($bytes >= 1073741824 && $bytes < 1099511627776);
    $size = sprintf("%.2f", ($bytes/1099511627776)) . ' TB' if ($bytes >= 1099511627776);
    }
    elsif($type eq 'M') {
    $bytes = $bytes * (1048576);
    $size = sprintf("%.2f", ($bytes/1048576)) . ' MB' if ($bytes >= 1048576 && $bytes < 1073741824);
    $size = sprintf("%.2f", ($bytes/1073741824)) . ' GB' if ($bytes >= 1073741824 && $bytes < 1099511627776);
    $size = sprintf("%.2f", ($bytes/1099511627776)) . ' TB' if ($bytes >= 1099511627776);
    }

    elsif($type eq 'G') {
    $bytes = $bytes * (1073741824);
    $size = sprintf("%.2f", ($bytes/1073741824)) . ' GB' if ($bytes >= 1073741824 && $bytes < 1099511627776);
    $size = sprintf("%.2f", ($bytes/1099511627776)) . ' TB' if ($bytes >= 1099511627776);
    }
    elsif($type eq 'MHZ') {
    $size = sprintf("%.2f", ($bytes/1e-06)) . ' MHz' if ($bytes >= 1e-06 && $bytes < 0.001);
    $size = sprintf("%.2f", ($bytes*0.001)) . ' GHz' if ($bytes >= 0.001);
    }

    return $size;
    }

    sub getColor {
    my ($val) = @_;
    my $color_string = "";
    if($val < $RED_WARN) { $color_string = ""; }
    elsif($val < $ORANGE_WARN) { $color_string = ""; }
    elsif($val < $YELLOW_WARN) { $color_string = ""; }
    else { $color_string = "
    ".$val." %".$val." %".$val." %".$val." %
    "; }

     

            return $color_string;
    1. http://andrewcantino.com/class/l2.html
    }

     

    sub power {      my ($i,$t);      my ($n, $p) = @_;      $t = $n;      for(my $i = 1; $i < $p; $i++) {           $t = $t * $n;      }      return $t; }

     

    #http://www.perlmonks.org/?node_id=17057 sub days_between {      my ($start, $end) = @_;      my ($y1, $m1, $d1) = split ("-", $start);      my ($y2, $m2, $d2) = split ("-", $end);      my $diff = mktime(0,0,0, $d2-1, $m2-1, $y2 - 1900) -  mktime(0,0,0, $d1-1, $m1-1, $y1 - 1900);      return $diff / (606024); }

     

    sub giveMeDate {         my ($date_format) = @_;         my %dttime = ();         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
        1. begin_: initialize DateTime number formats

     

                    $dttime{year }  = sprintf "%04d",($year + 1900);  ## four digits to specify the year         $dttime  = sprintf "%02d",($mon + 1);      ## zeropad months         $dttime  = sprintf "%02d",$mday;           ## zeropad day of the month         $dttime  = sprintf "%02d",$wday + 1;       ## zeropad day of week; sunday = 1;         $dttime  = sprintf "%02d",$yday;           ## zeropad nth day of the year         $dttime  = sprintf "%02d",$hour;           ## zeropad hour         $dttime  = sprintf "%02d",$min;            ## zeropad minutes         $dttime  = sprintf "%02d",$sec;            ## zeropad seconds         $dttime  = $isdst;         if($date_format eq 'MDYHMS') {                 $my_time = "$dttime-$dttime-$dttime $dttime:$dttime:$dttime";         }         elsif ($date_format eq 'YMD') {                 $my_time = "$dttime-$dttime-$dttime";         }         return $my_time; }