"Fossies" - the Fresh Open Source Software Archive

Member "monasca-log-api-2.9.0/docker/health_check.py" (1 Apr 2019, 1364 Bytes) of package /linux/misc/openstack/monasca-log-api-2.9.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "health_check.py" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/env python
    2 # coding=utf-8
    3 
    4 # (C) Copyright 2018 FUJITSU LIMITED
    5 #
    6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    7 # not use this file except in compliance with the License. You may obtain
    8 # a copy of the License at
    9 #
   10 # http://www.apache.org/licenses/LICENSE-2.0
   11 #
   12 # Unless required by applicable law or agreed to in writing, software
   13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   15 # License for the specific language governing permissions and limitations
   16 # under the License.
   17 
   18 """Health check will returns 0 when service is working properly."""
   19 
   20 import logging
   21 from urllib import request
   22 import os
   23 import sys
   24 
   25 
   26 LOG_LEVEL = logging.getLevelName(os.environ.get('LOG_LEVEL', 'INFO'))
   27 logging.basicConfig(level=LOG_LEVEL)
   28 logger = logging.getLogger(__name__)
   29 
   30 API_PORT = os.environ.get('MONASCA_CONTAINER_LOG_API_PORT', '5607')
   31 url = "http://localhost:" + API_PORT + "/healthcheck"
   32 
   33 
   34 def main():
   35     """Send health check request to health check endpoint of log API."""
   36     logger.debug('Send health check request to %s', url)
   37     try:
   38         request.urlopen(url=url)
   39     except Exception as ex:
   40         logger.error('Exception during request handling: ' + repr(ex))
   41         sys.exit(1)
   42 
   43 
   44 if __name__ == '__main__':
   45     main()