2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 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.
29 import cmk
.utils
.tty
as tty
30 import cmk
.utils
.render
33 import cmk_base
.config
as config
34 import cmk_base
.core_config
as core_config
35 import cmk_base
.console
as console
36 import cmk_base
.data_sources
as data_sources
37 import cmk_base
.ip_lookup
as ip_lookup
38 import cmk_base
.check_table
as check_table
39 import cmk_base
.checking
as checking
42 def dump_host(hostname
):
43 config_cache
= config
.get_config_cache()
44 host_config
= config_cache
.get_host_config(hostname
)
47 if config
.is_cluster(hostname
):
49 add_txt
= " (cluster of " + (", ".join(config
.nodes_of(hostname
))) + ")"
54 "%s%s%s%-78s %s\n" % (color
, tty
.bold
, tty
.white
, hostname
+ add_txt
, tty
.normal
))
56 ipaddress
= _ip_address_for_dump_host(hostname
)
59 if not config
.is_ipv4v6_host(hostname
):
62 ipv6_primary
= config
.is_ipv6_primary(hostname
)
65 secondary
= _ip_address_for_dump_host(hostname
, 4)
67 secondary
= _ip_address_for_dump_host(hostname
, 6)
71 addresses
= "%s, %s" % (ipaddress
, secondary
)
73 addresses
+= " (Primary: IPv6)"
75 addresses
+= " (Primary: IPv4)"
77 console
.output(tty
.yellow
+ "Addresses: " + tty
.normal
+
78 (addresses
if addresses
is not None else "No IP") + "\n")
80 tag_template
= tty
.bold
+ "[" + tty
.normal
+ "%s" + tty
.bold
+ "]" + tty
.normal
82 (tag_template
% ":".join(t
)) for t
in sorted(config_cache
.tags_of_host(hostname
).items())
84 console
.output(tty
.yellow
+ "Tags: " + tty
.normal
+ ", ".join(tags
) + "\n")
85 if config
.is_cluster(hostname
):
86 parents_list
= config
.nodes_of(hostname
)
88 parents_list
= config
.parents_of(hostname
)
89 if len(parents_list
) > 0:
90 console
.output(tty
.yellow
+ "Parents: " + tty
.normal
+
91 ", ".join(parents_list
) + "\n")
92 console
.output(tty
.yellow
+ "Host groups: " + tty
.normal
+
93 cmk_base
.utils
.make_utf8(", ".join(config
.hostgroups_of(hostname
))) + "\n")
94 console
.output(tty
.yellow
+ "Contact groups: " + tty
.normal
+
95 cmk_base
.utils
.make_utf8(", ".join(config
.contactgroups_of(hostname
))) + "\n")
98 sources
= data_sources
.DataSources(hostname
, ipaddress
)
99 for source
in sources
.get_data_sources():
100 agenttypes
.append(source
.describe())
102 if host_config
.is_ping_host
:
103 agenttypes
.append('PING only')
105 console
.output(tty
.yellow
+ "Agent mode: " + tty
.normal
)
106 console
.output(sources
.describe_data_sources() + "\n")
108 console
.output(tty
.yellow
+ "Type of agent: " + tty
.normal
)
109 if len(agenttypes
) == 1:
110 console
.output(agenttypes
[0] + "\n")
112 console
.output("\n ")
113 console
.output("\n ".join(agenttypes
) + "\n")
115 console
.output(tty
.yellow
+ "Services:" + tty
.normal
+ "\n")
116 check_items
= check_table
.get_sorted_check_table(hostname
)
118 headers
= ["checktype", "item", "params", "description", "groups"]
119 colors
= [tty
.normal
, tty
.blue
, tty
.normal
, tty
.green
, tty
.normal
]
120 if config
.service_dependencies
!= []:
121 headers
.append("depends on")
122 colors
.append(tty
.magenta
)
124 tty
.print_table(headers
, colors
, [[
126 cmk_base
.utils
.make_utf8(item
),
127 _evaluate_params(params
),
128 cmk_base
.utils
.make_utf8(description
),
129 cmk_base
.utils
.make_utf8(",".join(
130 config_cache
.service_extra_conf(hostname
, description
, config
.service_groups
))),
132 ] for checktype
, item
, params
, description
, deps
in check_items
], " ")
135 def _evaluate_params(params
):
136 if not isinstance(params
, cmk_base
.config
.TimespecificParamList
):
139 current_params
= checking
.determine_check_params(params
)
140 return "Timespecific parameters at %s: %r" % (cmk
.utils
.render
.date_and_time(time
.time()),
144 def _ip_address_for_dump_host(hostname
, family
=None):
145 if config
.is_cluster(hostname
):
147 ipaddress
= ip_lookup
.lookup_ip_address(hostname
, family
)
152 ipaddress
= ip_lookup
.lookup_ip_address(hostname
, family
)
154 ipaddress
= core_config
.fallback_ip_for(hostname
, family
)