Configuring user-defined collections (UDCs) and adding rules to alert upon the result have been covered previously in this blog.
With Oracle and SQL Server, UDCs are stored in the Foglight topology model at the instance level.
I found a special case with UDCs on DB2. When they are created, they get stored at the database level and the database name is added to the name of the UDC.
Start by creating your UDC via the Databases -> Administration -> User-Defined Collections option.
You can use the query text in multiple ways. You could select from a view which gives the advantage of being able to modify the where clause without affecting Foglight. However, the view needs to be created on each database that the UDC will be built on. In this example, I directly query the SYSIBMADM.DB_HISTORY table and have added column named "backup_key" to set as the key field in Foglight. I also specify that backup_status is an integer that is frequently modified so that it gets treated as a metric and not a property.
Once the UDC is saved, you can verify data collection by drilling down to the DB2 database and selecting Activity -> User-defined Collections. If you open this as a separate tab, it can help with refreshing the data while testing the alarm.
To create the rule, go to Administration -> Rules & Notifications -> Create Rule.
Provide a rule name, select multiple-severity and confirm it's data driven.
Next we'll drop down the DB_DB2 cartridge and select DB2_Custom_Query_Result for the topology type. Click the green u-turn button do drop it into the rule scope pane - it should just be "DB2_Custom_Query_Result" at this point. Since the database name gets automatically added to the UDC result, adding the text
" : name like '%backup_check%' " will filter to the UDC created in step 1.
Click the green check mark to verify that objects are returned from the scoping query. I've got 2 UDCs - one on my SAMPLE database and the other on my SALES database. I have other UDCs that aren't showing which confirms my scoping query worked. As you clone UDCs to other databases, they would show up in the results as well - which means the rule will automatically apply to them.
For the Condition, I've select fatal as my severity and entered #backup_status# == 1 as the criteria to evaluate to true in order for the rule to fire an alarm. Note that "backup_status" is the column name I used for the metric back in step 1 when creating the UDC. Click Test Rule Logic to confirm that the syntax is valid. I've also created an alarm message with a couple placeholders with the "@" symbol.
I want the message to include the database and instance name, so I've added these expressions as severity level variables. They get referenced in the alarm message with the @db or @inst notation. Click save to keep the changes and enable the rule. (Don't ask me how long it took to figure out that notation. Sometimes you have to experiment and it helps to look at other existing rules in order to figure it out. )
After checking the data in the dashboard from step 2, I can verify that I'm getting the alarm for each database (and they roll up to the instance level too). The alarm text also contains the database and instance name.