I have heard a pearl is a disease of oysters.
Astonished by the statement, I searched a bit  and I discovered that it is really a protection mechanism of the oyster.
I know this defense mechanism is not unique in nature. E.g. humans can isolate foreign bodies (this happens with not-extractable bullets), as well as bees propolize foreign bodies if they can't eject them.
What is the process, the ability of those organisms, called?
How does it works? E.g. how organisms recognize foreign bodies other than other things?