Automation

 View Only
  • 1.  Format logfiles

    Posted Aug 25, 2009 07:13 AM

    I would send me the vmkwarning logs per email:

    foreach ($vmhost in get-cluster cluster04 | get-vmhost){
     $log = get-log -key vmkwarning $vmhost
     $mailBody = $mailBody`
     + $log.entries
    }
    $mailBody
    

    But then the log entries are all on one line. How could I format this nicer?

    Thanks, Daniel



  • 2.  RE: Format logfiles

    Posted Aug 25, 2009 09:25 AM

    Get-Log for all VMHosts

    $mailbody = Get-VMHost | Get-Log -Key vmkwarning | % { $_.Entries }

    Get-Log for all VMHosts in Cluster

    $mailbody = Get-Cluster <clustername> | Get-VMHost | Get-Log -Key vmkwarning | % { $_.Entries }



  • 3.  RE: Format logfiles

    Posted Aug 25, 2009 10:05 AM

    Thanks, this is a lot easier way. But the result is the same. If I generate a mail with the variable $mailbody as mailtext I loose the newlines.

    Is there a way to remain them?



  • 4.  RE: Format logfiles
    Best Answer

    Posted Aug 25, 2009 11:00 AM

    Try this

    $mailbody = @()
    foreach ($vmhost in get-cluster | get-vmhost){
    	$log = get-log -key vmkernel $vmhost
    	$log.Entries | %{
    		$mailbody += ("`r`n" + $_)
    	}
    }
    
    # Send report via email
    $SmtpClient = New-Object system.net.mail.smtpClient
    $MailMessage = New-Object system.net.mail.mailmessage
    $SmtpClient.host = <smtp-server>
    $MailMessage.from = <from-address>
    $MailMessage.To.add(<to-address>)
    $MailMessage.Subject = "logs"
    $MailMessage.body = $mailBody
    $SmtpClient.Send($MailMessage)
    



  • 5.  RE: Format logfiles

    Posted Aug 25, 2009 11:57 AM

    Thank you, this one works as expected.

    I modified it a bit:

    $mailbody = @()
    foreach ($vmhost in get-cluster | get-vmhost | sort-object){
    	$log = get-log -key vmkwarning $vmhost
    	if ($log.Entries -ne "") {
    		$mailbody += ("`r`n" + $vmhost + ":")
    	}
    	$log.Entries | %{
    		$mailbody += ("`r`n" + $_)
    	}
    }
    ...
    



  • 6.  RE: Format logfiles

    Posted Aug 25, 2009 12:02 PM

    Hit Correct Answer for LucD --so others know its been answered



  • 7.  RE: Format logfiles

    Posted Aug 25, 2009 12:05 PM

    I did this already!