This is the Magnetic Door Switch Set, a small reed switch assembly specifically designed to alert you when doors, drawers, or any other aperture opens.
These types of switches are primarily used in home security systems. One half of the assembly set on a window or door frame and the other attached to the window or door itself. When the switch set is separated from each other the contact is broken and triggers an alarm.
When each magnet piece comes within 20mm of each other they complete the circuit with the internal reed switches. Each Magnetic Door Switch set can accept a max voltage of up to 100V at 500mA. Additionally each set is housed in durable ABS plastic and, with the included screws, can easily mount to most surfaces.