vendor and version
Message-ID: <595600c6.VJnJHhgie+hq+g2Q%si(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 3ae5cc40c3915f763808cc0a23648ef481666e35
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3ae5cc40c3915f…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Jun 30 09:30:40 2017 +0200
4878 FIX lnx_distro: Fixed wrong detected distribution name, vendor and version
Change-Id: Id11b82e43413fe7e93cbb5c0967c6995af9d657c
---
.werks/4878 | 21 ++++++
agents/plugins/mk_inventory.linux | 1 -
inventory/lnx_distro | 148 ++++++++++++++++++--------------------
3 files changed, 92 insertions(+), 78 deletions(-)
diff --git a/.werks/4878 b/.werks/4878
new file mode 100644
index 0000000..98aa2bf
--- /dev/null
+++ b/.werks/4878
@@ -0,0 +1,21 @@
+Title: lnx_distro: Fixed wrong detected distribution name, vendor and version
+Level: 1
+Component: inv
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1498568114
+
+The agent plugin {{mk_inventory.linux}} collects
+the content of following release files if available:
+"/etc/gentoo-release",
+"/etc/SuSE-release",
+"/etc/oracle-release",
+"/etc/redhat-release",
+"/etc/lsb-release",
+"/etc/debian_version"
+
+The first match in the related inventory plugin {{lnx_distro}}
+determines name, vendor and version. The type is always "Linux".
diff --git a/agents/plugins/mk_inventory.linux b/agents/plugins/mk_inventory.linux
index ea8a53f..c8ab766 100755
--- a/agents/plugins/mk_inventory.linux
+++ b/agents/plugins/mk_inventory.linux
@@ -61,7 +61,6 @@ then
for f in
{/etc/{oracle-release,debian_version,gentoo-release,lsb-release,redhat-release,SuSE-release},/usr/share/cma/version}
; do
if [ -e $f ] ; then
echo -n "$f|" ; tr \\n \| < $f | sed 's/|$//' ; echo
- break
fi
done
diff --git a/inventory/lnx_distro b/inventory/lnx_distro
index a8575de..7aa3641 100644
--- a/inventory/lnx_distro
+++ b/inventory/lnx_distro
@@ -45,38 +45,34 @@
def inv_lnx_distro(info):
- node = inv_tree("software.os.")
+ parsed = {}
for line in info:
- if line[0] == '/etc/lsb-release':
- inv_lnx_parse_lsb_release(node, line[1:])
- elif line[0] == '/etc/debian_version':
- inv_lnx_parse_debian(node, line[1])
- elif line[0] == '/etc/gentoo-release':
- inv_lnx_parse_gentoo(node, line[1])
- elif line[0] == '/etc/redhat-release':
- if line[1].startswith("Oracle"):
- inv_lnx_parse_oracle_vm_server_release(node, line[1])
- else:
- inv_lnx_parse_redhat_release(node, line[1])
- elif line[0] == '/etc/SuSE-release':
- inv_lnx_parse_suse_release(node, line[1:])
- elif line[0] == '/usr/share/cma/version':
- inv_lnx_parse_cma(node, line[1])
- elif line[0] == '/etc/oracle-release':
- inv_lnx_parse_oracle_vm_server_release(node, line[1])
-
-
-def inv_lnx_parse_suse_release(node, line):
- node["type"] = "linux"
- node["vendor"] = "SuSE"
+ parsed.setdefault(line[0], line[1:])
+ node = inv_tree("software.os.")
+ node["type"] = "Linux"
+ for file_name, handler in [
+ ("/usr/share/cma/version", inv_lnx_parse_cma),
+ ("/etc/gentoo-release", inv_lnx_parse_gentoo),
+ ("/etc/SuSE-release", inv_lnx_parse_suse),
+ ("/etc/oracle-release", inv_lnx_parse_oracle_vm_server),
+ ("/etc/redhat-release", inv_lnx_parse_redhat),
+ ("/etc/lsb-release", inv_lnx_parse_lsb),
+ ("/etc/debian_version", inv_lnx_parse_debian),
+ ]:
+ if file_name in parsed:
+ handler(node, parsed[file_name])
+ break
+
+
+def inv_lnx_parse_suse(node, line):
version = line[1].split()[-1]
-
if len(line) >= 3:
patchlevel = line[2].split()[-1]
else:
patchlevel = "0"
+ node["vendor"] = "SuSE"
node["version"] = "%s.%s" % (version, patchlevel)
node["name"] = "%s.%s" % (line[0].split('(')[0].strip(),
patchlevel)
@@ -96,32 +92,31 @@ def inv_lnx_parse_suse_release(node, line):
node["code_name"] = "Bottle"
-# <<<lnx_distro:sep(124)>>>
-# /etc/redhat-release|Oracle VM server release x.x.x
-def inv_lnx_parse_oracle_vm_server_release(node, line):
- node["type"] = "linux"
- parts = line.split(" ")
+def inv_lnx_parse_redhat(node, line):
+ entry = line[0]
+ if entry.startswith("Oracle"):
+ inv_lnx_parse_oracle_vm_server(node, line)
+ else:
+ parts = entry.split("(")
+ left = parts[0].strip()
+ node["code_name"] = parts[1].rstrip(")")
+ name, _release, version = left.rsplit(None, 2)
+ if name.startswith("Red Hat"):
+ node["vendor"] = "Red Hat"
+ node["version"] = version
+ node["name"] = left
+
+
+def inv_lnx_parse_oracle_vm_server(node, line):
+ parts = line[0].split(" ")
node["vendor"] = parts.pop(0)
node["version"] = parts.pop(-1)
node["name"] = " ".join(parts[:-1])
-def inv_lnx_parse_redhat_release(node, line):
- node["type"] = "linux"
- parts = line.split("(")
- left = parts[0].strip()
- node["code_name"] = parts[1].rstrip(")")
- name, _release, version = left.rsplit(None, 2)
- if name.startswith("Red Hat"):
- node["vendor"] = "Red Hat"
- node["version"] = version
- node["name"] = left
-
-
-def inv_lnx_parse_lsb_release(node, lines):
- node["type"] = "linux"
- for line in lines:
- varname, value = line.split("=", 1)
+def inv_lnx_parse_lsb(node, line):
+ for entry in line:
+ varname, value = entry.split("=", 1)
value = value.strip("'").strip('"')
if varname == "DISTRIB_ID":
node["vendor"] = value
@@ -133,53 +128,52 @@ def inv_lnx_parse_lsb_release(node, lines):
node["name"] = value
+# Do not overwrite Ubuntu information
def inv_lnx_parse_debian(node, line):
- node["type"] = "linux"
- if "name" not in node: # Do not overwrite Ubuntu information
- node["name"] = "Debian " + line
- node["vendor"] = "Debian"
- node["version"] = line
- if line.startswith("2.0."):
- node["code_name"] = "Hamm"
- elif line.startswith("2.1."):
- node["code_name"] = "Slink"
- elif line.startswith("2.2."):
- node["code_name"] = "Potato"
- elif line.startswith("3.0."):
- node["code_name"] = "Woody"
- elif line.startswith("3.1."):
- node["code_name"] = "Sarge"
- elif line.startswith("4."):
- node["code_name"] = "Etch"
- elif line.startswith("5."):
- node["code_name"] = "Lenny"
- elif line.startswith("6."):
- node["code_name"] = "Squeeze"
- elif line.startswith("7."):
- node["code_name"] = "Wheezy"
- elif line.startswith("8."):
- node["code_name"] = "Jessie"
+ entry = line[0]
+ node["name"] = "Debian " + entry
+ node["vendor"] = "Debian"
+ node["version"] = entry
+ if entry.startswith("2.0."):
+ node["code_name"] = "Hamm"
+ elif entry.startswith("2.1."):
+ node["code_name"] = "Slink"
+ elif entry.startswith("2.2."):
+ node["code_name"] = "Potato"
+ elif entry.startswith("3.0."):
+ node["code_name"] = "Woody"
+ elif entry.startswith("3.1."):
+ node["code_name"] = "Sarge"
+ elif entry.startswith("4."):
+ node["code_name"] = "Etch"
+ elif entry.startswith("5."):
+ node["code_name"] = "Lenny"
+ elif entry.startswith("6."):
+ node["code_name"] = "Squeeze"
+ elif entry.startswith("7."):
+ node["code_name"] = "Wheezy"
+ elif entry.startswith("8."):
+ node["code_name"] = "Jessie"
def inv_lnx_parse_cma(node, line):
- node["type"] = "linux"
- node["name"] = "Check_MK Appliance " + line
+ node["name"] = "Check_MK Appliance " + line[1]
node["vendor"] = "Mathias Kettner GmbH"
- node["version"] = line
+ node["version"] = line[1]
if "code_name" in node:
del node["code_name"]
def inv_lnx_parse_gentoo(node, line):
- node["type"] = "linux"
- node["name"] = line
+ entry = line[0]
+ node["name"] = entry
node["vendor"] = "Gentoo"
- parts = line.split(" ")
+ parts = entry.split(" ")
node["version"] = parts.pop(-1)
if "code_name" in node:
del node["code_name"]
inv_info['lnx_distro'] = {
- "inv_function" : inv_lnx_distro,
+ "inv_function": inv_lnx_distro,
}