In most cases, an act of terror is preceded by an increase in chatter. The sources are often known, but there usually isn't enough specific information to prevent an attack. All the intelligence agencies can do is provide non-specific warnings. In the case of the Bulgarian attack, apparently there was a non-specific warning.
Pakistan air strikes against Taliban kill at least 25 (Reuters)
from the article: Report: Israel fears Iranian terror attack at London 2012 Olympics