VMware Cloud Community
Twanoo
Contributor
Contributor
Jump to solution

Restore default Alarm / problem with 2 of them

Hello everybody!

I'm creating a script to restore vCenter Alarm on default state.

In fact, it's almost done as it work for 35 of them,

but I encounter issues with 2 of them that don't want to create.

you can find the current version of my script over here : http://ghostus.free.fr/Projet/PowerCLI/default-alarm.ps1

(I have commented the two alarm that don't work, so the rest of the code is working)

the part of the code that don't work is :

#Datastore usage on disk

nouv "or" "Datastore usage on disk" "Default alarm to monitor datastore disk usage"

metexpr 7500 0 8500 0 "Datastore" 147

$global:alarmMgr.CreateAlarm($entity.MoRef, $global:alarm)

and:

#Host connection and power state

nouv "and" "Host connection and power state" "Default alarm to monitor host connection and power state"

statexpr "isEqual" "notResponding" "runtime.connectionState" "HostSystem" ""

statexpr "isUnequal" "standBy" "runtime.powerState" "HostSystem" ""

$global:alarmMgr.CreateAlarm($entity.MoRef, $global:alarm)

but as it is using function of myself I don't except someone to see any error in-there,

nevertheless, I wonder if some of you guys as ever succeeded creating specially one of those 2 alarm using a script?

And if so, can you tell me, which type of expression/counter/event etc.. you used?

Any thoughts on that will be greatly appreciate =D

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I think I found the problem.

It's in the way the system expects the red and yellow conditions to be specified.

If you don't want to test for a specific condition you should leave as it came out of the constructor.

If you change your statexpr function like this it works.

function statexpr([string]$operator,[string]$red,[string]$path,[string]$type,[string]$yellow){
#Ajout d'un moniteur(expression) d'état(state) à une alarme
	$global:expr = New-Object VMware.Vim.StateAlarmExpression
	$global:expr.Operator = $operator
	if($red -ne ""){
		$global:expr.Red = $red
	}
	$global:expr.StatePath = $path
	$global:expr.Type = $type
	if($yellow -ne ""){
		$global:expr.Yellow = $yellow
	}
	$global:alarm.expression.expression += $global:expr
}

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
5 Replies
Twanoo
Contributor
Contributor
Jump to solution

PS : If it could be of any use, I joined you the "Powershell Plus"'s Variable Inspector view, of those two alarm on a virgin vcenter4u1.

http://ghostus.free.fr/Projet/PowerCLI/image/Host.png

http://ghostus.free.fr/Projet/PowerCLI/image/Datastore.png

0 Kudos
Twanoo
Contributor
Contributor
Jump to solution

One more clue :

Using a script from Lucd ( found here : http://www.lucd.info/2009/11/24/alarm-expressions-part-1-metric-alarms/ )

I generated a CSV file with the available metrics per entity type, and it seems that all Datastore metrics seems empty.

The csv begin with :

"Entity";"Interval";"CounterId";"Stat";"Instance";"Level";"Summary"

"Datastore";"Past day";;;;;

"Datastore";"Past week";;;;;

"Datastore";"Past month";;;;;

"Datastore";"Past year";;;;;

"Datastore";"RealTime";;;;;

"Datacenter";"Past day";;;;;

"Datacenter";"Past week";;;;;

"Datacenter";"Past month";;;;;

"Datacenter";"Past year";;;;;

"Datacenter";"RealTime";;;;;

"VirtualMachine";"Past day";"2";"cpu.usage.average";"";"1";"CPU usage as a percentage during the interval"

"VirtualMachine";"Past day";"6";"cpu.usagemhz.average";"";"1";"CPU usage, as measured in megahertz, during the interval"

"VirtualMachine";"Past day";"12";"cpu.ready.summation";"";"1";"Percentage of time that the virtual machine was ready, but could not get scheduled to run on the physical CPU"

"VirtualMachine";"Past day";"16";"mem.usage.average";"";"1";"Memory usage as percentage of total configured or available memory"

"VirtualMachine";"Past day";"77";"mem.swapinRate.average";"";"1";"Rate at which memory is swapped from disk into active memory during the interval"

......

And the case occurs in my vCenter test installation, and on a brand new vCenter4u1 installation.

So I think that's a general problem.

Can someone test to confirm that?

(and maybe someone with a vCenter 4u2, could tell us if it's fixed by the update2?)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid there is a bug in that script (which I will correct later today).

There are only performance counters for Datacenter, VirtualMachine, HostSystem, ClusterComputeResource and ResourcePool objects.

See also the Performance Counters section on the PerformanceManager page.

Sorry to have put you on the wrong track.

Btw I've been looking at the problem of these 2 alarms, and I think I might be onto something.

More later.

==> post has been updated

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think I found the problem.

It's in the way the system expects the red and yellow conditions to be specified.

If you don't want to test for a specific condition you should leave as it came out of the constructor.

If you change your statexpr function like this it works.

function statexpr([string]$operator,[string]$red,[string]$path,[string]$type,[string]$yellow){
#Ajout d'un moniteur(expression) d'état(state) à une alarme
	$global:expr = New-Object VMware.Vim.StateAlarmExpression
	$global:expr.Operator = $operator
	if($red -ne ""){
		$global:expr.Red = $red
	}
	$global:expr.StatePath = $path
	$global:expr.Type = $type
	if($yellow -ne ""){
		$global:expr.Yellow = $yellow
	}
	$global:alarm.expression.expression += $global:expr
}

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
Twanoo
Contributor
Contributor
Jump to solution

Once again Lucd, you found the thing Smiley Wink

the same thing with the metexpr function changed by :

function metexpr([int]$yellow,[int]$yellowint,[int]$red,[int]$redint,[string]$type,[int]$count){
	#Ajout d'un moniteur(expression) de performance(metric) à une alarme
	$global:expr = New-Object VMware.Vim.MetricAlarmExpression
	$global:expr.Yellow = $yellow
	if($yellowint -ne 0){
		$global:expr.YellowInterval = $yellowint}
	$global:expr.Red = $red
	if($redint -ne 0){
		$global:expr.RedInterval = $redint}
	$global:expr.Type = $type
	$global:expr.Metric = New-Object VMware.Vim.PerfMetricId
	$global:expr.Metric.CounterId = $count
	$global:expr.Metric.Instance = ""
	$global:alarm.expression.expression += $global:expr
}

And all the script is perfectly working.

I have updated the script on my ftp ( http://ghostus.free.fr/Projet/PowerCLI/default-alarm.ps1 )

now it is totally recreating all default alarm.

(I will post it over document when I get back home, at work my proxy don't let me upload file...)

Thanks for your help Smiley Wink

0 Kudos