SQL DB Backup test alerting when it shouldn't
Home  » Operations Manager  » SQL DB Backup test alerting when it shouldn't

SQL DB Backup test alerting when it shouldn't
Posted: Tue, Oct 06, 2009 10:01 AM :: Rank: 2
Author
Points: 6985
Level: System Center Specialist

I followed Stefan's blog entry here: http://blogs.technet.com/stefan_stranger/archive/2009/02/02/opsmgr-sql-full-or-differential-backup-check.aspx

Everything seems to work fine, except that SCOM creates alerts even when the NumHours property returned from the script is less than the threshold (in my case 25 hours).

I even modified part of the script so that I could tell what was going on.

 If CInt(oResults(1)) > iThresholdHours Then
          ' last backup is too old
          Call objBag.AddValue("Reason", "The last full or differential backup for database " & strDatabase & " is more than " & oResults(1) & " hours old!")
   Else
           ' backups is ok
           Call objBag.AddValue("Reason", "The last full or differential backup for database " & strDatabase & " is not supposed to be alerting because this backup is " & oResults(1) & " hours old.")
   End If
 

I've got the Healthy and Unhealthy expressions set right (as per his blog), but I still get critical alerts in my console with "The last full or differential backup for database DBNAME is not supposed to be alerting because this backup is 3 hours old."   I should never see these, since the rule should consider 3 hours old as Healthy.

Any thoughts as to what I might have done wrong?

   Report Abuse
Re: SQL DB Backup test alerting when it shouldn't
Posted: Tue, Oct 06, 2009 10:31 AM :: Rank: 0
Author
Points: 40804
Level: System Center Expert
Hi Bob, what is the Property[@Name='NumHours'] value set to?
   Report Abuse
RE: SQL DB Backup test alerting when it shouldn't
Posted: Tue, Oct 06, 2009 10:49 AM :: Rank: 31
Author
Points: 6985
Level: System Center Specialist

It is set to the results of the SQL query that compares the date/time of the last backup to the current date/time.  In other words, if the backup is 4 hours old, then NumHours=4.

There is a line above the section of the script that I posted that creates the property that then gets sent back to SCOM in the property bag.

Call objBag.AddValue("NumHours", CInt(oResults(1)))

 

The value that I see in the alert (or if I run the SQL query manually in on the server) is correct.  The problem is the reaction of SCOM to the value.  It's not seeing 3 as being less than 25 for some reason, even though I appear to have the Healthy and Unhealthy expressions correct (as in the picture).

   Report Abuse
RE: SQL DB Backup test alerting when it shouldn't
Posted: Wed, Oct 14, 2009 3:24 PM :: Rank: 0
Author
Points: 6985
Level: System Center Specialist

I never saw anyone post a valid solution to this problem, so I found a way around it.  Since the script itself was doing a fine job of figuring out if the backup was under a certain threshold, and SCOM was having a hard time figuring out if 3 was less than 25, I added a line of code to the script.  See below:

If oResults.EOF Then
Call objBag.AddValue("BackupType", "Full or differential backup")
Call objBag.AddValue("NumHours", "9999")
Call objBag.AddValue("Reason", "A full backup for database " & strDatabase & " is never be made!")
Call objBag.AddValue("Status","Bad")

 

Else
Call objBag.AddValue("BackupType", "Full or differential backup")
Call objBag.AddValue("NumHours", CStr(oResults(1)))
If CInt(oResults(1)) > iThresholdHours Then
Call objBag.AddValue("Reason", "The last full or differential backup for database " & strDatabase & " is more than " & oResults(1) & " hours old!")
Call objBag.AddValue("Status","Bad")

Else
' backups is ok
Call objBag.AddValue("Reason", "The last full or differential backup for database " & strDatabase & " SHOULD NOT BE ALERTING BECAUSE IT is less than " & CStr(iThresholdHours) & " hours old.")
Call objBag.AddValue("Status","OK")
End If
End If 

Now, I've set the Healthy and Unhealthy expressions in the monitor to key off of the 'Status' variable instead of trying to compare the 'NumHours' variable.  Everything is working fine now.  

I still have no idea why SCOM had trouble comparing the 2 numbers.

Accepted Answer
   Report Abuse
Re: SQL DB Backup test alerting when it shouldn't
Posted: Mon, Oct 19, 2009 5:07 AM :: Rank: 1
Author
Points: 145
Level: System Center Hero
Hi ComputerBob,



Can I add another file at the end of my blogpost with your improvements?



Regards,

Stefan Stranger



http://blogs.technet.com/stefan_stranger/archive/2009/02/02/opsmgr-sql-full-or-differential-backup-check.aspx?CommentPosted=true#commentmessage
   Report Abuse
