actually, a better, and more reliable solution would be a magnetic switch for an alarm system. it might also look neater. or a microswitch with a lever that activates the switch at the end of the door's travel. not as nice looking as the magnetic switch, but it would work.
the magnetic switch comes with a magnet that gets mounted on the door, and the switch itself is mounted on the door frame. i said they are a "neater looking" solution, because they are in nice (usually white or tan colored) plastic enclosures. if you are married, or have a girlfriend, better to have something that looks nice.