#!/usr/bin/python
import sys
import os

def main(argc, argv):
    # set a 'magic' phrase to find in the page (static, command-line
    # defined, ...)
    magic = 'Welcome to the official Nagios'
    # parse the command line and extract the argument of the -H option
    # ...
    url = 'www.nagios.org'
    # ask lynx to get the page
    stdout = os.popen('lynx -dump '+url)
    for line in stdout:
        if magic in line:
            print "HTTP OK - Website up and running"
            return 0
    print "HTTP CRITICAL - Wooops, website screwed up"
    return 2

if __name__ == '__main__':
    retcode = 3
    try:
        retcode = main(len(sys.argv), sys.argv)
        if retcode < 0 or retcode > 3:
            retcode = 3
    except Exception, err:
        print "PYTHON ERROR - "+str(err)
        retcode = 2
    sys.exit(retcode)
else:
    print "Not an importable module. Please run 'check_http_lynx.py' from the command line"
    sys.exit(3)
    