2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2013 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # Example outputs from various systems:
28 # <<<lnx_distro:sep(124)>>>
29 # /etc/debian_version|wheezy/sid
31 # <<<lnx_distro:sep(124)>>>
32 # /etc/lsb-release|DISTRIB_ID=Ubuntu|DISTRIB_RELEASE=12.10|DISTRIB_CODENAME=quantal|DISTRIB_DESCRIPTION="Ubuntu 12.10"
34 # <<<lnx_distro:sep(124)>>>
35 # /etc/redhat-release|Red Hat Enterprise Linux Server release 6.5 (Santiago)
37 # <<<lnx_distro:sep(124)>>>
38 # /etc/redhat-release|Oracle VM server release x.x.x
40 # <<<lnx_distro:sep(124):persist(1399310551)>>>
41 # /etc/SuSE-release|SUSE Linux Enterprise Server 11 (x86_64)|VERSION = 11|PATCHLEVEL = 2
43 # <<<lnx_distro:sep(124):persist(1490598851)>>>
44 # /etc/oracle-release|Oracle LinuxServer release 7.1
47 def inv_lnx_distro(info
):
51 if line
[0].startswith("[[[") and line
[0].endswith("]]]"):
52 filename
= line
[0][3:-3]
53 elif filename
is not None:
54 parsed
.setdefault(filename
, line
)
55 elif filename
is None:
56 # stay compatible to older versions of output
57 parsed
.setdefault(line
[0], line
[1:])
59 node
= inv_tree("software.os.")
60 node
["type"] = "Linux"
61 for file_name
, handler
in [
62 ("/usr/share/cma/version", inv_lnx_parse_cma
),
63 ("/etc/os-release", inv_lnx_parse_os
),
64 ("/etc/gentoo-release", inv_lnx_parse_gentoo
),
65 ("/etc/SuSE-release", inv_lnx_parse_suse
),
66 ("/etc/oracle-release", inv_lnx_parse_oracle_vm_server
),
67 ("/etc/redhat-release", inv_lnx_parse_redhat
),
68 ("/etc/lsb-release", inv_lnx_parse_lsb
),
69 ("/etc/debian_version", inv_lnx_parse_debian
),
71 if file_name
in parsed
:
72 handler(node
, parsed
[file_name
])
76 def inv_lnx_parse_os(node
, line
):
78 if entry
.count("=") == 0:
80 k
, v
= map(lambda x
: x
.replace('"', ''), entry
.split("=", 1))
83 elif k
== "PRETTY_NAME":
85 elif k
== "VERSION_CODENAME":
86 node
["code_name"] = v
.title()
88 node
["vendor"] = v
.title()
91 def inv_lnx_parse_suse(node
, line
):
92 version
= line
[1].split()[-1]
94 patchlevel
= line
[2].split()[-1]
98 node
["vendor"] = "SuSE"
99 node
["version"] = "%s.%s" % (version
, patchlevel
)
100 node
["name"] = "%s.%s" % (line
[0].split('(')[0].strip(), patchlevel
)
102 if node
["version"] == "11.2":
103 node
["code_name"] = "Emerald"
104 elif node
["version"] == "11.3":
105 node
["code_name"] = "Teal"
106 elif node
["version"] == "11.4":
107 node
["code_name"] = "Celadon"
108 elif node
["version"] == "12.1":
109 node
["code_name"] = "Asparagus"
110 elif node
["version"] == "12.2":
111 node
["code_name"] = "Mantis"
112 elif node
["version"] == "12.3":
113 node
["code_name"] = "Darthmouth"
114 elif node
["version"] == "13.1":
115 node
["code_name"] = "Bottle"
118 def inv_lnx_parse_redhat(node
, line
):
120 if entry
.startswith("Oracle"):
121 inv_lnx_parse_oracle_vm_server(node
, line
)
123 parts
= entry
.split("(")
124 left
= parts
[0].strip()
125 node
["code_name"] = parts
[1].rstrip(")")
126 name
, _release
, version
= left
.rsplit(None, 2)
127 if name
.startswith("Red Hat"):
128 node
["vendor"] = "Red Hat"
129 node
["version"] = version
133 def inv_lnx_parse_oracle_vm_server(node
, line
):
134 parts
= line
[0].split(" ")
135 node
["vendor"] = parts
.pop(0)
136 node
["version"] = parts
.pop(-1)
137 node
["name"] = " ".join(parts
[:-1])
140 def inv_lnx_parse_lsb(node
, line
):
142 varname
, value
= entry
.split("=", 1)
143 value
= value
.strip("'").strip('"')
144 if varname
== "DISTRIB_ID":
145 node
["vendor"] = value
146 elif varname
== "DISTRIB_RELEASE":
147 node
["version"] = value
148 elif varname
== "DISTRIB_CODENAME":
149 node
["code_name"] = value
.title()
150 elif varname
== "DISTRIB_DESCRIPTION":
154 # Do not overwrite Ubuntu information
155 def inv_lnx_parse_debian(node
, line
):
157 node
["name"] = "Debian " + entry
158 node
["vendor"] = "Debian"
159 node
["version"] = entry
160 if entry
.startswith("2.0."):
161 node
["code_name"] = "Hamm"
162 elif entry
.startswith("2.1."):
163 node
["code_name"] = "Slink"
164 elif entry
.startswith("2.2."):
165 node
["code_name"] = "Potato"
166 elif entry
.startswith("3.0."):
167 node
["code_name"] = "Woody"
168 elif entry
.startswith("3.1."):
169 node
["code_name"] = "Sarge"
170 elif entry
.startswith("4."):
171 node
["code_name"] = "Etch"
172 elif entry
.startswith("5."):
173 node
["code_name"] = "Lenny"
174 elif entry
.startswith("6."):
175 node
["code_name"] = "Squeeze"
176 elif entry
.startswith("7."):
177 node
["code_name"] = "Wheezy"
178 elif entry
.startswith("8."):
179 node
["code_name"] = "Jessie"
182 def inv_lnx_parse_cma(node
, line
):
183 node
["name"] = "Check_MK Appliance " + line
[0]
184 node
["vendor"] = "Mathias Kettner GmbH"
185 node
["version"] = line
[0]
186 if "code_name" in node
:
187 del node
["code_name"]
190 def inv_lnx_parse_gentoo(node
, line
):
193 node
["vendor"] = "Gentoo"
194 parts
= entry
.split(" ")
195 node
["version"] = parts
.pop(-1)
196 if "code_name" in node
:
197 del node
["code_name"]
200 inv_info
['lnx_distro'] = {
201 "inv_function": inv_lnx_distro
,