Search code examples
python-3.xflaskclient-serversecure-crt

Checking a flask application running on Secure_CRT


I have written a flask application which returns "Site is OK!". I have this application running on an Ubuntu server locally in SecureCRT. Generally, to check if the application is running or not, I copy paste the URL, for example, http://locahost:5000/check_point in browser or postman and see if "Site is OK!" is displayed on browser or postman. Since in SecureCRT, there is no browser and the application is currently running, so I cannot type in any other command as well, unless and until I do Ctrl + C, may I know how can I check if the application is returning the correct output or not? Sorry, I am new to all these, so my question might be very basic or inappropriate but I will really appreciate any kind of help. Thanks!


Solution

  • Suppose you have the following code and you save it in a file called check_point.py. This will display "Site is OK!" on http://locahost:5000/check_point. It will also create a log file with the name check_point.log.

    If you start this on your Ubuntu server in the background (python check_point.py &) it will log all activity in the log file. curl 127.0.0.1:5000/check_point on the Ubuntu server will trigger a response.

    import logging
    from logging.handlers import RotatingFileHandler
    
    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/check_point')
    def checkPoint():
        app.logger.info('Site is OK!')
        return 'Site is OK!'
    
    if __name__ == '__main__':
        formatter = logging.Formatter(
            '%(asctime)s | %(pathname)s:%(lineno)d | %(funcName)s | %(levelname)s | %(message)s')
        log = RotatingFileHandler('check_point.log', maxBytes=10000, backupCount=1)
        log.setFormatter(formatter)
        app.logger.addHandler(log)
        app.logger.setLevel(logging.INFO)
        app.run(host='0.0.0.0', port=5000)