This query was originally adapted from jbiggley post in
For the purposes of this post and to keep it as simple as possible, I'm trying to create an alert that will identify interfaces that exceed a threshold defined as a percentage of receive discards (.1% for this example). This query works just fine in SQL studio and the returned results are all the interfaces that meet or exceed the .1% receive discards threshold.
SELECT interfaces.fullname, interfaces.interfaceidFROM interfaces WITH (nolock) JOIN (SELECT id.[interfaceid], CASE WHEN id.[in_discards] + Isnull(it.[in_totalpkts], 0) = 0 THEN 0 ELSE Round(( ( [in_discards] ) / ( id.[in_discards] + Isnull(it.[in_totalpkts], 0) ) * 100 ), 2 ) END receivepercentdiscards, CASE WHEN id.[out_discards] + Isnull(it.[out_totalpkts], 0) = 0 THEN 0 ELSE Round(( ( [out_discards] ) / ( id.[out_discards] + Isnull(it.[out_totalpkts], 0) ) * 100 ), 2) END transmitpercentdiscards FROM [DBO].[interfaceerrors_detail] id WITH (nolock) LEFT JOIN [DBO].[interfacetraffic_detail] it WITH (nolock) ON id.interfaceid = it.interfaceid AND id.[datetime] = it.[datetime] WHERE in_discards > 0 -- Match events from the previous 15 minutes (alert evaluation interval) AND id.datetime >= Dateadd(ss, -900, Getdate())) AS t1 ON t1.interfaceid = interfaces.interfaceid JOIN nodesdata nd WITH (nolock) ON interfaces.nodeid = nd.nodeid JOIN nodescustomproperties ncp WITH (nolock) ON nd.nodeid = ncp.nodeidWHERE ( [T1].[receivepercentdiscards] >= 1 OR [T1].[transmitpercentdiscards] >= 1 ) AND ( ncp.site_id NOT LIKE 'UTR%' ); -- filter out devices assigned to any UTR% `site_id`
My question pertains to how I take this information and use it in a trigger action, as this is my first SQL alert. With all my other alerts, that identify issues through the drop down menu conditions (for lack of a better way to phrase it), I am able to use the variables such as ${N=SwisEntity;M=Node.DisplayName} or ${N=SwisEntity;M=InterfaceName}. My first question is if it is possible to pass the ReceivePercentDiscards value into my trigger action. If it is, how would I go about such a thing?
I have tried passing the below variables, but instead of passing the actual ReceivePercentDiscards value, it just shows up as "{SQL: [T1].[ReceivePercentDiscards]}":
C:\windows\system32\windowspowershell\v1.0\powershell.exe -ExecutionPolicy unrestricted -command "C:\sw_tools\scripts\slack\Slack_Alert_Trigger_RX-Discard.ps1 '${N=SwisEntity;M=Node.DisplayName}' '${N=SwisEntity;M=InterfaceName}' '${N=SwisEntity;M=Alias}' '{SQL: [T1].[ReceivePercentDiscards]}' '${N=Alerting;M=AlertDetailsUrl}' '${N=SwisEntity;M=Node.DetailsUrl}' '${N=Alerting;M=AcknowledgeUrl}' '${N=Generic;M=DateTime;F=OriginalValue}'"