Home Datacenter Investigating and setting syslog settings for ESXi with #PowerCLI

Investigating and setting syslog settings for ESXi with #PowerCLI

by Philip Sellers

Persistent logs in ESXi are useful in all troubleshooting situations.  Earlier this week, I posted about vRealize Log Insight and as part of the quick-start of that product, it can set remote syslog settings on an ESXi host.  What should you do if you want to set your own settings – to a third party syslog or another product – or set persistent logging to a shared VMFS datastore?  PowerCLI can save your bacon for that.

First, you should know the advanced settings that you need to set and what they do.  In the next section, we cover those advanced settings, which are visible under the Configure tab and Advanced System Settings on any ESXi host in vCenter.  But PowerCLI can help you set these across all your hosts easily.

Syslog Advanced Settings

Syslog.global.logDir  – A location on a datastore where the logs can be saved to.  It uses format of “[datastore] path” for the setting.

Syslog.global.logDirUnique – a boolean option to create a host-specific directory under the logDir defined.  This is useful for sharing the same settings across multiple hosts.

Syslog.global.logHost – a comma separated list of remote servers where the logs are sent by syslog.  The format is protocol and host with port – tcp://hostname:514 or udp://hostname:514.

Checking Existing Settings with PowerCLI

Checking the logDir setting on all the hosts attached to your vCenter:

[code]Get-AdvancedSetting -Entity (Get-VMHost) -Name "Syslog.global.logDir" | Select Entity, Name, Value[/code]

Checking the logDirUnique setting on all the hosts attached to your vCenter:

[code]Get-AdvancedSetting -Entity (Get-VMHost) -Name "Syslog.global.logDirUnique" | Select Entity, Name, Value[/code]

Checking the logHost setting on all the hosts attached to your vCenter:

[code]Get-AdvancedSetting -Entity (Get-VMHost) -Name "Syslog.global.logHost" | Select Entity, Name, Value[/code]

Setting the Advanced Settings with PowerCLI

The Set-AdvancedSetting cmdlet utilizes an AdvancedSetting object to make a change, meaning you have to use Set-AdvancedSetting with Get-AdvancedSetting.  Reuse the first part of your code above in order to get the correct Advanced Setting from the host and then pipe it to Set-AdvancedSetting with your new value.

[code]Get-AdvancedSetting -Entity (Get-VMHost) -Name "Syslog.global.logDir" | Set-AdvancedSetting -Value "[VMFS_Name] /systemlogs[/code]

[code]Get-AdvancedSetting -Entity (Get-VMHost) -Name "Syslog.global.logDirUnique" | Set-AdvancedSetting -Value $True[/code]

[code]Get-AdvancedSetting -Entity (Get-VMHost) -Name "Syslog.global.logHost" | Set-AdvancedSetting -Value "udp://hostname:514"[/code]

You may also like