-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlnx_distro
130 lines (116 loc) · 4.93 KB
/
lnx_distro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2013 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
# Example outputs from various systems:
# <<<lnx_distro:sep(124)>>>
# /etc/debian_version|wheezy/sid
# <<<lnx_distro:sep(124)>>>
# /etc/lsb-release|DISTRIB_ID=Ubuntu|DISTRIB_RELEASE=12.10|DISTRIB_CODENAME=quantal|DISTRIB_DESCRIPTION="Ubuntu 12.10"
# <<<lnx_distro:sep(124)>>>
# /etc/redhat-release|Red Hat Enterprise Linux Server release 6.5 (Santiago)
# <<<lnx_distro:sep(124):persist(1399310551)>>>
# /etc/SuSE-release|SUSE Linux Enterprise Server 11 (x86_64)|VERSION = 11|PATCHLEVEL = 2
def inv_lnx_distro(info):
node = inv_tree("software.os.")
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/redhat-release':
inv_lnx_parse_redhat_release(node, line[1])
elif line[0] == '/etc/SuSE-release':
inv_lnx_parse_suse_release(node, line[1:])
def inv_lnx_parse_suse_release(node, line):
node["type"] = "linux"
node["vendor"] = "SuSE"
version = "%s.%s" % (line[1].split()[-1], line[2].split()[-1])
node["version"] = version
if version == "11.2":
node["code_name"] = "Emerald"
elif version == "11.3":
node["code_name"] = "Teal"
elif version == "11.4":
node["code_name"] = "Celadon"
elif version == "12.1":
node["code_name"] = "Asparagus"
elif version == "12.2":
node["code_name"] = "Mantis"
elif version == "12.3":
node["code_name"] = "Darthmouth"
elif version == "13.1":
node["code_name"] = "Bottle"
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)
value = value.strip("'").strip('"')
if varname == "DISTRIB_ID":
node["vendor"] = value
elif varname == "DISTRIB_RELEASE":
node["version"] = value
elif varname == "DISTRIB_CODENAME":
node["code_name"] = value.title()
elif varname == "DISTRIB_DESCRIPTION":
node["name"] = value
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"
inv_info['lnx_distro'] = {
"inv_function" : inv_lnx_distro,
}