From eff32aab979f87c7ed59b8b3843c5c882bc491c8 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 4 Oct 2019 15:03:53 -0500 Subject: [PATCH] mgr/telemetry: include device telemetry - anonymize device id - anonymize host names - strip out the serial number Signed-off-by: Sage Weil --- src/pybind/mgr/devicehealth/module.py | 8 +++-- src/pybind/mgr/telemetry/module.py | 47 +++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/devicehealth/module.py b/src/pybind/mgr/devicehealth/module.py index 1955bec661e71..78bbc3166755f 100644 --- a/src/pybind/mgr/devicehealth/module.py +++ b/src/pybind/mgr/devicehealth/module.py @@ -641,6 +641,8 @@ class Module(MgrModule): except: return -1, '', 'unable to invoke diskprediction local or remote plugin' - def gather_device_report(self): - # write me - return {} + def get_recent_device_metrics(self, devid, min_sample): + return self._get_device_metrics(devid, min_sample=min_sample) + + def get_time_format(self): + return TIME_FORMAT diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index 769fc72bc62a5..8a260b27176cd 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -11,7 +11,7 @@ import re import requests import uuid import time -from datetime import datetime +from datetime import datetime, timedelta from threading import Event from collections import defaultdict @@ -129,7 +129,7 @@ class Module(MgrModule): 'name': 'channel_device', 'type': 'bool', 'default': True, - 'description': 'Share device health metrics (e.g., SMART data)', + 'description': 'Share device health metrics (e.g., SMART data, minus potentially identifying info like serial numbers)', }, ] @@ -293,9 +293,50 @@ class Module(MgrModule): def gather_device_report(self): try: - return self.remote('devicehealth', 'gather_device_report') + time_format = self.remote('devicehealth', 'get_time_format') except: return None + cutoff = datetime.utcnow() - timedelta(hours=self.interval * 2) + min_sample = cutoff.strftime(time_format) + + devices = self.get('devices')['devices'] + + res = {} + for d in devices: + devid = d['devid'] + try: + m = self.remote('devicehealth', 'get_recent_device_metrics', + devid, min_sample) + except: + continue + + # anonymize host id + try: + host = d['location'][0]['host'] + except: + continue + anon_host = self.get_store('host-id/%s' % host) + if not anon_host: + anon_host = str(uuid.uuid1()) + self.set_store('host-id/%s' % host, anon_host) + m['host_id'] = anon_host + + # anonymize device id + (vendor, model, serial) = devid.split('_') + anon_devid = self.get_store('devid-id/%s' % devid) + if not anon_devid: + anon_devid = '%s_%s_%s' % (vendor, model, uuid.uuid1()) + self.set_store('devid-id/%s' % devid, anon_devid) + + self.log.info('devid %s / %s, host %s / %s' % (devid, anon_devid, + host, anon_host)) + + # anonymize the smartctl report itself + for k in ['serial_number']: + m.pop(k) + + res[anon_devid] = m + return res def compile_report(self, channels=[]): if not channels: -- 2.39.5