Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / agents / plugins / mk_site_object_counts
blob8241a69f859ddd1d30a046a914751ab8ba3bd311
1 #!/bin/bash
2 # +------------------------------------------------------------------+
3 # | ____ _ _ __ __ _ __ |
4 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
5 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
6 # | | |___| | | | __/ (__| < | | | | . \ |
7 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 # | |
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-------------------------------------------------------------.
28 # | _ |
29 # | __ _ _ _ ___ _ __(_) ___ ___ |
30 # | / _` | | | |/ _ \ '__| |/ _ \/ __| |
31 # | | (_| | |_| | __/ | | | __/\__ \ |
32 # | \__, |\__,_|\___|_| |_|\___||___/ |
33 # | |_| |
34 # '----------------------------------------------------------------------'
37 function get_tag_stats () {
38 local socket="$1"
39 local site="$2"
40 local header="$3"
41 local tags=($(echo "$header" | tr ' ' '\n'))
42 if [ "${#tags[@]}" -ne 0 ] && [ -S "$socket" ];
43 then
44 local tags_query="GET hosts\n"
45 for tag in "${tags[@]}";
47 tags_query="${tags_query}Stats: custom_variables ~ TAGS ${tag}\n"
48 done
49 echo "Tags|$header|$(echo -e "${tags_query}" | waitmax 3 "/omd/sites/${site}/bin/unixcat" "${socket}")"
54 function get_check_command_stats () {
55 local socket="$1"
56 local site="$2"
57 local header="$3"
58 local service_check_commands=($(echo "$header" | tr ' ' '\n'))
59 if [ "${#service_check_commands[@]}" -ne 0 ] && [ -S "$socket" ];
60 then
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"
65 done
66 echo "Service check commands|$header|$(echo -e "${service_check_commands_query}" | waitmax 3 "/omd/sites/${site}/bin/unixcat" "${socket}")"
72 # .--main----------------------------------------------------------------.
73 # | _ |
74 # | _ __ ___ __ _(_)_ __ |
75 # | | '_ ` _ \ / _` | | '_ \ |
76 # | | | | | | | (_| | | | | | |
77 # | |_| |_| |_|\__,_|_|_| |_| |
78 # | |
79 # '----------------------------------------------------------------------'
81 SITES=
82 TAGS=
83 SERVICE_CHECK_COMMANDS=
86 if [ -e "$MK_CONFDIR/site_object_counts.cfg" ];
87 then
88 . "$MK_CONFDIR/site_object_counts.cfg"
92 if type omd >/dev/null;
93 then
94 echo "<<<site_object_counts:sep(124)>>>"
95 if [ -n "$SITES" ];
96 then
97 sites=($(echo "$SITES" | tr ' ' '\n'))
98 else
99 sites=($(omd sites | cut -d' ' -f1))
102 if [ -n "$TAGS" ];
103 then
104 tags="$TAGS"
107 if [ -n "$SERVICE_CHECK_COMMANDS" ];
108 then
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" ];
117 then
118 site_tags="$tags $site_tags"
119 elif [ -n "$tags" ];
120 then
121 site_tags="$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" ];
127 then
128 site_service_check_commands="$service_check_commands $site_service_check_commands"
129 elif [ -n "$service_check_commands" ];
130 then
131 site_service_check_commands="$service_check_commands"
134 socket="/omd/sites/${site}/tmp/run/live"
136 echo "[[[$site]]]"
137 get_tag_stats "$socket" "$site" "$site_tags"
138 get_check_command_stats "$socket" "$site" "$site_service_check_commands"
139 done