forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_cloudera_manager_license.pl
executable file
·122 lines (104 loc) · 3.71 KB
/
check_cloudera_manager_license.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
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2014-04-12 22:33:14 +0100 (Sat, 12 Apr 2014)
#
# http://github.com/harisekhon
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check Cloudera Manager license expiry using CM API
Calculates the number of days left on license and compares against given thresholds
Also checks if the license is running free version either 'Cloudera Standard' or 'Cloudera Express' and if the license is in Trial Mode
Tested on Cloudera Manager 4.8.2 and 5.0.0";
$VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use HariSekhon::ClouderaManager;
use POSIX 'floor';
$ua->agent("Hari Sekhon $progname version $main::VERSION");
my $license_free;
my $license_trial;
my $default_warning = 31;
my $default_critical = 15;
$warning = $default_warning;
$critical = $default_critical;
%options = (
%hostoptions,
%useroptions,
%cm_options_tls,
"F|license-free" => [ \$license_free, "Free License OK - Cloudera Standard or Cloudera Express - CM reverts to this after commercial license expiry (default: CRITICAL)" ],
"A|license-trial" => [ \$license_trial, "Trial License OK (default: WARNING)" ],
"w|warning=s" => [ \$warning, "Warning threshold in days (default: $default_warning)" ],
"c|critical=s" => [ \$critical, "Critical threshold in days (default: $default_critical)" ],
);
@usage_order = qw/host port user password tls ssl-CA-path tls-noverify license-free license-trial warning critical/;
get_options();
$host = validate_host($host);
$port = validate_port($port);
$user = validate_user($user);
$password = validate_password($password);
validate_thresholds(1, 1, { "simple" => "lower", "positive" => 1 } );
vlog2;
set_timeout();
$status = "OK";
$url = "$api/cm/license";
try{
cm_query();
};
catch{
if($@ =~ /This installation is currently running (Cloudera (?:Standard|Express))/){
$msg = "licensed as $1";
if($license_free){
$status = "OK"
} else {
$msg .= " (Commercial license expired? Use --license-free if intentionally using free version)";
}
} else {
critical;
$msg = $@;
}
quit $status, $msg;
};
foreach(qw/owner expiration/){
unless(defined($json->{$_})){
quit "UNKNOWN", "$_ field not found in returned license information. $nagios_plugins_support_msg_api";
}
}
if($json->{"owner"} eq "Trial License"){
if($license_trial){
$msg = "trial license, ";
} else {
warning;
$msg = "TRIAL license (use --license-trial if this is ok), ";
}
}
unless($json->{"expiration"} =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.\d+[A-Za-z]?$/){
quit "UNKNOWN", "failed to recognize expiry date format retrieved from Cloudera Manager. API format may have changed or date may be invalid. $nagios_plugins_support_msg";
}
my $year = $1;
my $month = $2;
my $day = $3;
my $hour = $4;
my $min = $5;
my $sec = $6;
my $days_left = floor(timecomponents2days($year, $month, $day, $hour, $min, $sec));
isInt($days_left, 1) or code_error "non-integer returned for days left calculation. $nagios_plugins_support_msg";
vlog2 "calculated $days_left days left on license\n";
plural abs($days_left);
if($days_left < 0){
critical;
$days_left = abs($days_left);
$msg .= "Cloudera Manager LICENSE EXPIRED $days_left day$plural ago'. Expiry Date: '" . $json->{"expiration"} . "'";
} else {
$msg .= "$days_left day$plural remaining on Cloudera Manager license";
$msg .= ". License Expires: '" . $json->{"expiration"} . "'";
check_thresholds($days_left);
}
quit $status, $msg;