We've noticed on more than one occasion where devices do not properly come out of unmanage like they should. This can lead to some pretty serious problems, so I decided to build a monitor to make sure devices and applications don't overrun their normal unmanage windows. This can occur with both scheduled unmanage windows from the Unmanage Utility as well as manually entered windows from the Web Console.
I've created the following SQL Server User Experience Monitors for Node and Application windows, respectively.
SELECT CONVERT (INTEGER, unmanaged), caption
FROM dbo.Nodes
WHERE (unmanaged=1 and UnManageUntil < GetDate())
SELECT CONVERT (INTEGER, unmanaged), name
FROM dbo.APM_Application
WHERE (unmanaged=1 and UnManageUntil < GetDate())
We currently have a node in an overrun state that I'm using for testing, and it does respond properly; however, when I attempt to test the APM version I receive the following message and the component showing DOWN:
Query must return at least 1 row
I'm assuming that the Node monitor will behave the same once the overrun is cleared. I don't know enough SQL to know how to setup a complicated If/Else statement inside the query. I thought that ORDER BY/Sort would do the trick, but I don't think that it will accomplish what I'm looking for.
What I'd like is to allow for an empty result set to return that the component is Available. I don't mind doing more research on my own, so I'm not necessarily looking for anyone to rewrite the script... but I'd appreciate being pointed in the right direction.