forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_cloudera_manager_config_validation.pl
executable file
·223 lines (190 loc) · 6.28 KB
/
check_cloudera_manager_config_validation.pl
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2014-04-13 20:58:38 +0100 (Sun, 13 Apr 2014)
#
# https://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
# still calling v1 for compatability with older CM versions
#
# http://cloudera.github.io/cm_api/apidocs/v1/index.html
$DESCRIPTION = "Nagios Plugin to check Cloudera Manager config validation for services/roles via CM Rest API
Use verbose mode to print explanations for any non-OK configs if available
You may need to upgrade to Cloudera Manager 4.6 for the Standard Edition (free) to allow the API to be used, but it should work on all versions of Cloudera Manager Enterprise Edition
This is still using v1 of the API for compatability purposes
Tested on Cloudera Manager 5.0.0, 5.7.0";
our $VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use HariSekhon::ClouderaManager;
$ua->agent("Hari Sekhon $progname version $main::VERSION");
my $stale = 0;
my $validate = 0;
my $cm = 0;
$api = "/api/v1";
%options = (
%hostoptions,
%useroptions,
%cm_options,
%cm_options_list,
"CM" => [ \$cm, "Cloudera Manager config" ],
);
delete $options{"I|hostId=s"};
delete $options{"activityId=s"};
delete $options{"N|nameservice=s"};
@usage_order = qw/host port user password tls ssl-CA-path tls-noverify cluster service hostId activityId nameservice roleId CM CM-mgmt list-activities list-clusters list-hosts list-nameservices list-roles list-services list-users/;
get_options();
$host = validate_host($host);
$port = validate_port($port);
$user = validate_user($user);
$password = validate_password($password);
validate_thresholds();
vlog2;
set_timeout();
$status = "OK";
list_cm_components();
if($cm){
if($cluster or $service or $hostid or $cm_mgmt){
usage "cannot mix --cluster/--service/--host/--CM-mgmt and --CM";
}
$url .= "$api/cm";
} elsif($cm_mgmt){
if($cluster or $service or $hostid or $cm){
usage "cannot mix --cluster/--service/--host/--CM and --CM-mgmt";
}
$url .= "$api/cm/service";
if(defined($role)){
$url .= "/roles/$role";
}
} else {
validate_cm_cluster_options();
}
$url .= "/config?view=full";
cm_query();
my $shortrole;
if($cm){
$msg = "Cloudera Manager";
} elsif(($cluster and $service) or $cm_mgmt){
if($cm_mgmt){
$msg = "Cloudera Manager Mgmt service";
} else {
$msg = "cluster '$cluster' service '$service'";
}
if($role){
$role =~ /^[^-]+-([^-]+)-/ or quit "UNKNOWN", "unknown role not in expected format. $nagios_plugins_support_msg";
$shortrole = $1;
if($verbose){
$msg .= " role '$role'";
} else {
$msg .= " role '$shortrole'";
}
}
} elsif($hostid){
$msg = "host '$hostid'";
} else {
usage "must specify one of: --hostId, --cluster/--service or --CM-mgmt and optionally --role, --CM";
}
check_cm_field("items");
my $validationState;
my $validationMessage;
my $ok_count = 0;
my %warning_configs;
my %error_configs;
my %unknown_configs;
sub parse_config_states($@){
my $role = shift;
my @items = shift;
foreach my $item (@{$json->{"items"}}){
foreach(qw/name validationState/){
$item->{$_} or quit "UNKNOWN", "'$_' field not found for configuration item. $nagios_plugins_support_msg_api";
}
$validationState = $item->{"validationState"};
$validationMessage = ( defined($json->{"validationMessage"}) ? $json->{"validationMessage"} : "no validationMessage" );
if($validationState eq "OK"){
$ok_count++;
} elsif($validationState eq "WARNING"){
warning;
$warning_configs{$role}{$item->{"name"}} = $validationMessage;
} elsif($validationState eq "ERROR"){
critical;
$error_configs{$role}{$item->{"name"}} = $validationMessage;
} else {
unknown;
$unknown_configs{$role}{$item->{"name"}} = $validationMessage;
}
}
}
if(defined($json->{"roleTypeConfigs"})){
isArray($json->{"roleTypeConfigs"}) or quit "UNKNOWN", "roleTypeConfigs is not an array! $nagios_plugins_support_msg_api";
foreach(@{$json->{"roleTypeConfigs"}}){
defined($_->{"roleType"}) or quit "UNKNOWN", "roleType not defined. $nagios_plugins_support_msg_api";
my $role = $_->{"roleType"};
parse_config_states($role, @{$_->{"items"}});
}
}
parse_config_states("", @{$json->{"items"}});
my $warning_count = 0;
foreach(keys %warning_configs){
$warning_count += scalar keys %{$warning_configs{$_}};
}
my $error_count = 0;
foreach(keys %error_configs){
$error_count += scalar keys %{$error_configs{$_}};
}
my $unknown_count = 0;
foreach(keys %unknown_configs){
$unknown_count += scalar keys %{$unknown_configs{$_}};
}
quit "UNKNOWN", "failed to validate any configs. $nagios_plugins_support_msg_api" unless ($ok_count + $warning_count + $error_count + $unknown_count);
$msg .= " config items: $ok_count OK";
if($warning_count){
$msg .= ", $warning_count WARNING";
if($verbose){
$msg .= " (";
foreach my $role (sort keys %warning_configs){
$msg .= "[$role: " if $role;
foreach(sort keys %{$warning_configs{$role}}){
$msg .= "$_='$warning_configs{$role}{$_}', ";
}
$msg =~ s/, $/], / if $role;
}
$msg =~ s/, $/)/;
}
}
if($error_count){
$msg .= ", $error_count ERROR";
if($verbose){
$msg .= " (";
foreach my $role (sort keys %error_configs){
$msg .= "[$role: " if $role;
foreach(sort keys %{$error_configs{$role}}){
$msg .= "$_='$error_configs{$role}{$_}', ";
}
$msg =~ s/, $/], / if $role;
}
$msg =~ s/, $/)/;
}
}
if($unknown_count){
$msg .= ", $unknown_count UNKKNOWN";
if($verbose){
$msg .= " (";
foreach my $role (sort keys %unknown_configs){
$msg .= "[$role: " if $role;
foreach(sort keys %{$unknown_configs{$role}}){
$msg .= "$_='$unknown_configs{$role}{$_}', ";
}
$msg =~ s/, $/], / if $role;
}
$msg =~ s/, $/)/;
}
}
quit $status, $msg;