3c012b4ff280773a4a2714c46a46daee9be78ba2
[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 os
16 import time
17
18 LOG = doctor_log.Logger('doctor_consumer').getLogger()
19
20
21 app = Flask(__name__)
22
23
24 @app.route('/failure', methods=['POST'])
25 def event_posted():
26     LOG.info('doctor consumer notified at %s' % time.time())
27     LOG.info('received data = %s' % request.data)
28     d = json.loads(request.data)
29     return "OK"
30
31
32 def get_args():
33     parser = argparse.ArgumentParser(description='Doctor Sample Consumer')
34     parser.add_argument('port', metavar='PORT', type=int, nargs='?',
35                         help='the port for consumer')
36     return parser.parse_args()
37
38
39 def main():
40     args = get_args()
41     app.run(host="0.0.0.0", port=args.port)
42
43
44 if __name__ == '__main__':
45     main()