VMware Cloud Community
C4113
Contributor
Contributor
Jump to solution

Problem with New-AlarmTrigger and input for -EventType parameter

I'm trying to create a new Alarm using a certain event type ID as a trigger, since the 6.7 Html5-GUI for creating Alarms have made 99% of all guides relying on the Flash-GUI useless.

I need to create trigger based on the event ID "esx.problem.vmsyslogd.remote.failure", to do that i first define $EventType as a variable using Get-EventType and the try to run the New-AlarmTrigger using $EventType as input as follows:
$EventType = Get-EventType | Where Id -eq "esx.problem.vmsyslogd.remote.failure"
New-AlarmTrigger -EventType $EventType
And gets the error:
"New-AlarmTrigger : The parameter set cannot be resolved using the specified named parameters."
I only include one parameter in the command, since the lack of input parameters does not seem to be the problem.
The help page for New-EventTriggeronly has one example including the -EventType as input and there the variable apparently is defined already, the help page does not specify what format the variable should have .. or does it? The help page has the following text above the examples, which tells me absolutely nothing:

Return Type

VMware.VimAutomation.ViCore.Types.V1.Alarm.AlarmTrigger
When i follow the link it says at the top:

AlarmTrigger - Object

... which leads me to believe the variable should be a object.

To my very limited understanding of powershell, the output of the command: Get-EventType | Where Id -eq "esx.problem.vmsyslogd.remote.failure" should return a object, right?

I have passed "esx.problem.vmsyslogd.remote.failure" as a variable to EventType just as a test and and get complaints that the variable is a string ...

So if it wont accept either a string of a object, what format should the variable have? This is where my powershell knowledge hits a brick wall.

This could all be avoided of there was a simpler way to specify esx.problem.vmsyslogd.remote.failure as a trigger for a alarm, but alas VMware has removed that.

At the end, all i need is a alarm for when syslog stops working, to comply with DoD STIG for vCenter.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

This seems to work for me

$eventId = 'esx.problem.vmsyslogd.remote.failure'

$eventType = Get-EventType | where{$_.Id -match $eventId}

$root = Get-Folder -Name Datacenters


$trigger = New-AlarmTrigger -EventType $eventType -EntityType HostSystem -EntityStatus Red

New-AlarmDefinition -Name 'Remote syslog fail' -AlarmTrigger $trigger -Entity $root -Disabled


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

View solution in original post

7 Replies
LucD
Leadership
Leadership
Jump to solution

This seems to work for me

$eventId = 'esx.problem.vmsyslogd.remote.failure'

$eventType = Get-EventType | where{$_.Id -match $eventId}

$root = Get-Folder -Name Datacenters


$trigger = New-AlarmTrigger -EventType $eventType -EntityType HostSystem -EntityStatus Red

New-AlarmDefinition -Name 'Remote syslog fail' -AlarmTrigger $trigger -Entity $root -Disabled


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

C4113
Contributor
Contributor
Jump to solution

That solved the parameter problem indeed 😃

If even made my vCenter STIG compliance script pass!

I'm still not 100% sure why, but hey .. knowledge is a journey!

Thanx alot for the help, much appreciated!!

\\C

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The issue was that the Get-Event returns an object where the Id property contains 'EventType-EventEx;FullFormat-esx.problem.vmsyslogd.remote.failure'
With an -eq you do not find a match, that is why I used the -match operator.


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

0 Kudos
Slicster_SG
Contributor
Contributor
Jump to solution

Hi,

I'm having a different but somewhat similar issues.  I'm trying to create some alarms but I cannot find the EventType for them.  Existing Alarm - "Datastore usage on disk" doesn't show up in the Event Types.  If I run the following, I don't see it:

 

Get-EventType | where description -like "*datastore*"

 

Any ideas?  Because without that, I'm unable to use the new POWERCLI commands such as New-AlarmTrigger.

 

Thanks.

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That alarm is not based on an Event but on a Metric.
You can see this with

Get-AlarmDefinition -Name 'Datastore usage on disk' | Get-AlarmTrigger


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

0 Kudos
Slicster_SG
Contributor
Contributor
Jump to solution

Hey LucD,
I've read a ton of your posts and you've helped me a lot in recent years so thanks for that!

We're trying to do something similar to in this post:
https://blogs.vmware.com/PowerCLI/2019/11/new-vsphere-alarm-management.html

So we can have a script with all our own alarms defined to apply on multiple vCenters.  We want to avoid creating an export/import so we don't have to manage all the alarms on a vCenter but rather just have a static script we can modify thresholds or add new alarms.

The part that is not working is:

$vmReconfigEvt = Get-EventType | Where-Object {$_.Description -eq "VM reconfigured"}
 
$alarmTriggerInput = @{
    EventType = $vmReconfigEvt
    EntityStatus = "Yellow"
    EntityType = "VirtualMachine"
}
$alarmTrigger = New-AlarmTrigger @alarmTriggerInput
 
$alarmDefInput = @{
    Name = "VM Reconfiguration"
    Description = "Alarm to monitor virtual machine reconfiguration events"
    AlarmTrigger = $alarmTrigger
    Entity = Get-Folder -Type Datacenter -NoRecursion
}
New-AlarmDefinition @alarmDefInput

 

And I don't know how I would work around the above using:

Get-AlarmDefinition -Name 'Datastore usage on disk' | Get-AlarmTrigger

 

Hope that makes sense

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You define a Trigger, but instead of an Event you use a Metric.
Something like this

$metric = Get-Metric -Name 'Space actually used'
$trigger = New-AlarmTrigger -Metric $metric -MetricAlarmOperator Above -Yellow 5000 -Red 7500 -EntityType Datastore

$root = Get-Folder -Name Datacenters
New-AlarmDefinition -Name 'New alarm' -Disabled -AlarmTrigger $trigger -Entity $root


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

0 Kudos