abrt/0032-plugins-add-abrt-action-generate-machine-id.patch
Jakub Filak 55686befa2 upstream git snapshot
Resolves: #1141485
2014-10-01 16:41:18 +02:00

116 lines
3.5 KiB
Diff

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