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

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