Could you use the LUA highlight capability of the forum?
Makes the snippets way easier to read.
You have a button in the toolbar.
[ highlight="Lua" ] [ /highlight ]
Hard to debug a piece of code in isolation and you didn't say exactly what is not working.
What I can tell you is that you need to register the Threat Events against a callback in order for you to see any updates.
Like so:
Lua Code:
local function UpdateThreat(self, event, unit)
-- Do stuff here
end
frame:RegisterEvent("UNIT_THREAT_LIST_UPDATE", UpdateThreat)
frame:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", UpdateThreat)