Print info to an email from trap alert

I have the following code. Im trying to extract the port information from this trap message. I admittedly dont know SQL code very well but I think it is pretty simple what im trying to do. I want to pull the port number aka "ifindex" . My thought is this code would look for "Ifindex" in the code and print 2 characters. Can someone tell me what im missing?

trap message:

'DNOS-PORTSECURITY-PRIVATE-MIB:agentPortSecurityTraps.0.1 : ifIndex.7 = 7, agentPortSecurityLastDiscardedMAC.7 = 20 54:be:f7:0c:e7:c6, sysUpTime = 139 days 13 hours 41 minutes 26.61 seconds, experimental.1057.1.0 =, snmpTrapEnterprise = DNOS-PORTSECURITY-PRIVATE-MIB:agentPortSecurityTraps'

My Code:

${N=SWQL;M=SELECT SUBSTRING('${N=OLM.AlertingMacros;M=OLMAlertMessage.EventMessage}',
PATINDEX('%ifIndex.%', '${N=OLM.AlertingMacros;M=OLMAlertMessage.EventMessage}')+2
) AS Message
FROM Orion.Nodes n}