Microsoft.SystemCenter.VirtualMachineManager.2012.UserRoleUsageUnitMonitorType (UnitMonitorType)

Element properties:

RunAsDefault
AccessibilityPublic
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Scheduler Default
Probe ProbeAction Microsoft.SystemCenter.VirtualMachineManager.2012.PowerShellProbeActionModuleType Default
CDOnCritical ConditionDetection System.ExpressionFilter Default
CDOnHealthy ConditionDetection System.ExpressionFilter Default
CDOnWarning ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
TimeoutSecondsint$Config/TimeoutSeconds$
WarningThresholddouble$Config/WarningThreshold$
CriticalThresholddouble$Config/CriticalThreshold$

Source Code:

<UnitMonitorType ID="Microsoft.SystemCenter.VirtualMachineManager.2012.UserRoleUsageUnitMonitorType" Accessibility="Public">
<MonitorTypeStates>
<MonitorTypeState ID="UserRoleHealthy" NoDetection="false"/>
<MonitorTypeState ID="UserRoleWarning" NoDetection="false"/>
<MonitorTypeState ID="UserRoleCritical" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element name="WarningThreshold" type="xsd:double"/>
<xsd:element name="CriticalThreshold" type="xsd:double"/>
<xsd:element name="UserRoleId" type="xsd:string"/>
<xsd:element name="VMMServer" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="WarningThreshold" Selector="$Config/WarningThreshold$" ParameterType="double"/>
<OverrideableParameter ID="CriticalThreshold" Selector="$Config/CriticalThreshold$" ParameterType="double"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="Probe" TypeID="Microsoft.SystemCenter.VirtualMachineManager.2012.PowerShellProbeActionModuleType">
<Parameters>
<Parameter>
<Name>VMMServer</Name>
<Value>$Config/VMMServer$</Value>
</Parameter>
<Parameter>
<Name>domain</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Domain$</Value>
</Parameter>
<Parameter>
<Name>username</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>pass</Name>
<Value>$RunAs[Name="PROV2Library!Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Password$</Value>
</Parameter>
</Parameters>
<ScriptBody><Script>
param($VMMServer, $domain, $username, $pass)

function Cleanup
{
$module = get-module -name "virtualmachinemanagercore"

if ($module -ne $null)
{
remove-module -moduleInfo $module
}
if ($session -ne $null)
{
Remove-PSSession $session;
}
}

# UserRoleQuota.ps1 - calculates the user role usage ratio to its quota across clouds in VMM

#error codes
$NewPSSessionFailureCode = 25933;
$CredentialNullCode = 25934;
$GetVMMFailureCode = 25935;
$GetUserRoleFailureCode = 25936;
$ScriptSuccessCode = 25940;


$oAPI = New-Object -comObject 'MOM.ScriptAPI'
$pBag = $oAPI.CreatePropertyBag()

$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "Microsoft.SystemCenter.VirtualMachineManager.2012.Monitor.UserRoleQuotaUsageMonitor";
$errevent = [System.Diagnostics.EventLogEntryType]::Error;
$infoevent = [System.Diagnostics.EventLogEntryType]::Information;


$error.Clear();

$cred = $null;
if ($domain -AND $username -AND $pass)
{
#Append domain to get domain\username
$domainUser = $domain + "\" + $username;

#Create Cred object
$securePass = ConvertTo-SecureString -AsPlainText $pass -force
$cred = New-Object System.Management.Automation.PSCredential $domainUser, $securePass;

}

####### Remote Session
if ($cred -eq $null)
{
$evt.WriteEntry("Credentials are null for user: " + $domainUser, $errevent, $CredentialNullCode);
Cleanup
return;
}


$error.Clear();
$session = New-PSSession -ComputerName $VMMServer -Authentication Default -Credential $cred;
if ($error.Count -ne 0)
{
$evt.WriteEntry("New PS Session failed:" + $error[0].Exception.StackTrace, $errevent, $NewPSSessionFailureCode);
Cleanup
return;
}


$error.Clear();
$vmmServer = Invoke-Command -Session $session -ArgumentList $VMMServer -ScriptBlock {
$module = get-module -name "virtualmachinemanagercore";
if ($module -eq $null)
{
Import-Module "virtualmachinemanagercore";
}
$vmm = Get-SCVMMServer -ComputerName $args[0];
$vmm
};

if ($vmmServer -eq $null)
{
$evt.WriteEntry("Get VMM Server failed:" + $error[0].Exception.StackTrace, $errevent, $GetVMMFailureCode);
Cleanup
return;
}

#remote script to calculate userrole quota usage vs capacity percentage
$UserRoleQuotaUsagePercentList = Invoke-Command -Session $session -ScriptBlock {
function GetPercent
{
param($usage, $capacity)
$percent = 0;
if ($capacity -ne 0)
{
$percent = [Math]::Round(($usage * 100) / $capacity);
}

$percent;
}

foreach ($u in Get-SCUserRole)
{
$cpuCapacitySum = 0; $cpuUsageSum = 0;
$customQuotaCapacitySum = 0; $customQuotaUsageSum = 0;
$memCapacitySum = 0; $memUsageSum = 0;
$storageCapacitySum = 0; $storageUsageSum = 0;
$vmCountCapacitySum = 0; $vmCountUsageSum = 0;

foreach ($c in Get-SCCloud)
{
$quota = Get-SCUserRoleQuota -QuotaPerUser $false -Cloud $c -UserRole $u;
if ($quota -ne $null)
{
$usage = Get-SCCloudUsage -Cloud $c -UserRole $u;

# if user role quota uses max available, then that cloud usage/quota does not apply
if(!$quota.UseCPUCountDefault)
{
$cpuUsageSum += $usage.CPUUsageCount;
$cpuCapacitySum +=$quota.CPUCount
}

if(!$quota.UseCustomQuotaCountDefault)
{
$customQuotaUsageSum += $usage.CustomQuotaUsageCount;
$customQuotaCapacitySum +=$quota.CustomQuotaCount
}

if(!$quota.UseMemoryDefault)
{
$memUsageSum += $usage.MemoryUsageMB;
$memCapacitySum +=$quota.MemoryMB
}

if(!$quota.UseStorageGBDefault)
{
$storageUsageSum += $usage.StorageUsageGB;
$storageCapacitySum +=$quota.StorageGB
}

if(!$quota.UseVMCountDefault)
{
$vmCountUsageSum += $usage.VMUsageCount;
$vmCountCapacitySum +=$quota.VMCount
}
}
}
# return quota percentages for every user role
$u.ID.ToString();
$u.Name;
GetPercent -usage $cpuUsageSum -capacity $cpuCapacitySum;
GetPercent -usage $customQuotaUsageSum -capacity $customQuotaCapacitySum;
GetPercent -usage $memUsageSum -capacity $memCapacitySum;
GetPercent -usage $storageUsageSum -capacity $storageCapacitySum;
GetPercent -usage $vmCountUsageSum -capacity $vmCountCapacitySum;
}
};

if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $errevent, $GetUserRoleFailureCode);
Cleanup
return;
}