RE: SQL DB Backup test alerting when it shouldn't
Posted: Thu, Oct 29, 2009 8:55 AM :: Rank: 0
Author
Points: 6985
Level: System Center Specialist

Yes, please do.  I think other people would benefit from it.

   Report Abuse
RE: SQL DB Backup test alerting when it shouldn't
Posted: Fri, Jan 15, 2010 1:29 AM :: Rank: 0
Author
Points: 180
Level: System Center Hero

Hi Bob, 

I also followed Stefan's solution and i also ran into the issue your referring to above. When i posted the same issue the MSDN forum http://social.technet.microsoft.com/Forums/en-US/operationsmanagergeneral/thread/f3ee2886-dcdc-4257-ba67-7f8e047683f5 , Daniele Grandini suggested that i change the data type in the xml configuration from string to integer. Since making this change, the alerts and state changes seems to occur when at the correct time. Here is the bit of xml i changed to integer.

 

 

          <ErrorExpression>

            <SimpleExpression>

              <ValueExpression>

                <XPathQuery Type="Integer">Property[@Name='NumHours'] </XPathQuery>

              </ValueExpression>

              <Operator>Greater</Operator>

              <ValueExpression>

                <Value Type="Integer">20</Value>

              </ValueExpression>

            </SimpleExpression>

          </ErrorExpression>

          <SuccessExpression>

            <SimpleExpression>

              <ValueExpression>

                <XPathQuery Type="Integer">Property[@Name='NumHours'] </XPathQuery>

              </ValueExpression>

              <Operator>LessEqual</Operator>

              <ValueExpression>

                <Value Type="Integer">20</Value>

              </ValueExpression>

            </SimpleExpression>

          </SuccessExpression>

Cheers,

PK

 

   Report Abuse
Re: SQL DB Backup test alerting when it shouldn't
Posted: Fri, Jan 15, 2010 1:57 PM :: Rank: 0
Author
Points: 6985
Level: System Center Specialist
That's great news, PK! I'm glad someone figured that out. I was beginning to think that the SCOM programmers didn't understand simple boolean logic. Makes sense now to understand that it was reading that variable as string instead of an integer. Thanks.
   Report Abuse
Re: SQL DB Backup test alerting when it shouldn't
Posted: Tue, Jun 15, 2010 10:37 AM :: Rank: 42
Author
Points: 6985
Level: System Center Specialist
PK emailed me about another issue he was having with this process. He had some DBs with a space in the name (ie: "GBIX DB") which caused a problem because the script would see those as 2 separate variables and basically fail. I sent him a solution which worked for him and should work for most people. I have seen this before in another script, and had a fix for it that might work here. When you pass the parameter to the script, put quotations around it. See below to see what I’m talking about.



This is what is documented as the parameters sent to that script:

$Target/Host/Property[Type="SQLServer2!Microsoft.SQLServer.DBEngine"]/ConnectionString$ $Target/Property[Type="SQLServer2!Microsoft.SQLServer.Database"]/DatabaseName$ 47



Change it to look like this (notice the quotations around the 2nd parameter):

$Target/Host/Property[Type="SQLServer2!Microsoft.SQLServer.DBEngine"]/ConnectionString$ “$Target/Property[Type="SQLServer2!Microsoft.SQLServer.Database"]/DatabaseName$” 47



I did this for a script having to do with IIS sites and it fixed my ‘extra parameters’ problem when the people that made the site had put a space in the name.



PK tested this in his environment and it works to resolve his issue.

   Report Abuse
Re: SQL DB Backup test alerting when it shouldn't
Posted: Wed, Dec 14, 2011 4:04 PM :: Rank: 79
Author
Points: 60
Level: System Center Enthusiast
Computer Bob. The link from Stefan is no longer working for the script. Would you be able to post it somewhere. I am tasked with reporting on SQL backups using SCOM. Thanks in advance
   Report Abuse
RE: Re: SQL DB Backup test alerting when it shouldn't
Posted: Thu, Dec 15, 2011 9:01 AM :: Rank: 62
Author
Points: 47503
Level: System Center Expert
An enhanced version of that script has already been incorporated into a management pack, which can be downloaded at the link below:
SQL Admin Extensions Sample Management Pack for OpsMgr 2007 and Essentials 2010
   Report Abuse

Home  » Operations Manager  » SQL DB Backup test alerting when it shouldn't
Top Contributors
Featured Members
Pete Zerger
Points: 72684
Level: System Center Expert
Tommy Gunn
Points: 47503
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Andreas Zuckerhut
Points: 30700
Level: System Center Expert
Stefan Koell
Points: 30179
Level: System Center Expert