2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | Copyright Mathias Kettner 2017 mk@mathias-kettner.de |
10 # +------------------------------------------------------------------+
12 # This file is part of Check_MK.
13 # The official homepage is at http://mathias-kettner.de/check_mk.
15 # check_mk is free software; you can redistribute it and/or modify it
16 # under the terms of the GNU General Public License as published by
17 # the Free Software Foundation in version 2. check_mk is distributed
18 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
19 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
21 # tails. You should have received a copy of the GNU General Public
22 # License along with GNU Make; see the file COPYING. If not, write
23 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
24 # Boston, MA 02110-1301 USA.
27 # .--queries-------------------------------------------------------------.
29 # | __ _ _ _ ___ _ __(_) ___ ___ |
30 # | / _` | | | |/ _ \ '__| |/ _ \/ __| |
31 # | | (_| | |_| | __/ | | | __/\__ \ |
32 # | \__, |\__,_|\___|_| |_|\___||___/ |
34 # '----------------------------------------------------------------------'
37 function get_tag_stats
() {
41 local tags
=($
(echo "$header" |
tr ' ' '\n'))
42 if [ "${#tags[@]}" -ne 0 ] && [ -S "$socket" ];
44 local tags_query
="GET hosts\n"
45 for tag
in "${tags[@]}";
47 tags_query
="${tags_query}Stats: custom_variables ~ TAGS ${tag}\n"
49 echo "Tags|$header|$(echo -e "${tags_query}" | waitmax 3 "/omd/sites/${site}/bin/unixcat" "${socket}")"
54 function get_check_command_stats
() {
58 local service_check_commands
=($
(echo "$header" |
tr ' ' '\n'))
59 if [ "${#service_check_commands[@]}" -ne 0 ] && [ -S "$socket" ];
61 local service_check_commands_query
="GET services\n"
62 for service_check_command
in "${service_check_commands[@]}";
64 service_check_commands_query
="${service_check_commands_query}Stats: check_command ~~ ${service_check_command}$\n"
66 echo "Service check commands|$header|$(echo -e "${service_check_commands_query}" | waitmax 3 "/omd/sites/${site}/bin/unixcat" "${socket}")"
72 # .--main----------------------------------------------------------------.
74 # | _ __ ___ __ _(_)_ __ |
75 # | | '_ ` _ \ / _` | | '_ \ |
76 # | | | | | | | (_| | | | | | |
77 # | |_| |_| |_|\__,_|_|_| |_| |
79 # '----------------------------------------------------------------------'
83 SERVICE_CHECK_COMMANDS
=
86 if [ -e "$MK_CONFDIR/site_object_counts.cfg" ];
88 .
"$MK_CONFDIR/site_object_counts.cfg"
92 if type omd
>/dev
/null
;
94 echo "<<<site_object_counts:sep(124)>>>"
97 sites
=($
(echo "$SITES" |
tr ' ' '\n'))
99 sites
=($
(omd sites | cut
-d' ' -f1))
107 if [ -n "$SERVICE_CHECK_COMMANDS" ];
109 service_check_commands
="$SERVICE_CHECK_COMMANDS"
112 for site
in "${sites[@]}";
114 site_tags
="TAGS_$site"
115 site_tags
=${!site_tags}
116 if [ -n "$tags" ] && [ -n "$site_tags" ];
118 site_tags
="$tags $site_tags"
124 site_service_check_commands
="SERVICE_CHECK_COMMANDS_$site"
125 site_service_check_commands
=${!site_service_check_commands}
126 if [ -n "$service_check_commands" ] && [ -n "$site_service_check_commands" ];
128 site_service_check_commands
="$service_check_commands $site_service_check_commands"
129 elif [ -n "$service_check_commands" ];
131 site_service_check_commands
="$service_check_commands"
134 socket
="/omd/sites/${site}/tmp/run/live"
137 get_tag_stats
"$socket" "$site" "$site_tags"
138 get_check_command_stats
"$socket" "$site" "$site_service_check_commands"