From 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 30 Sep 2013 00:03:24 +0200 Subject: Import Nagios Plugins site Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files. --- web/attachments/112621-utils.pm.t | 141 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 web/attachments/112621-utils.pm.t (limited to 'web/attachments/112621-utils.pm.t') diff --git a/web/attachments/112621-utils.pm.t b/web/attachments/112621-utils.pm.t new file mode 100644 index 0000000..630985c --- /dev/null +++ b/web/attachments/112621-utils.pm.t @@ -0,0 +1,141 @@ +#! /usr/bin/perl -w +BEGIN {use File::Basename; use lib(dirname($0) . "/.."); } + +use strict; +use Test::Simple tests => 80; +use utils qw(&check_range); + + +my @tests = +( + # Format: [metric, range, name, expected result] + # + # 'Expected result' is the result expected from check_range: 0 if + # check_range should return 0 (metric is outside of range), 1 if + # check_range should return 1 (metric is inside range). The expected + # result can also be -1, indicating that check_range should exit with + # plugin error code of 'UNKNOWN' after a usage error (caused by an + # invalid range). + + # Check min:max ranges + [-1, '2:4', 'Test 1', 0], + [0, '2:4', 'Test 2', 0], + [1, '2:4', 'Test 3', 0], + [2, '2:4', 'Test 4', 1], + [3, '2:4', 'Test 5', 1], + [4, '2:4', 'Test 6', 1], + [5, '2:4', 'Test 7', 0], + + # Check max ranges + [-1, 2, 'Test 8', 0], + [0, 2, 'Test 9', 1], + [1, 2, 'Test 10', 1], + [2, 2, 'Test 11', 1], + [3, 2, 'Test 12', 0], + + # Check :max ranges + [-1, ':2', 'Test 13', 0], + [0, ':2', 'Test 14', 1], + [1, ':2', 'Test 15', 1], + [2, ':2', 'Test 16', 1], + [3, ':2', 'Test 17', 0], + [-1, '1:', 'Test 18', 0], + + # Check min: ranges + [0, '1:', 'Test 19', 0], + [1, '1:', 'Test 20', 1], + [2, '1:', 'Test 21', 1], + + # Check 0 + [-1, 0, 'Test 22', 0], + [0, 0, 'Test 23', 1], + [1, 0, 'Test 24', 1], + + # Check ~:max ranges + [-1, '~:1', 'Test 25', 1], + [0, '~:1', 'Test 26', 1], + [1, '~:1', 'Test 27', 1], + [2, '~:1', 'Test 28', 0], + + # Check min:max ranges where min and max are the same, including :0 + # which should be equivalent to 0:0. + [-1, '1:1', 'Test 29', 0], + [0, '1:1', 'Test 30', 0], + [1, '1:1', 'Test 31', 1], + [2, '1:1', 'Test 32', 0], + [-1, '0:0', 'Test 33', 0], + [0, '0:0', 'Test 34', 1], + [1, '0:0', 'Test 35', 0], + [-1, ':0', 'Test 36', 0], + [0, ':0', 'Test 37', 1], + [1, ':0', 'Test 38', 0], + + # Check min:max ranges which are invalid + [1, '4:2', 'Test 39', -1], + [1, '~:~', 'Test 40', -1], + + # Check @min:max ranges + [-1, '@2:4', 'Test 1', 1], + [0, '@2:4', 'Test 2', 1], + [1, '@2:4', 'Test 3', 1], + [2, '@2:4', 'Test 4', 0], + [3, '@2:4', 'Test 5', 0], + [4, '@2:4', 'Test 6', 0], + [5, '@2:4', 'Test 7', 1], + + # Check @max ranges + [-1, '@2', 'Test 8', 1], + [0, '@2', 'Test 9', 0], + [1, '@2', 'Test 10', 0], + [2, '@2', 'Test 11', 0], + [3, '@2', 'Test 12', 1], + + # Check @:max ranges + [-1, '@:2', 'Test 13', 1], + [0, '@:2', 'Test 14', 0], + [1, '@:2', 'Test 15', 0], + [2, '@:2', 'Test 16', 0], + [3, '@:2', 'Test 17', 1], + [-1, '@1:', 'Test 18', 1], + + # Check @min: ranges + [0, '@1:', 'Test 19', 1], + [1, '@1:', 'Test 20', 0], + [2, '@1:', 'Test 21', 0], + + # Check @0 + [-1, '@0', 'Test 22', 1], + [0, '@0', 'Test 23', 0], + [1, '@0', 'Test 24', 0], + + # Check @~:max ranges + [-1, '@~:1', 'Test 25', 0], + [0, '@~:1', 'Test 26', 0], + [1, '@~:1', 'Test 27', 0], + [2, '@~:1', 'Test 28', 1], + + # Check @min:max ranges where min and max are the same, including @:0 + # which should be equivalent to @0:0. + [-1, '@1:1', 'Test 29', 1], + [0, '@1:1', 'Test 30', 1], + [1, '@1:1', 'Test 31', 0], + [2, '@1:1', 'Test 32', 1], + [-1, '@0:0', 'Test 33', 1], + [0, '@0:0', 'Test 34', 0], + [1, '@0:0', 'Test 35', 1], + [-1, '@:0', 'Test 36', 1], + [0, '@:0', 'Test 37', 0], + [1, '@:0', 'Test 38', 1], + + # Check @min:max ranges which are invalid + [1, '@4:2', 'Test 39', -1], + [1, '@~:~', 'Test 40', -1], +); + +foreach my $test (@tests) +{ + ok(check_range($test->[0], $test->[1]) == $test->[3],$test->[2]); +} + +exit; + -- cgit v1.2.3-74-g34f1