diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-01-30 22:24:31 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-01-30 22:24:31 (GMT) |
commit | e0688a69114c95efaa0fbee8f8e91f6dcc21a1ee (patch) | |
tree | f3f3c0a2ab5a142499e650cc4cc56123649b998f /plugins/tests | |
parent | 795100ae5124915bb647a304d5dfe2ada2f44ab0 (diff) | |
download | monitoring-plugins-e0688a69114c95efaa0fbee8f8e91f6dcc21a1ee.tar.gz |
Clearly defined thresholds & ranges in docs. Added get_status routine. Added
set_thresholds routine. Tests enhanced to check new routines
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1304 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/tests')
-rw-r--r-- | plugins/tests/test_utils.c | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c index 1fda367..5604bac 100644 --- a/plugins/tests/test_utils.c +++ b/plugins/tests/test_utils.c | |||
@@ -29,77 +29,112 @@ const char *progname = "utils"; | |||
29 | int | 29 | int |
30 | main (int argc, char **argv) | 30 | main (int argc, char **argv) |
31 | { | 31 | { |
32 | threshold *range; | 32 | range *range; |
33 | double temp; | 33 | double temp; |
34 | thresholds *thresholds; | ||
35 | int rc; | ||
34 | 36 | ||
35 | plan_tests(40); | 37 | plan_tests(66); |
36 | 38 | ||
37 | range = parse_threshold("6"); | 39 | range = parse_range_string("6"); |
38 | ok( range != NULL, "'6' is valid threshold"); | 40 | ok( range != NULL, "'6' is valid range"); |
39 | ok( range->start == 0, "Start correct"); | 41 | ok( range->start == 0, "Start correct"); |
40 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 42 | ok( range->start_infinity == FALSE, "Not using negative infinity"); |
41 | ok( range->end == 6, "End correct"); | 43 | ok( range->end == 6, "End correct"); |
42 | ok( range->end_infinity == FALSE, "Not using infinity"); | 44 | ok( range->end_infinity == FALSE, "Not using infinity"); |
43 | free(range); | 45 | free(range); |
44 | 46 | ||
45 | range = parse_threshold("-7:23"); | 47 | range = parse_range_string("-7:23"); |
46 | ok( range != NULL, "'-7:23' is valid threshold"); | 48 | ok( range != NULL, "'-7:23' is valid range"); |
47 | ok( range->start == -7, "Start correct"); | 49 | ok( range->start == -7, "Start correct"); |
48 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 50 | ok( range->start_infinity == FALSE, "Not using negative infinity"); |
49 | ok( range->end == 23, "End correct"); | 51 | ok( range->end == 23, "End correct"); |
50 | ok( range->end_infinity == FALSE, "Not using infinity"); | 52 | ok( range->end_infinity == FALSE, "Not using infinity"); |
51 | free(range); | 53 | free(range); |
52 | 54 | ||
53 | range = parse_threshold(":5.75"); | 55 | range = parse_range_string(":5.75"); |
54 | ok( range != NULL, "':5.75' is valid threshold"); | 56 | ok( range != NULL, "':5.75' is valid range"); |
55 | ok( range->start == 0, "Start correct"); | 57 | ok( range->start == 0, "Start correct"); |
56 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 58 | ok( range->start_infinity == FALSE, "Not using negative infinity"); |
57 | ok( range->end == 5.75, "End correct"); | 59 | ok( range->end == 5.75, "End correct"); |
58 | ok( range->end_infinity == FALSE, "Not using infinity"); | 60 | ok( range->end_infinity == FALSE, "Not using infinity"); |
59 | free(range); | 61 | free(range); |
60 | 62 | ||
61 | range = parse_threshold("~:-95.99"); | 63 | range = parse_range_string("~:-95.99"); |
62 | ok( range != NULL, "~:-95.99' is valid threshold"); | 64 | ok( range != NULL, "~:-95.99' is valid range"); |
63 | ok( range->start_infinity == TRUE, "Using negative infinity"); | 65 | ok( range->start_infinity == TRUE, "Using negative infinity"); |
64 | ok( range->end == -95.99, "End correct (with rounding errors)"); | 66 | ok( range->end == -95.99, "End correct (with rounding errors)"); |
65 | ok( range->end_infinity == FALSE, "Not using infinity"); | 67 | ok( range->end_infinity == FALSE, "Not using infinity"); |
66 | free(range); | 68 | free(range); |
67 | 69 | ||
68 | range = parse_threshold("12345678901234567890:"); | 70 | range = parse_range_string("12345678901234567890:"); |
69 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ | 71 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ |
70 | ok( range != NULL, "'12345678901234567890:' is valid threshold"); | 72 | ok( range != NULL, "'12345678901234567890:' is valid range"); |
71 | ok( range->start == temp, "Start correct"); | 73 | ok( range->start == temp, "Start correct"); |
72 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 74 | ok( range->start_infinity == FALSE, "Not using negative infinity"); |
73 | ok( range->end_infinity == TRUE, "Using infinity"); | 75 | ok( range->end_infinity == TRUE, "Using infinity"); |
76 | /* Cannot do a "-1" on temp, as it appears to be same value */ | ||
77 | ok( check_range(temp/1.1, range) == TRUE, "12345678901234567890/1.1 - alert"); | ||
78 | ok( check_range(temp, range) == FALSE, "12345678901234567890 - no alert"); | ||
79 | ok( check_range(temp*2, range) == FALSE, "12345678901234567890*2 - no alert"); | ||
74 | free(range); | 80 | free(range); |
75 | 81 | ||
76 | range = parse_threshold("~:0"); | 82 | range = parse_range_string("~:0"); |
77 | ok( range != NULL, "'~:0' is valid threshold"); | 83 | ok( range != NULL, "'~:0' is valid range"); |
78 | ok( range->start_infinity == TRUE, "Using negative infinity"); | 84 | ok( range->start_infinity == TRUE, "Using negative infinity"); |
79 | ok( range->end == 0, "End correct"); | 85 | ok( range->end == 0, "End correct"); |
80 | ok( range->end_infinity == FALSE, "Not using infinity"); | 86 | ok( range->end_infinity == FALSE, "Not using infinity"); |
81 | ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); | 87 | ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); |
88 | ok( check_range(0.5, range) == TRUE, "0.5 - alert"); | ||
89 | ok( check_range(-10, range) == FALSE, "-10 - no alert"); | ||
90 | ok( check_range(0, range) == FALSE, "0 - no alert"); | ||
82 | free(range); | 91 | free(range); |
83 | 92 | ||
84 | range = parse_threshold("@0:657.8210567"); | 93 | range = parse_range_string("@0:657.8210567"); |
85 | ok( range != 0, "@0:657.8210567' is a valid threshold"); | 94 | ok( range != 0, "@0:657.8210567' is a valid range"); |
86 | ok( range->start == 0, "Start correct"); | 95 | ok( range->start == 0, "Start correct"); |
87 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 96 | ok( range->start_infinity == FALSE, "Not using negative infinity"); |
88 | ok( range->end == 657.8210567, "End correct"); | 97 | ok( range->end == 657.8210567, "End correct"); |
89 | ok( range->end_infinity == FALSE, "Not using infinity"); | 98 | ok( range->end_infinity == FALSE, "Not using infinity"); |
90 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | 99 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); |
100 | ok( check_range(32.88, range) == TRUE, "32.88 - alert"); | ||
101 | ok( check_range(-2, range) == FALSE, "-2 - no alert"); | ||
102 | ok( check_range(657.8210567, range) == TRUE, "657.8210567 - alert"); | ||
103 | ok( check_range(0, range) == TRUE, "0 - alert"); | ||
91 | free(range); | 104 | free(range); |
92 | 105 | ||
93 | range = parse_threshold("1:1"); | 106 | range = parse_range_string("1:1"); |
94 | ok( range != NULL, "'1:1' is a valid threshold"); | 107 | ok( range != NULL, "'1:1' is a valid range"); |
95 | ok( range->start == 1, "Start correct"); | 108 | ok( range->start == 1, "Start correct"); |
96 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 109 | ok( range->start_infinity == FALSE, "Not using negative infinity"); |
97 | ok( range->end == 1, "End correct"); | 110 | ok( range->end == 1, "End correct"); |
98 | ok( range->end_infinity == FALSE, "Not using infinity"); | 111 | ok( range->end_infinity == FALSE, "Not using infinity"); |
112 | ok( check_range(0.5, range) == TRUE, "0.5 - alert"); | ||
113 | ok( check_range(1, range) == FALSE, "1 - no alert"); | ||
114 | ok( check_range(5.2, range) == TRUE, "5.2 - alert"); | ||
99 | free(range); | 115 | free(range); |
100 | 116 | ||
101 | range = parse_threshold("2:1"); | 117 | range = parse_range_string("2:1"); |
102 | ok( range == NULL, "''2:1' rejected"); | 118 | ok( range == NULL, "'2:1' rejected"); |
119 | |||
120 | rc = _set_thresholds(&thresholds, NULL, "80"); | ||
121 | ok( rc == 0, "Thresholds (NULL, '80') set"); | ||
122 | ok( thresholds->warning == NULL, "Warning not set"); | ||
123 | ok( thresholds->critical->end == 80, "Critical set correctly"); | ||
124 | |||
125 | rc = _set_thresholds(&thresholds, "5:33", NULL); | ||
126 | ok( rc == 0, "Thresholds ('5:33', NULL) set"); | ||
127 | ok( thresholds->warning->start == 5, "Warning start set"); | ||
128 | ok( thresholds->warning->end == 33, "Warning end set"); | ||
129 | ok( thresholds->critical == NULL, "Critical not set"); | ||
130 | |||
131 | rc = _set_thresholds(&thresholds, "30", "60"); | ||
132 | ok( rc == 0, "Thresholds ('30', '60') set"); | ||
133 | ok( thresholds->warning->end == 30, "Warning set correctly"); | ||
134 | ok( thresholds->critical->end == 60, "Critical set correctly"); | ||
135 | ok( get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); | ||
136 | ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); | ||
137 | ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); | ||
103 | 138 | ||
104 | return exit_status(); | 139 | return exit_status(); |
105 | } | 140 | } |