VMware Cloud Community
mibiras
Contributor
Contributor

Log Filtering on ESXi Hosts

Hello,

I need configure for multiple esxi host this syslog filtering:

esxcli system syslog config logfilter set --log-filtering-enabled=true
esxcli system syslog config logfilter add -f "0 | Hostd | SetVigorNotificationTime: Not connected"
esxcli system syslog reload

Is it possible do via PowerCli ?

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

Yes, use the Get-EsxCli cmdlet, preferable with the V2 switch.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mibiras
Contributor
Contributor

Yes, I know about Get-EsxCLI, but I have problem to create $options1 and $options2 in script below

foreach ($VMHost in $VMHosts) {
$esxcli = Get-EsxCli -VMHost $VMHost -V2
$esxcli.system.syslog.config.logfilter.set.Invoke($options1)
$esxcli.system.syslog.config.logfilter.add.Invoke($options2)
$esxcli.system.syslog.reload
}
Reply
0 Kudos
LucD
Leadership
Leadership

The cmdlet has a CreateArgs method that will return an empty hash table with the parameters.
Also indicating which ones are required or optional.

$esxcli.system.syslog.config.logfilter.set.CreateArgs()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mibiras
Contributor
Contributor

I have read https://www.virten.net/2016/11/how-to-use-esxcli-v2-commands-in-powercli/, but it doesnt work for me:

 

 

PS C:\> $esxcli.system.syslog.config.logfilter.set.CreateArgs()

Name Value
---- -----
logfilteringenabled Unset, ([boolean])


PS C:\> $arguments.logfilteringenabled = 'true'
The property 'logfilteringenabled' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $arguments.logfilteringenabled = 'true'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Reply
0 Kudos
LucD
Leadership
Leadership

The CreateArgs method produces hash table, so you have to reference an entry with the Key.

$arguments = $esxcli.system.syslog.config.logfilter.set.CreateArgs()
$arguments['logfilteringenabled'] = $true
$esxcli.system.syslog.config.logfilter.set.Invoke($arguments)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mibiras
Contributor
Contributor

OK, it works with:

PS C:\> $arguments = $esxcli.system.syslog.config.logfilter.set.CreateArgs()
PS C:\> $arguments['logfilteringenabled'] = $true
PS C:\> $esxcli.system.syslog.config.logfilter.set.Invoke($arguments)
true
PS C:\> $arguments = $esxcli.system.syslog.config.logfilter.add.CreateArgs()
PS C:\> $arguments['filter'] = "0 | Hostd | SetVigorNotificationTime: Not connected"
PS C:\> $esxcli.system.syslog.config.logfilter.add.Invoke($arguments)
true

but should I also use:

$option1 = @{logfilteringenabled=$true}
$option2 = @{filter = "0 | Hostd | SetVigorNotificationTime: Not connected"}

$esxcli.system.syslog.config.logfilter.set.Invoke($option1)
$esxcli.system.syslog.config.logfilter.add.Invoke($option2)
Reply
0 Kudos
LucD
Leadership
Leadership

That is the same.
With the CreatArgs method the hash table is created for you.
With the other method like

@{filter = "0 | Hostd | SetVigorNotificationTime: Not connected"}

you create the hash table yourself.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mibiras
Contributor
Contributor

super, thanks for help

Reply
0 Kudos
JT_CPL
Contributor
Contributor

What is that error ? "VigorStatsProvider...   SetVigorNotificationTime: Not connected" ?   I see millions of these logs

Reply
0 Kudos