doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

Blame SOURCES/0059-plugins-add-abrt-action-generate-machine-id.patch

a60cd7
From 0e2514743b71f4e0d177b072036884c1d9b72621 Mon Sep 17 00:00:00 2001
a60cd7
From: Jakub Filak <jfilak@redhat.com>
a60cd7
Date: Tue, 16 Sep 2014 15:35:55 +0200
a60cd7
Subject: [ABRT PATCH 59/66] plugins: add abrt-action-generate-machine-id
a60cd7
a60cd7
Enabled by default on RHEL7.
a60cd7
a60cd7
Resolves: rhbz#1140044
a60cd7
a60cd7
Signed-off-by: Jakub Filak <jfilak@redhat.com>
a60cd7
---
a60cd7
 src/daemon/abrt_event.conf                  |  3 ++
a60cd7
 src/plugins/Makefile.am                     |  2 +
a60cd7
 src/plugins/abrt-action-generate-machine-id | 57 +++++++++++++++++++++++++++++
a60cd7
 3 files changed, 62 insertions(+)
a60cd7
 create mode 100644 src/plugins/abrt-action-generate-machine-id
a60cd7
a60cd7
diff --git a/src/daemon/abrt_event.conf b/src/daemon/abrt_event.conf
a60cd7
index 380b312..deda7c7 100644
a60cd7
--- a/src/daemon/abrt_event.conf
a60cd7
+++ b/src/daemon/abrt_event.conf
a60cd7
@@ -92,6 +92,9 @@ EVENT=post-create
a60cd7
         rm sosreport.log
a60cd7
         exit 1
a60cd7
 
a60cd7
+# Example: if you want to include *machineid* in dump directories:
a60cd7
+EVENT=post-create
a60cd7
+    /usr/libexec/abrt-action-generate-machine-id -o $DUMP_DIR/machineid
a60cd7
 
a60cd7
 # Example: if you want to upload data immediately at the moment of a crash:
a60cd7
 #EVENT=post-create
a60cd7
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
a60cd7
index 727dae0..326bb6e 100644
a60cd7
--- a/src/plugins/Makefile.am
a60cd7
+++ b/src/plugins/Makefile.am
a60cd7
@@ -35,6 +35,7 @@ libexec_PROGRAMS = \
a60cd7
     abrt-action-install-debuginfo-to-abrt-cache
a60cd7
 
a60cd7
 libexec_SCRIPTS = \
a60cd7
+    abrt-action-generate-machine-id \
a60cd7
     abrt-action-ureport \
a60cd7
     abrt-gdb-exploitable
a60cd7
 
a60cd7
@@ -91,6 +92,7 @@ EXTRA_DIST = \
a60cd7
     analyze_VMcore.xml.in \
a60cd7
     abrt-action-analyze-core.in \
a60cd7
     abrt-action-analyze-vmcore \
a60cd7
+    abrt-action-generate-machine-id \
a60cd7
     abrt-action-check-oops-for-hw-error \
a60cd7
     abrt-action-save-kernel-data \
a60cd7
     abrt-action-ureport \
a60cd7
diff --git a/src/plugins/abrt-action-generate-machine-id b/src/plugins/abrt-action-generate-machine-id
a60cd7
new file mode 100644
a60cd7
index 0000000..0aea787
a60cd7
--- /dev/null
a60cd7
+++ b/src/plugins/abrt-action-generate-machine-id
a60cd7
@@ -0,0 +1,57 @@
a60cd7
+#!/usr/bin/python
a60cd7
+from argparse import ArgumentParser
a60cd7
+
a60cd7
+import dmidecode
a60cd7
+import hashlib
a60cd7
+
a60cd7
+
a60cd7
+# Generate a machine_id based off dmidecode fields
a60cd7
+def generate_machine_id():
a60cd7
+    dmixml = dmidecode.dmidecodeXML()
a60cd7
+
a60cd7
+    # Fetch all DMI data into a libxml2.xmlDoc object
a60cd7
+    dmixml.SetResultType(dmidecode.DMIXML_DOC)
a60cd7
+    xmldoc = dmixml.QuerySection('all')
a60cd7
+
a60cd7
+    # Do some XPath queries on the XML document
a60cd7
+    dmixp = xmldoc.xpathNewContext()
a60cd7
+
a60cd7
+    # What to look for - XPath expressions
a60cd7
+    keys = ['/dmidecode/SystemInfo/Manufacturer',
a60cd7
+            '/dmidecode/SystemInfo/ProductName',
a60cd7
+            '/dmidecode/SystemInfo/SerialNumber',
a60cd7
+            '/dmidecode/SystemInfo/SystemUUID']
a60cd7
+
a60cd7
+    # Create a sha256 of ^ for machine_id
a60cd7
+    machine_id = hashlib.sha256()
a60cd7
+
a60cd7
+    # Run xpath expressions
a60cd7
+    for k in keys:
a60cd7
+        data = dmixp.xpathEval(k)
a60cd7
+        for d in data:
a60cd7
+            # Update the hash as we find the fields we are looking for
a60cd7
+            machine_id.update(d.get_content())
a60cd7
+
a60cd7
+    del dmixp
a60cd7
+    del xmldoc
a60cd7
+    # Create sha256 digest
a60cd7
+    return machine_id.hexdigest()
a60cd7
+
a60cd7
+
a60cd7
+if __name__ == "__main__":
a60cd7
+    CMDARGS = ArgumentParser(description = "Generate a machine_id based off dmidecode fields")
a60cd7
+    CMDARGS.add_argument('-o', '--output', type=str, help='Output file')
a60cd7
+
a60cd7
+    OPTIONS = CMDARGS.parse_args()
a60cd7
+    ARGS = vars(OPTIONS)
a60cd7
+
a60cd7
+    machineid =  generate_machine_id()
a60cd7
+
a60cd7
+    if ARGS['output']:
a60cd7
+        try:
a60cd7
+            with open(ARGS['output'], 'w') as outfile:
a60cd7
+                outfile.write(machineid)
a60cd7
+        except IOError as ex:
a60cd7
+            print ex
a60cd7
+    else:
a60cd7
+        print machineid
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7