The requirements gathering phase of the management pack development lifecycle is critically important to the success of the project. Something that may come out of this phase is receiving company health check scripts, and this is an excellent opportunity to incorporate familiar company knowledge into a new monitoring solution.
These scripts might be used to check for some condition that may have occurred in the past
n minutes or hours –
n is referred to as a time offset in this case. This article will briefly describe a simple concept to a best practice around implementing this type of script in a custom data source.
This concept can be broken down into the simplest term, where
n and monitoring interval share configuration.
For example, a script executes the following SQL query:
SELECT COUNT(Column1) as [Count], Name
WHERE Timestamp BETWEEN DATEADD(minute,-60,GETDATE()) AND GETDATE()
GROUP BY Name
The part I want to draw your attention to is the
WHERE clause in the SQL query, because this is where time offset comes into the picture – it is how time offset is identified, and allows for the implementation of this coupling concept.
The query above would return records that have been written in the past 60 minutes from now. When the script is plugged into a data source, “now” is the monitoring interval, which is configured on the scheduler that triggers script execution.
So, we conclude that “now” is
IntervalSeconds on the simple scheduler module.
Now that we know we can couple time offset with monitoring interval, we can easily use the same value for both by sharing the same configuration. In order to do this, two minor changes need to be made in any script you plan to incorporate using this concept:
1. Ensure time offset is in seconds.
2. Replace the time offset value with the IntervalSeconds configuration.
WHERE Timestamp BETWEEN DATEADD(second,-$Config/IntervalSeconds$,GETDATE()) AND GETDATE()
Why is using this concept a good practice?
Monitoring interval is a standard override parameter, and inevitably it will be overridden – maybe not on this particular monitor, and maybe not until you’re long gone. But don’t assume the customer is going to keep the default interval – ever.
By coupling script time offsets to monitoring intervals, a basic interval override will not cause monitor state skewing.