MySQL Status Check in Nagios 2

Part one of this series introduced the concept of using a web status page for nagios checks and how to setup a mysql and php status page. In part two the nagios check itself is detailed along with “what other interesting things could one do.”
The Nagios Check Script

For simplification I will follow what seems to be “the systhread standard” and first break the script down into pieces and at the end put it all together. First setting things up: