summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_swap.t
blob: 68946f6dea80eafe3e92601c0f9f5ef9e2a849ca (plain)
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
#! /usr/bin/perl -w -I ..
#
# Swap Space Tests via check_swap
#
#

use strict;
use warnings;
use Test::More tests => 21;
use NPTest;
use JSON;

my $result;
my $outputFormat = '--output-format mp-test-json';
my $output;
my $message = '/^[0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';

$result = NPTest->testCmd( "./check_swap $outputFormat" );					# Always OK
cmp_ok( $result->return_code, "==", 0, "Always OK" );
is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct");
like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");

$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" );		# 1 MB free
cmp_ok( $result->return_code, "==", 0, "Always OK" );
is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct");
like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");

$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" );			# 1% free
cmp_ok( $result->return_code, "==", 0, "Always OK" );
is($result->{'mp_test_result'}->{'state'}, "OK", "State was correct");
like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");

$result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" );			# 100% (always critical)
cmp_ok( $result->return_code, "==", 0, "Always OK" );
is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct");
like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");

$result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" );			# 100% (always warn)
cmp_ok( $result->return_code, "==", 0, "Always OK" );
is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct");
like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");

$result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" );				# 100% (single threshold, always warn)
cmp_ok( $result->return_code, "==", 0, "Always OK" );
is($result->{'mp_test_result'}->{'state'}, "WARNING", "State was correct");
like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");

$result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" );				# 100% (single threshold, always critical)
cmp_ok( $result->return_code, "==", 0, "Always OK" );
is($result->{'mp_test_result'}->{'state'}, "CRITICAL", "State was correct");
like($result->{'mp_test_result'}->{'checks'}->[0]->{'output'}, $message, "Output was correct");