At least that's how most switches and relays function. The magnet is stronger than the spring, which pulls the other piece into contact allowing continuity.
I'm sure you can find something suitable on eBay for cheap. It's the kind of thing that you can put on your home window or door to alarm when it is opened and the pieces come away from each other.