doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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