Cleanup config.nodes_of
[check_mk.git] / inventory / lnx_ip_r
blobf5b98c4dd870a17c7dc0d83119197ce7fc9d429d
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 output from agent:
28 # <<<ip_a_r>>>
29 # default via 10.10.0.1 dev wlan0 proto static
30 # 10.10.0.0/16 dev wlan0 proto kernel scope link src 10.10.0.41 metric 9
33 def parse_lnx_ip_route(line):
34 def parse_network(n):
35 if n == "default":
36 return "0.0.0.0/0"
37 return n
39 route = {
40 "target": parse_network(line[0]),
43 line = line[1:]
44 while line:
45 if line[0] == "dev":
46 route.setdefault("type", "local")
47 route["device"] = line[1]
48 line = line[2:]
49 elif line[0] == "via":
50 route["type"] = "gateway"
51 route["gateway"] = line[1]
52 line = line[2:]
53 else:
54 line = line[1:]
56 return route
59 def inv_lnx_ip_r(info):
60 routes = inv_tree_list("networking.routes:")
61 for line in info:
62 routes.append(parse_lnx_ip_route(line))
65 inv_info['lnx_ip_r'] = {
66 "inv_function": inv_lnx_ip_r,