SQL Server database file might not grow using the configured growth value
http://go.microsoft.com/fwlink/?LinkId=231432
Target | Microsoft.KnowledgeServices.SQLServer.Database | ||
Parent Monitor | System.Health.ConfigurationState | ||
Category | Alert | ||
Enabled | True | ||
Alert Generate | True | ||
Alert Severity | Warning | ||
Alert Priority | Normal | ||
Alert Auto Resolve | True | ||
Monitor Type | Microsoft.KnowledgeServices.Library.PowerShellMonitorEx | ||
Remotable | True | ||
Accessibility | Public | ||
Alert Message |
| ||
RunAs | Default | ||
Comment | SupportTopic=TBD;VersionNumber=1.0.0.0; |
<UnitMonitor ID="Monitor_AK555349" Comment="SupportTopic=TBD;VersionNumber=1.0.0.0;" Accessibility="Public" Enabled="true" Target="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="Normal" TypeID="KnowledgeServicesLibrary!Microsoft.KnowledgeServices.Library.PowerShellMonitorEx" ConfirmDelivery="true">
<Category>Alert</Category>
<AlertSettings AlertMessage="MonitorMessageb34fa567fb894944940c4af5269c6455">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Warning</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Data/Context/Property[@Name='AffectedFileName']$</AlertParameter1>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<ScriptName>AK555349.ps1</ScriptName>
<Parameters>
<Parameter>
<Name>ConnectionString</Name>
<Value>$Target/Host/Property[Type="MicrosoftSQLServerLibrary!Microsoft.SQLServer.DBEngine"]/ConnectionString$</Value>
</Parameter>
<Parameter>
<Name>SQLServerVersion</Name>
<Value>$Target/Host/Property[Type="MicrosoftSQLServerLibrary!Microsoft.SQLServer.DBEngine"]/Version$</Value>
</Parameter>
<Parameter>
<Name>IsDatabaseReadOnly</Name>
<Value>$Target/Property[Type="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database"]/ReadOnly$</Value>
</Parameter>
<Parameter>
<Name>TargetDatabaseID</Name>
<Value>$Target/Property[Type="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database"]/DatabaseId$</Value>
</Parameter>
<Parameter>
<Name>TargetDataBaseStatus</Name>
<Value>$Target/Property[Type="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.Database"]/Status$</Value>
</Parameter>
</Parameters>
<ScriptBody>
param($ConnectionString,$SQLServerVersion,$IsDatabaseReadOnly,$TargetDatabaseID,$TargetDataBaseStatus)
$ErrorActionPreference = "Stop"
# Set up the arguments
$scriptargs = new-object psobject
$scriptargs | add-member NoteProperty "ConnectionString" $ConnectionString
$scriptargs | add-member NoteProperty "SQLServerVersion" $SQLServerVersion
$scriptargs | add-member NoteProperty "IsDatabaseReadOnly" $IsDatabaseReadOnly
$scriptargs | add-member NoteProperty "TargetDatabaseID" $TargetDatabaseID
$scriptargs | add-member NoteProperty "TargetDataBaseStatus" $TargetDataBaseStatus
# Set up the output
$global:scriptoutput = new-object psobject
$scriptoutput | add-member NoteProperty "HasIssue" $false
$scriptoutput | add-member NoteProperty "AffectedFileName" ""
#-----------------------------------------------------
# MAIN CODE SECTION
#-----------------------------------------------------
# Environment
$scriptenv = new-object psobject
$scriptenv | add-member NoteProperty "ConnectionString" ""
$scriptenv | add-member NoteProperty "QueryString" ""
$scriptenv | add-member NoteProperty "SQLServerVersion" ""
$scriptenv | add-member NoteProperty "ErrorFlag" $false
# Function to get affected File Name
function Get-AffectedFileName {
$scriptenv.QueryString = "select name from sys.master_files where database_id = " + $scriptargs.TargetDatabaseID + " AND type = 1 AND is_percent_growth = 0 AND growth % 524288 = 0"
$scriptenv.ConnectionString = "Data Source=" + $scriptargs.ConnectionString + "; Initial Catalog=master;Integrated Security=SSPI"
$conn = new-object System.Data.SqlClient.SqlConnection($scriptenv.ConnectionString)
$conn.Open()
$cmd = $conn.CreateCommand()
$cmd.CommandText = $scriptenv.QueryString
$sqlReader= $cmd.ExecuteReader()
while ($sqlReader.Read()){
If($sqlReader[0] -ne $null -and $sqlReader[0].Trim() -ne ""){
$scriptoutput.AffectedFileName = $scriptoutput.AffectedFileName + "," + $sqlReader[0]
}
}
$sqlReader.Close()
If($scriptoutput.AffectedFileName.Length -gt 0)
{
$scriptoutput.AffectedFileName = $scriptoutput.AffectedFileName.Substring(1)
}
}
# Main function
function AdvisorRule($scriptargs, $scriptoutput)
{
trap [Exception] {
$scriptenv.ErrorFlag = $true
continue
}
# All parameters should be populated outside of the main function.
# The mian function should only include the detection logic so that it can be easyly reused by the Atlanta authoring tool.
# Initialize parameters
$scriptoutput.HasIssue = $false
$scriptoutput.AffectedFileName = ""
# Set parameter values
$scriptenv.SQLServerVersion = $scriptargs.SQLServerVersion.SubString(0,$scriptargs.SQLServerVersion.Indexof('.'))
# Detection Logic
# This rule is only applicable for SQL Server 2008 and SQL Server 2008 R2
If ($scriptenv.SQLServerVersion -eq "10"){
# Evaluate this rule only if the Database property is_read_only = 0 and state = ONLINE
If($scriptargs.TargetDataBaseStatus.ToUpper() -eq "ONLINE" -and $scriptargs.IsDatabaseReadOnly -eq $false){
Get-AffectedFileName
If($scriptoutput.AffectedFileName -ne "" -and $scriptoutput.AffectedFileName -ne $null){
If ($scriptenv.ErrorFlag -ne $true){
#Raise alert
$scriptoutput.HasIssue = $true
}
}
}
}
}
AdvisorRule $scriptargs $scriptoutput
# set the output
$mom = new-object -comobject "MOM.ScriptAPI"
$bag = $mom.CreatePropertyBag()
if ($scriptoutput.HasIssue -ne $null)
{
$bag.AddValue("HasIssue", $scriptoutput.HasIssue)
}
if ($scriptoutput.AffectedFileName -ne $null)
{
$bag.AddValue("AffectedFileName", $scriptoutput.AffectedFileName)
}
$bag
</ScriptBody>
<SnapIns/>
<TimeoutSeconds>300</TimeoutSeconds>
<Schedule>86396</Schedule>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<Not>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</Not>
</SuccessExpression>
</Configuration>
</UnitMonitor>