if ($UserRoleQuotaUsagePercentList -ne $null -and $UserRoleQuotaUsagePercentList.Count -ne $null)
{
$count = $UserRoleQuotaUsagePercentList.Count - $UserRoleQuotaUsagePercentList.Count % 7;
$pBag = $oAPI.CreatePropertyBag()

# returned property list from VMM has 7 properties per user role.
for ( $i = 0; $i -le $count; $i += 7)
{
if ($UserRoleQuotaUsagePercentList[$i] -ne $null)
{
$pBag.AddValue($UserRoleQuotaUsagePercentList[$i] + "-CPU", $UserRoleQuotaUsagePercentList[$i+2])
$pBag.AddValue($UserRoleQuotaUsagePercentList[$i] + "-CustomQuota", $UserRoleQuotaUsagePercentList[$i+3])
$pBag.AddValue($UserRoleQuotaUsagePercentList[$i] + "-Memory", $UserRoleQuotaUsagePercentList[$i+4])
$pBag.AddValue($UserRoleQuotaUsagePercentList[$i] + "-Storage", $UserRoleQuotaUsagePercentList[$i+5])
$pBag.AddValue($UserRoleQuotaUsagePercentList[$i] + "-VMCount", $UserRoleQuotaUsagePercentList[$i+6])
}
}
$pBag
$evt.WriteEntry("Created property bag with " + $count + " properties.", $infoevent, $ScriptSuccessCode);

}
Cleanup


</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection ID="CDOnHealthy" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/UserRoleId$']</XPathQuery>
</ValueExpression>
<Operator>Less</Operator>
<ValueExpression>
<Value Type="Double">$Config/WarningThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOnWarning" TypeID="System!System.ExpressionFilter">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/UserRoleId$']</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="Double">$Config/WarningThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/UserRoleId$']</XPathQuery>
</ValueExpression>
<Operator>Less</Operator>
<ValueExpression>
<Value Type="Double">$Config/CriticalThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDOnCritical" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">Property[@Name='$Config/UserRoleId$']</XPathQuery>
</ValueExpression>
<Operator>GreaterEqual</Operator>
<ValueExpression>
<Value Type="Double">$Config/CriticalThreshold$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="UserRoleHealthy">
<Node ID="CDOnHealthy">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="UserRoleWarning">
<Node ID="CDOnWarning">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="UserRoleCritical">
<Node ID="CDOnCritical">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>