summaryrefslogtreecommitdiffstats
path: root/src/telemetry
diff options
context:
space:
mode:
authorSage Weil <sage@redhat.com>2019-10-10 04:30:44 +0200
committerSage Weil <sage@redhat.com>2019-10-10 04:30:44 +0200
commitc9bfbb7a47c32638f7d9ead9a032d636850d4726 (patch)
tree524d14f0997eb598fda804b05bbb735cc8c1aa4e /src/telemetry
parentMerge PR #30809 into master (diff)
parentmgr/telemetry: bump content revision and add a release note (diff)
downloadceph-c9bfbb7a47c32638f7d9ead9a032d636850d4726.tar.xz
ceph-c9bfbb7a47c32638f7d9ead9a032d636850d4726.zip
Merge PR #30724 into master
* refs/pull/30724/head: mgr/telemetry: bump content revision and add a release note telemetry/server: add device report endpoint mgr/telemetry: include device telemetry mgr/devicehealth: factor _get_device_metrics out of show_device_metrics mgr/devicehealth: pull out MAX_SAMPLES Reviewed-by: Dan Mick <dmick@redhat.com>
Diffstat (limited to 'src/telemetry')
-rwxr-xr-xsrc/telemetry/server/ceph_telemetry/app.py3
-rw-r--r--src/telemetry/server/ceph_telemetry/rest/device.py40
2 files changed, 42 insertions, 1 deletions
diff --git a/src/telemetry/server/ceph_telemetry/app.py b/src/telemetry/server/ceph_telemetry/app.py
index f2c2b997377..0d2b5e1d760 100755
--- a/src/telemetry/server/ceph_telemetry/app.py
+++ b/src/telemetry/server/ceph_telemetry/app.py
@@ -2,7 +2,7 @@
import argparse
from flask_restful import Api
from flask import Flask
-from ceph_telemetry.rest import Index, Report
+from ceph_telemetry.rest import Index, Report, Device
def create_app(name):
@@ -10,6 +10,7 @@ def create_app(name):
api = Api(app, catch_all_404s=True)
api.add_resource(Index, '/')
api.add_resource(Report, '/report')
+ api.add_resource(Device, '/device')
return app
diff --git a/src/telemetry/server/ceph_telemetry/rest/device.py b/src/telemetry/server/ceph_telemetry/rest/device.py
new file mode 100644
index 00000000000..02506c0e655
--- /dev/null
+++ b/src/telemetry/server/ceph_telemetry/rest/device.py
@@ -0,0 +1,40 @@
+from flask import request, jsonify
+from flask_restful import Resource
+import datetime
+import hashlib
+import json
+import copy
+import psycopg2
+
+class Device(Resource):
+ def __init__(self, report=None):
+ super(Device, self).__init__()
+ self.report = report
+ with open('/opt/telemetry/pg_pass.txt', 'r') as f:
+ p = f.read()
+ self.pg_password = p.strip()
+
+ def put(self):
+ self.report = request.get_json(force=True)
+
+ self.post_to_postgres()
+
+ return jsonify(status=True)
+
+ def _connect_pg(self):
+ return psycopg2.connect(
+ host='localhost',
+ database='telemetry',
+ user='telemetry',
+ password=self.pg_password,
+ )
+
+ def post_to_postgres(self):
+ conn = self._connect_pg()
+ cur = conn.cursor()
+ for devid, devinfo in self.report:
+ for stamp, report in devinfo:
+ cur.execute(
+ 'INSERT INTO device_report (device_id, report_stamp, report) VALUES (%s,%s,%s) ON CONFLICT DO NOTHING',
+ (devid, stamp, report))
+ conn.commit()