-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_element_cluster_performance.pl
executable file
·79 lines (59 loc) · 2.08 KB
/
check_element_cluster_performance.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
#!/usr/bin/perl
# nagios: -epn
# --
# check_element_cluster_performance - Check NetApp ElementOS Cluster Performance
# Copyright (C) 2019 Alexander Krogloth, git@krogloth.de
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --
use strict;
use warnings;
use Encode qw(encode_utf8);
use HTTP::Request ();
use JSON::MaybeXS qw(encode_json decode_json);
use Data::Dumper;
use LWP::UserAgent;
use Getopt::Long;
GetOptions(
'hostname=s' => \my $Hostname,
'username=s' => \my $Username,
'password=s' => \my $Password,
'help|?' => sub { exec perldoc => -F => $0 or die "Cannot execute perldoc: $!\n"; },
) or Error("$0: Error in command line arguments\n");
sub Error {
print "$0: " . $_[0] . "\n";
exit 2;
}
Error('Option --hostname needed!') unless $Hostname;
Error('Option --username needed!') unless $Username;
Error('Option --password needed!') unless $Password;
sub connect_api {
my $method = shift;
my $browser = LWP::UserAgent->new;
$browser->ssl_opts(SSL_verify_mode => 0);
$browser->ssl_opts(verify_hostname => 0);
my $json = {
method => $method,
};
my $header = ['Content-Type' => 'application/json; charset=UTF-8'];
my $encoded_data = encode_utf8(encode_json($json));
my $req = HTTP::Request->new( POST => "https://$Hostname/json-rpc/11.3/", $header, $encoded_data );
$req->authorization_basic( $Username, $Password );
my $page = $browser->request( $req );
my $content = $page->decoded_content;
my $student = decode_json $content;
return $student;
}
my $output = connect_api("GetClusterStats");
my $stats = $output->{'result'}->{'clusterStats'};
my $cluster_util = $stats->{'clusterUtilization'}*100;
$cluster_util = sprintf("%.2f", $cluster_util);
if($cluster_util > 75){
print "WARNING: high cluster performance utilization ($cluster_util %)\n";
exit 2;
} else {
print "OK: cluster performance utilization ($cluster_util %)\n";
exit 0;
}