Monitor every mosque in the world and the problem is solved.
I think we need the 21st century equivalent of shunning.
Identify terrorist nations - Saudi Arabia, Yemen, Somalia, Pakistan, Afganistan - and proclaim that if you have a passport from one of them or a passport stamp that shows you were there, you can no longer visit western countries.
No coming here for medical treatments, schooling, or even vacation. Start with a five or ten year shunning and force them to stay in the shitholes that they have created. If they clean out their own rats nest destroying the terrorists they are breeding and show they can act civilised, then we might allow them back in civilised society. It sure would be a lot cheaper than the way we are currently dealing with them.