def _info(disk): attributes = extended_info(disk.name, disk.smart_options) cap = capabilities(disk.name, disk.smart_options) e_summary, e_lines = error_logs(disk.name, disk.smart_options) smartid = info(disk.name, disk.smart_options) test_d, log_lines = test_logs(disk.name, disk.smart_options) ts = datetime.utcnow().replace(tzinfo=utc) si = SMARTInfo(disk=disk, toc=ts) si.save() for k in sorted(attributes.keys(), reverse=True): t = attributes[k] sa = SMARTAttribute(info=si, aid=t[0], name=t[1], flag=t[2], normed_value=t[3], worst=t[4], threshold=t[5], atype=t[6], updated=t[7], failed=t[8], raw_value=t[9]) sa.save() for c in sorted(cap.keys(), reverse=True): t = cap[c] SMARTCapability(info=si, name=c, flag=t[0], capabilities=t[1]).save() for enum in sorted(e_summary.keys(), key=int, reverse=True): l = e_summary[enum] SMARTErrorLogSummary(info=si, error_num=enum, lifetime_hours=l[0], state=l[1], etype=l[2], details=l[3]).save() for l in e_lines: SMARTErrorLog(info=si, line=l).save() for tnum in sorted(test_d.keys()): t = test_d[tnum] tlen = len(t) if (tlen < 5): [t.append('') for i in range(tlen, 5)] for i in range(2, 4): try: t[i] = int(t[i]) except: t[i] = -1 SMARTTestLog(info=si, test_num=tnum, description=t[0], status=t[1], pct_completed=t[2], lifetime_hours=t[3], lba_of_first_error=t[4]).save() for l in log_lines: SMARTTestLogDetail(info=si, line=l).save() SMARTIdentity(info=si, model_family=smartid[0], device_model=smartid[1], serial_number=smartid[2], world_wide_name=smartid[3], firmware_version=smartid[4], capacity=smartid[5], sector_size=smartid[6], rotation_rate=smartid[7], in_smartdb=smartid[8], ata_version=smartid[9], sata_version=smartid[10], scanned_on=smartid[11], supported=smartid[12], enabled=smartid[13], version=smartid[14], assessment=smartid[15]).save() return Response(SMARTInfoSerializer(si).data)