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
import requests
import uuid
import time
-from datetime import datetime
+from datetime import datetime, timedelta
from threading import Event
from collections import defaultdict
'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)',
},
]
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: