For various reasons (not the least of them being that I am a geek prone to overengineering π ), my openhab installation consists of multiple Rasperry Pi nodes. The data collected is pushed via HTTP (upcoming: mqtt) to the server node.
Also, there are some precautions in place to avoid overloading the OH2 server while keeping a short response time to events. The first script published there is for the magnetic window contacts.
Without further ado, please find my scripts over at https://github.com/hakan42/openhab-sensor-scripts