1 changed file
check_mapr_cluster_version.pl + | ||
Add comment 1 Plus #!/usr/bin/perl -T
Add comment 2 Plus # nagios: -epn
Add comment 3 Plus #
Add comment 4 Plus # Author: Hari Sekhon
Add comment 5 Plus # Date: 2014-02-19 22:00:59 +0000 (Wed, 19 Feb 2014)
Add comment 6 Plus #
Add comment 7 Plus # https://github.com/harisekhon/nagios-plugins
Add comment 8 Plus #
Add comment 9 Plus # License: see accompanying Hari Sekhon LICENSE file
Add comment 10 Plus #
Add comment 11 Plus # vim:ts=4:sts=4:sw=4:et
Add comment 12 Plus
Add comment 13 Plus $DESCRIPTION = "Nagios Plugin to check the MapR cluster version of a given cluster or all clusters managed by MapR Control System via the MapR Control System REST API
Add comment 14 Plus
Add comment 15 Plus Tested on MapR 4.0.1";
Add comment 16 Plus
Add comment 17 Plus $VERSION = "0.1";
Add comment 18 Plus
Add comment 19 Plus use strict;
Add comment 20 Plus use warnings;
Add comment 21 Plus BEGIN {
Add comment 22 Plus use File::Basename;
Add comment 23 Plus use lib dirname(__FILE__) . "/lib";
Add comment 24 Plus }
Add comment 25 Plus use HariSekhonUtils;
Add comment 26 Plus use HariSekhon::MapR;
Add comment 27 Plus
Add comment 28 Plus $ua->agent("Hari Sekhon $progname version $main::VERSION");
Add comment 29 Plus
Add comment 30 Plus my $expected;
Add comment 31 Plus
Add comment 32 Plus %options = (
Add comment 33 Plus %mapr_options,
Add comment 34 Plus %mapr_option_cluster,
Add comment 35 Plus "e|expected=s" => [ \$expected, "Expected version regex (optional)" ],
Add comment 36 Plus );
Add comment 37 Plus splice @usage_order, 7, 0, 'expected';
Add comment 38 Plus
Add comment 39 Plus get_options();
Add comment 40 Plus
Add comment 41 Plus validate_mapr_options();
Add comment 42 Plus list_clusters();
Add comment 43 Plus $cluster = validate_cluster($cluster) if $cluster;
Add comment 44 Plus
Add comment 45 Plus my $expected_regex = validate_regex($expected) if defined($expected);
Add comment 46 Plus
Add comment 47 Plus vlog2;
Add comment 48 Plus set_timeout();
Add comment 49 Plus
Add comment 50 Plus $status = "OK";
Add comment 51 Plus
Add comment 52 Plus $json = curl_mapr "/dashboard/info", $user, $password;
Add comment 53 Plus
Add comment 54 Plus my @data = get_field_array("data");
Add comment 55 Plus
Add comment 56 Plus my $name;
Add comment 57 Plus my $version;
Add comment 58 Plus my $found;
Add comment 59 Plus foreach(@data){
Add comment 60 Plus $name = get_field2($_, "cluster.name");
Add comment 61 Plus next if $cluster and $name ne $cluster;
Add comment 62 Plus $found++;
Add comment 63 Plus $version = get_field2($_, "version");
Add comment 64 Plus $msg = "cluster '$name' version $version";
Add comment 65 Plus if(defined($expected_regex)){
Add comment 66 Plus unless($version =~ $expected_regex){
Add comment 67 Plus critical;
Add comment 68 Plus $msg .= " (expected: '$expected')";
Add comment 69 Plus }
Add comment 70 Plus }
Add comment 71 Plus $msg .= ", ";
Add comment 72 Plus }
Add comment 73 Plus $msg =~ s/, $//;
Add comment 74 Plus unless($found){
Add comment 75 Plus quit "UNKNOWN", "cluster not found, did you specify a valid cluster name? See --list-clusters";
Add comment 76 Plus }
Add comment 77 Plus
Add comment 78 Plus vlog2;
Add comment 79 Plus quit $status, $msg;
Add comment 80 Plus