Remove obsolete packages
[doctor.git] / tests / consumer.py
1 ##############################################################################
2 # Copyright (c) 2016 NEC Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import argparse
11 from flask import Flask
12 from flask import request
13 import json
14 import logger as doctor_log
15 import time
16
17 LOG = doctor_log.Logger('doctor_consumer').getLogger()
18
19
20 app = Flask(__name__)
21
22
23 @app.route('/failure', methods=['POST'])
24 def event_posted():
25     LOG.info('doctor consumer notified at %s' % time.time())
26     LOG.info('received data = %s' % request.data)
27     d = json.loads(request.data)
28     return "OK"
29
30
31 def get_args():
32     parser = argparse.ArgumentParser(description='Doctor Sample Consumer')
33     parser.add_argument('port', metavar='PORT', type=int, nargs='?',
34                         help='the port for consumer')
35     return parser.parse_args()
36
37
38 def main():
39     args = get_args()
40     app.run(host="0.0.0.0", port=args.port)
41
42
43 if __name__ == '__main__':
44     main()