I recently had a request to write some code that would enable System Center Operations Manager 2007 R2 (SCOM) to perform a database query against a SQL database and then evaluate the result to determine if various systems were healthy. The first few queries were against a Microsoft SQL Server 2005 database. The remaining couple of queries were against an IBM DB2 database.
Usually, this type of request will involve writing a VB script.
After performing a search on the Internet for similar solutions (always a good idea to see if somebody else has solved the same type of problem), I came up with a couple of useful sites.
When looking at the sample code provided by these links, I noticed that the provider in all samples was “Microsoft OLE DB Provider for SQL Server (SQLOLEDB)”. This would have worked for me, but taking things one step further, I also found out that this provider has been deprecated.
Instead, I chose to use the “SQL Server Native Client OLEDB Provider (SQLNCLI10)”. Using this provider is very similar to using SQLOLEDB.
I could also have chosen to use the “Microsoft OLE DB Provider for ODBC Drivers (MSDASQL)”. During testing, the only thing I didn’t *like* about this provider is that it connects to ODBC, instead of a database. Compared to SQLOLEDB/SQLNCLI10, this means that we need to define a DSN instead of just using a connection string.
How do I enumerate the OLEDB providers on my server?
If you have Microsoft SQL Server installed then this can be done by executing the following stored procedure against the MASTER database:
The output is similar to the following:
Passing Credentials to the Monitor
We have a class called “MyCompany.MyApplication.Watcher” that represents the set of computers from which we will run a script to monitor the MyApplication application.
We have a “Timed Script Two State Monitor” called “MyCompany.MyApplication.Status.Monitor” that is targeted at the “MyCompany.MyApplication.Watcher” class. This monitor contains the script that performs a database lookup against an IBM DB2 database to determine the health of the MyApplication application.
SCOM provides a secure method of passing a credential to a script using a Run-As Profile. For the purpose of connecting to a DB2 database this is not the same as running the script under different credentials. Hence care should be taken not to change the “Run as profile” setting within the monitor. Instead, we will pass the credentials to the script using script parameters.
(to be continued)
List of external links
- Data Access Technologies Road Map (http://msdn.microsoft.com/library/ms810810.aspx)
- Query a database with a monitor
- Query a database with a monitor – part two
- Operations Manager Custom Collection
(Note: this is a quick publish article and is not yet complete)