Github user sedukull commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/625#discussion_r35605766
  
    --- Diff: reporter/usage-report-collector.py ---
    @@ -0,0 +1,64 @@
    +#!/usr/bin/env python
    +# Licensed to the Apache Software Foundation (ASF) under one
    +# or more contributor license agreements.  See the NOTICE file
    +# distributed with this work for additional information
    +# regarding copyright ownership.  The ASF licenses this file
    +# to you under the Apache License, Version 2.0 (the
    +# "License"); you may not use this file except in compliance
    +# with the License.  You may obtain a copy of the License at
    +# 
    +#   http://www.apache.org/licenses/LICENSE-2.0
    +# 
    +# Unless required by applicable law or agreed to in writing,
    +# software distributed under the License is distributed on an
    +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +# KIND, either express or implied.  See the License for the
    +# specific language governing permissions and limitations
    +# under the License.
    +
    +from flask import abort, Flask, request, Response
    +from elasticsearch import Elasticsearch
    +import json
    +import time
    +
    +def json_response(response):
    +    return json.dumps(response, indent=2) + "\n", 200, {'Content-Type': 
'application/json; charset=utf-8'}
    +
    +def generate_app(config=None):
    +    app = Flask(__name__)
    +
    +    @app.route('/report/<unique_id>', methods=['POST'])
    +    def report(unique_id):
    +        # We expect JSON data, so if the Content-Type doesn't match JSON 
data we throw an error
    +        if 'Content-Type' in request.headers:
    +            if request.headers['Content-Type'] != 'application/json':
    +                abort(417, "No or incorrect Content-Type header was 
supplied")
    +
    +        index = "cloudstack-%s" % time.strftime("%Y.%m.%d", time.gmtime())
    +        timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
    +
    +        es = Elasticsearch()
    +        es.indices.create(index=index, ignore=400)
    +
    +        report = json.loads(request.data)
    --- End diff --
    
    May be we wanted to add a small check to see report is None and proceed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to