Blob Blame History Raw
From 86e6843a61758fc17b13286c0c928efb97d15227 Mon Sep 17 00:00:00 2001
From: Pavel Moravec <pmoravec@redhat.com>
Date: Sat, 28 Jul 2018 09:45:49 +0200
Subject: [PATCH] [block] collect luksDump for all encrypted devices

Call "cryptsetup luksDump /dev/sd*" for all encrypted devices

Resolves: #1390

Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
---
 sos/plugins/block.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/sos/plugins/block.py b/sos/plugins/block.py
index 3a2d14d3..059686c5 100644
--- a/sos/plugins/block.py
+++ b/sos/plugins/block.py
@@ -19,6 +19,22 @@ class Block(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
     verify_packages = ('util-linux',)
     files = ('/sys/block',)
 
+    def get_luks_devices(self, lsblk_file):
+        out = []
+        try:
+            lsblk_out = open(lsblk_file).read()
+        except IOError:
+            return out
+        for line in lsblk_out.splitlines():
+            # find in output lines like
+            # |-sda2    crypto_LUKS    <uuid>
+            # and separate device name - it will be 1st string on the line
+            # after first '-'
+            if 'crypto_LUKS' in line:
+                dev = line.split()[0].split('-', 1)[1]
+                out.append(dev)
+        return out
+
     def setup(self):
         self.add_cmd_output([
             "lsblk",
@@ -51,4 +67,10 @@ class Block(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
                     "fdisk -l %s" % disk_path
                 ])
 
+        lsblk_file = self.get_cmd_output_now("lsblk -f -a")
+        # for LUKS devices, collect cryptsetup luksDump
+        if lsblk_file:
+            for dev in self.get_luks_devices(lsblk_file):
+                self.add_cmd_output('cryptsetup luksDump /dev/%s' % dev)
+
 # vim: set et ts=4 sw=4 :
-- 
2.17.1