Hey all,
I am having a hell of a time with trying to create a custom query in SQL where I pull all active alerts, and include the name of the node to which the alert applies.
Here is my SQL code, sans node identification:
SELECT AStat.[ObjectName] AS 'Summary', ADefs.[AlertName] AS 'Category', CONVERT(varchar(20),AStat.[TriggerTimeStamp],0) AS 'Time Triggered' FROM [SolarWindsOrion].[dbo].[AlertStatus] AS AStat INNER JOIN [SolarWindsOrion].[dbo].[AlertDefinitions] AS ADefs ON AStat.AlertDefID = ADefs.AlertDefID WHERE Acknowledged = '0' AND AStat.State = '2' ORDER BY 'Time Triggered' DESC
Simple, right? The issue comes in trying to tie in that node identification. In the AlertStatus table all entries have an ActiveObject column. The problem is that this value ties to a different table depending on what the ObjectType is. Node alerts go to the Nodes table, Volume alerts go to the Volumes table. This would seem to lend itself to a massive query with tons of joins; one for each potential alert type.
For example, here is a query that (albeit coded in SWQL) shows an example of the problem, and its not even a complete list for all alert types:
SELECT '' AS Sev, CASE WHEN AStat.State = '1' THEN ('/Orion/images/StatusIcons/Small-Warning.gif') WHEN AStat.State = '2' THEN ('/Orion/images/StatusIcons/Small-Critical.gif') END AS [_IconFor_Sev], tolocal(AStat.TriggerTimeStamp) AS [Time of Alert], AStat.ObjectName AS [Object], ADefs.Name AS [Category], CASE WHEN AStat.ObjectType = 'Node' THEN ('/Orion/NetPerfMon/NodeDetails.aspx?NetObject=N%3a' + ToString(Nodes.NodeID)) WHEN AStat.ObjectType = 'Volume' THEN ('/Orion/NetPerfMon/VolumeDetails.aspx?NetObject=V%3a' + ToString(Volumes.VolumeID)) WHEN AStat.ObjectType = 'Interface' THEN ('/Orion/View.aspx?NetObject=I%3a' + ToString(Interfaces.InterfaceID)) WHEN AStat.ObjectType = 'Hardware Sensor' THEN ('/Orion/View.aspx?NetObject=N%3a' + ToString(Hardware.NodeID)) WHEN AStat.ObjectType = 'APM: Component' THEN ('/Orion/View.aspx?NetObject=AM%3a' + ToString(APMC.ComponentID)) WHEN AStat.ObjectType = 'APM: Application' THEN ('/Orion/View.aspx?NetObject=AA%3a' + ToString(APMA.ApplicationID)) WHEN AStat.ObjectType = 'Custom Node Poller' THEN ('/Orion/View.aspx?NetObject=N%3a' + ToString(CusPol.NodeID)) END AS [_LinkFor_Object] FROM Orion.AlertStatus AS AStat INNER JOIN Orion.AlertDefinitions AS ADefs ON AStat.AlertDefID = ADefs.AlertDefID LEFT OUTER JOIN Orion.Nodes AS Nodes ON ToString(Nodes.NodeID) = AStat.ActiveObject AND AStat.ObjectType = 'Node' LEFT OUTER JOIN Orion.Volumes AS Volumes ON ToString(Volumes.VolumeID) = AStat.ActiveObject AND AStat.ObjectType = 'Volume' LEFT OUTER JOIN Orion.NPM.Interfaces AS Interfaces ON ToString(Interfaces.InterfaceID) = AStat.ActiveObject AND AStat.ObjectType = 'Interface' LEFT OUTER JOIN Orion.HardwareHealth.HardwareItem AS Hardware ON ToString(Hardware.ID) = AStat.ActiveObject AND AStat.ObjectType = 'Hardware Sensor' LEFT OUTER JOIN Orion.APM.Component AS APMC ON ToString(APMC.ComponentID) = AStat.ActiveObject AND AStat.ObjectType = 'APM: Component' LEFT OUTER JOIN Orion.APM.Application AS APMA ON ToString(APMA.ApplicationID) = AStat.ActiveObject AND AStat.ObjectType = 'APM: Application' LEFT OUTER JOIN Orion.NPM.CustomPollerAssignment AS CusPol ON ToString(CusPol.CustomPollerAssignmentID) = AStat.ActiveObject AND AStat.ObjectType = 'Custom Node Poller' WHERE Acknowledged = 0 AND AStat.State = '2' ORDER BY TriggerTimeStamp DESC
Am I missing a far more elegant way of doing this?