diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2026-04-06 11:55:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-06 11:55:27 +0200 |
| commit | c57381d789fb246602966fccfcb80131a7fb0461 (patch) | |
| tree | 2087b6db4410047c93cd2e2a4fb84d2486238d36 /plugins | |
| parent | a71ce153082565e5728424749475593dc0623492 (diff) | |
| download | monitoring-plugins-c57381d789fb246602966fccfcb80131a7fb0461.tar.gz | |
Revert check_disk performance data back to used space (#2243)
* Implement simple output shortcut for ranges
If ranges start with zero (e.g. 0:10), the zero and the colon
can be left out.
This patch implements this by default, since some systems (icinga2)
do not fully implement the whole range format and this reduces errors
in the common case of just an upper border.
* switch check_disk perfdata back to used space
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_disk.c | 58 | ||||
| -rw-r--r-- | plugins/t/check_disk.t | 213 |
2 files changed, 160 insertions, 111 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 0d941f25..73fe815e 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
| @@ -933,31 +933,43 @@ void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units, | |||
| 933 | 933 | ||
| 934 | if (warn_freespace_units) { | 934 | if (warn_freespace_units) { |
| 935 | tmp = mp_parse_range_string(warn_freespace_units); | 935 | tmp = mp_parse_range_string(warn_freespace_units); |
| 936 | tmp.range.start = mp_create_pd_value(0); | ||
| 937 | tmp.range.start_infinity = false; | ||
| 936 | path->freespace_units = mp_thresholds_set_warn(path->freespace_units, tmp.range); | 938 | path->freespace_units = mp_thresholds_set_warn(path->freespace_units, tmp.range); |
| 937 | } | 939 | } |
| 938 | 940 | ||
| 939 | if (crit_freespace_units) { | 941 | if (crit_freespace_units) { |
| 940 | tmp = mp_parse_range_string(crit_freespace_units); | 942 | tmp = mp_parse_range_string(crit_freespace_units); |
| 943 | tmp.range.start = mp_create_pd_value(0); | ||
| 944 | tmp.range.start_infinity = false; | ||
| 941 | path->freespace_units = mp_thresholds_set_crit(path->freespace_units, tmp.range); | 945 | path->freespace_units = mp_thresholds_set_crit(path->freespace_units, tmp.range); |
| 942 | } | 946 | } |
| 943 | 947 | ||
| 944 | if (warn_freespace_percent) { | 948 | if (warn_freespace_percent) { |
| 945 | tmp = mp_parse_range_string(warn_freespace_percent); | 949 | tmp = mp_parse_range_string(warn_freespace_percent); |
| 950 | tmp.range.start = mp_create_pd_value(0); | ||
| 951 | tmp.range.start_infinity = false; | ||
| 946 | path->freespace_percent = mp_thresholds_set_warn(path->freespace_percent, tmp.range); | 952 | path->freespace_percent = mp_thresholds_set_warn(path->freespace_percent, tmp.range); |
| 947 | } | 953 | } |
| 948 | 954 | ||
| 949 | if (crit_freespace_percent) { | 955 | if (crit_freespace_percent) { |
| 950 | tmp = mp_parse_range_string(crit_freespace_percent); | 956 | tmp = mp_parse_range_string(crit_freespace_percent); |
| 957 | tmp.range.start = mp_create_pd_value(0); | ||
| 958 | tmp.range.start_infinity = false; | ||
| 951 | path->freespace_percent = mp_thresholds_set_crit(path->freespace_percent, tmp.range); | 959 | path->freespace_percent = mp_thresholds_set_crit(path->freespace_percent, tmp.range); |
| 952 | } | 960 | } |
| 953 | 961 | ||
| 954 | if (warn_freeinodes_percent) { | 962 | if (warn_freeinodes_percent) { |
| 955 | tmp = mp_parse_range_string(warn_freeinodes_percent); | 963 | tmp = mp_parse_range_string(warn_freeinodes_percent); |
| 964 | tmp.range.start = mp_create_pd_value(0); | ||
| 965 | tmp.range.start_infinity = false; | ||
| 956 | path->freeinodes_percent = mp_thresholds_set_warn(path->freeinodes_percent, tmp.range); | 966 | path->freeinodes_percent = mp_thresholds_set_warn(path->freeinodes_percent, tmp.range); |
| 957 | } | 967 | } |
| 958 | 968 | ||
| 959 | if (crit_freeinodes_percent) { | 969 | if (crit_freeinodes_percent) { |
| 960 | tmp = mp_parse_range_string(crit_freeinodes_percent); | 970 | tmp = mp_parse_range_string(crit_freeinodes_percent); |
| 971 | tmp.range.start = mp_create_pd_value(0); | ||
| 972 | tmp.range.start_infinity = false; | ||
| 961 | path->freeinodes_percent = mp_thresholds_set_crit(path->freeinodes_percent, tmp.range); | 973 | path->freeinodes_percent = mp_thresholds_set_crit(path->freeinodes_percent, tmp.range); |
| 962 | } | 974 | } |
| 963 | } | 975 | } |
| @@ -1182,14 +1194,22 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1182 | humanize_byte_value((unsigned long long)measurement_unit.total_bytes, false)); | 1194 | humanize_byte_value((unsigned long long)measurement_unit.total_bytes, false)); |
| 1183 | } | 1195 | } |
| 1184 | 1196 | ||
| 1185 | mp_perfdata used_space = perfdata_init(); | 1197 | // Free space just internally for computation |
| 1186 | used_space.label = measurement_unit.name; | 1198 | mp_perfdata free_space_pd = perfdata_init(); |
| 1187 | used_space.value = mp_create_pd_value(measurement_unit.free_bytes); | 1199 | free_space_pd.label = measurement_unit.name; |
| 1188 | used_space = mp_set_pd_max_value(used_space, mp_create_pd_value(measurement_unit.total_bytes)); | 1200 | free_space_pd.value = mp_create_pd_value(measurement_unit.free_bytes); |
| 1189 | used_space = mp_set_pd_min_value(used_space, mp_create_pd_value(0)); | 1201 | free_space_pd = |
| 1190 | used_space.uom = "B"; | 1202 | mp_pd_set_thresholds(free_space_pd, measurement_unit.freespace_bytes_thresholds); |
| 1191 | used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds); | 1203 | freespace_bytes_sc = mp_set_subcheck_state(freespace_bytes_sc, mp_get_pd_status(free_space_pd)); |
| 1192 | freespace_bytes_sc = mp_set_subcheck_state(freespace_bytes_sc, mp_get_pd_status(used_space)); | 1204 | |
| 1205 | // Used space for display | ||
| 1206 | mp_perfdata used_space_pd = perfdata_init(); | ||
| 1207 | used_space_pd.label = measurement_unit.name; | ||
| 1208 | used_space_pd.value = mp_create_pd_value(measurement_unit.used_bytes); | ||
| 1209 | used_space_pd = | ||
| 1210 | mp_set_pd_max_value(used_space_pd, mp_create_pd_value(measurement_unit.total_bytes)); | ||
| 1211 | used_space_pd = mp_set_pd_min_value(used_space_pd, mp_create_pd_value(0)); | ||
| 1212 | used_space_pd.uom = "B"; | ||
| 1193 | 1213 | ||
| 1194 | // special case for absolute space thresholds here: | 1214 | // special case for absolute space thresholds here: |
| 1195 | // if absolute values are not set, compute the thresholds from percentage thresholds | 1215 | // if absolute values are not set, compute the thresholds from percentage thresholds |
| @@ -1209,7 +1229,8 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1209 | } | 1229 | } |
| 1210 | measurement_unit.freespace_bytes_thresholds = | 1230 | measurement_unit.freespace_bytes_thresholds = |
| 1211 | mp_thresholds_set_crit(measurement_unit.freespace_bytes_thresholds, tmp_range); | 1231 | mp_thresholds_set_crit(measurement_unit.freespace_bytes_thresholds, tmp_range); |
| 1212 | used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds); | 1232 | free_space_pd = |
| 1233 | mp_pd_set_thresholds(free_space_pd, measurement_unit.freespace_bytes_thresholds); | ||
| 1213 | } | 1234 | } |
| 1214 | 1235 | ||
| 1215 | if (!temp_thlds.warning_is_set && | 1236 | if (!temp_thlds.warning_is_set && |
| @@ -1225,10 +1246,22 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1225 | } | 1246 | } |
| 1226 | measurement_unit.freespace_bytes_thresholds = | 1247 | measurement_unit.freespace_bytes_thresholds = |
| 1227 | mp_thresholds_set_warn(measurement_unit.freespace_bytes_thresholds, tmp_range); | 1248 | mp_thresholds_set_warn(measurement_unit.freespace_bytes_thresholds, tmp_range); |
| 1228 | used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds); | 1249 | free_space_pd = |
| 1250 | mp_pd_set_thresholds(free_space_pd, measurement_unit.freespace_bytes_thresholds); | ||
| 1229 | } | 1251 | } |
| 1230 | 1252 | ||
| 1231 | mp_add_perfdata_to_subcheck(&freespace_bytes_sc, used_space); | 1253 | mp_thresholds thr_used_space = measurement_unit.freespace_bytes_thresholds; |
| 1254 | if (thr_used_space.critical_is_set) { | ||
| 1255 | thr_used_space.critical.alert_on_inside_range = | ||
| 1256 | !thr_used_space.critical.alert_on_inside_range; | ||
| 1257 | } | ||
| 1258 | if (thr_used_space.warning_is_set) { | ||
| 1259 | thr_used_space.warning.alert_on_inside_range = | ||
| 1260 | !thr_used_space.warning.alert_on_inside_range; | ||
| 1261 | } | ||
| 1262 | used_space_pd = mp_pd_set_thresholds(used_space_pd, thr_used_space); | ||
| 1263 | |||
| 1264 | mp_add_perfdata_to_subcheck(&freespace_bytes_sc, used_space_pd); | ||
| 1232 | mp_add_subcheck_to_subcheck(&result, freespace_bytes_sc); | 1265 | mp_add_subcheck_to_subcheck(&result, freespace_bytes_sc); |
| 1233 | 1266 | ||
| 1234 | // ========================== | 1267 | // ========================== |
| @@ -1264,7 +1297,8 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_ | |||
| 1264 | 1297 | ||
| 1265 | mp_perfdata inode_percentage_pd = perfdata_init(); | 1298 | mp_perfdata inode_percentage_pd = perfdata_init(); |
| 1266 | inode_percentage_pd = mp_set_pd_value(inode_percentage_pd, free_inode_percentage); | 1299 | inode_percentage_pd = mp_set_pd_value(inode_percentage_pd, free_inode_percentage); |
| 1267 | inode_percentage_pd = mp_pd_set_thresholds(inode_percentage_pd, measurement_unit.freeinodes_percent_thresholds); | 1300 | inode_percentage_pd = mp_pd_set_thresholds(inode_percentage_pd, |
| 1301 | measurement_unit.freeinodes_percent_thresholds); | ||
| 1268 | 1302 | ||
| 1269 | if (verbose > 0) { | 1303 | if (verbose > 0) { |
| 1270 | printf("free inode percentage computed: %g\n", free_inode_percentage); | 1304 | printf("free inode percentage computed: %g\n", free_inode_percentage); |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index 72a83ea4..ba149842 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | # TODO: Add in tests for perf data. Need to beef up Monitoring::Plugin::Performance to cater for max, min, etc | 7 | # TODO: Add in tests for perf data. Need to beef up Monitoring::Plugin::Performance to cater for max, min, etc |
| 8 | 8 | ||
| 9 | use strict; | 9 | use strict; |
| 10 | use warnings; | ||
| 10 | use Test::More; | 11 | use Test::More; |
| 11 | use NPTest; | 12 | use NPTest; |
| 12 | use POSIX qw(ceil floor); | 13 | use POSIX qw(ceil floor); |
| @@ -26,7 +27,7 @@ my $output_format = "--output-format mp-test-json"; | |||
| 26 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { | 27 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { |
| 27 | plan skip_all => "Need 2 mountpoints to test"; | 28 | plan skip_all => "Need 2 mountpoints to test"; |
| 28 | } else { | 29 | } else { |
| 29 | plan tests => 97; | 30 | plan tests => 96; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | $result = NPTest->testCmd( | 33 | $result = NPTest->testCmd( |
| @@ -34,25 +35,30 @@ $result = NPTest->testCmd( | |||
| 34 | ); | 35 | ); |
| 35 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); | 36 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); |
| 36 | 37 | ||
| 38 | my $result_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]; | ||
| 39 | my $result_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]; | ||
| 40 | |||
| 37 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "Main result is OK"); | 41 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "Main result is OK"); |
| 38 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'state'}, "/OK/", "First sub result is OK"); | 42 | like($result_mp2->{'state'}, "/OK/", "First sub result is OK"); |
| 39 | like($result->{'mp_test_result'}->{'checks'}->[1]->{'state'}, "/OK/", "Second sub result is OK"); | 43 | like($result_mp1->{'state'}, "/OK/", "Second sub result is OK"); |
| 44 | |||
| 45 | my @perfdata; | ||
| 46 | @perfdata[0] = $result_mp2->{'checks'}->[0]->{'perfdata'}->[0]; | ||
| 47 | @perfdata[1] = $result_mp1->{'checks'}->[0]->{'perfdata'}->[0]; | ||
| 40 | 48 | ||
| 41 | my $absolut_space_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | 49 | my $absolut_space_mp1 = $perfdata[1]->{'max'}->{'value'}; |
| 42 | # print("absolute space on mp1: ". $absolut_space_mp1 . "\n"); | 50 | # print("absolute space on mp1: ". $absolut_space_mp1 . "\n"); |
| 51 | my $absolut_used_space_mp1 = $perfdata[1]->{'value'}->{'value'}; | ||
| 43 | 52 | ||
| 44 | my $free_percent_on_mp1 = ($result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'} / ($absolut_space_mp1/100)); | 53 | my $free_percent_on_mp1 = ($absolut_space_mp1 - $absolut_used_space_mp1) / ($absolut_space_mp1/100); |
| 45 | print("free percent on mp1: ". $free_percent_on_mp1 . "\n"); | 54 | # print("free percent on mp1: ". $free_percent_on_mp1 . "\n"); |
| 46 | 55 | ||
| 47 | my $absolut_space_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | 56 | my $absolut_space_mp2 = $perfdata[0]->{'max'}->{'value'}; |
| 48 | # print("absolute space on mp2: ". $absolut_space_mp2 . "\n"); | 57 | # print("absolute space on mp2: ". $absolut_space_mp2 . "\n"); |
| 58 | my $absolut_used_space_mp2 = $perfdata[0]->{'value'}->{'value'}; | ||
| 49 | 59 | ||
| 50 | my $free_percent_on_mp2 = ($result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'}/ ($absolut_space_mp2/100)); | 60 | my $free_percent_on_mp2 = (($absolut_space_mp2 - $absolut_used_space_mp2)/ ($absolut_space_mp2/100)); |
| 51 | print("free percent on mp2: ". $free_percent_on_mp2 . "\n"); | 61 | # print("free percent on mp2: ". $free_percent_on_mp2 . "\n"); |
| 52 | |||
| 53 | my @perfdata; | ||
| 54 | @perfdata[0] = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]; | ||
| 55 | @perfdata[1] = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]; | ||
| 56 | 62 | ||
| 57 | # Decrease precision of numbers since the the fs might be modified between the two runs | 63 | # Decrease precision of numbers since the the fs might be modified between the two runs |
| 58 | $perfdata[0]->{'value'}->{'value'} = int($perfdata[0]->{'value'}->{'value'} / 1000000); | 64 | $perfdata[0]->{'value'}->{'value'} = int($perfdata[0]->{'value'}->{'value'} / 1000000); |
| @@ -73,46 +79,56 @@ if ($free_percent_on_mp1 > $free_percent_on_mp2) { | |||
| 73 | die "Two mountpoints are the same - cannot do rest of test"; | 79 | die "Two mountpoints are the same - cannot do rest of test"; |
| 74 | } | 80 | } |
| 75 | 81 | ||
| 76 | print("less free: " . $less_free . "\n"); | 82 | # print("less free: " . $less_free . "\n"); |
| 77 | print("more free: " . $more_free . "\n"); | 83 | # print("more free: " . $more_free . "\n"); |
| 78 | 84 | ||
| 79 | if($free_percent_on_mp1 == $avg_free_percent || $free_percent_on_mp2 == $avg_free_percent) { | 85 | if($free_percent_on_mp1 == $avg_free_percent || $free_percent_on_mp2 == $avg_free_percent) { |
| 80 | die "One mountpoints has average space free - cannot do rest of test"; | 86 | die "One mountpoints has average space free - cannot do rest of test"; |
| 81 | } | 87 | } |
| 82 | 88 | ||
| 83 | my $used_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; | 89 | # TODO enable inode checks later when there is enough nerves for Perl |
| 84 | my $total_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; | 90 | # my $have_inodes = 1; |
| 85 | 91 | # my $more_inode_free; | |
| 86 | my $free_inodes_on_mp1 = $total_inodes_on_mp1 - $used_inodes_on_mp1; | 92 | # my $less_inode_free; |
| 87 | my $free_inode_percentage_on_mp1 = $free_inodes_on_mp1 / ($total_inodes_on_mp1 / 100); | 93 | # my $avg_inode_free_percentage; |
| 88 | 94 | ||
| 89 | # print("free inodes on mp1: " . $free_inodes_on_mp1 . "\n"); | 95 | # # Do we have an inode reading? might not be if the filesystem does not have a fixed number of inodes |
| 90 | # print("total inodes on mp1: " . $total_inodes_on_mp1 . "\n"); | 96 | # if ($result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2] && $result->{'mp_test_result'}->{'checks'}->[0]) { |
| 91 | # print("free inode percentage on mp1: " . $free_inode_percentage_on_mp1 . "\n"); | 97 | # my $used_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; |
| 92 | 98 | # my $total_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; | |
| 93 | my $used_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; | 99 | |
| 94 | my $total_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; | 100 | # my $free_inodes_on_mp1 = $total_inodes_on_mp1 - $used_inodes_on_mp1; |
| 95 | my $free_inodes_on_mp2 = $total_inodes_on_mp2 - $used_inodes_on_mp2; | 101 | # my $free_inode_percentage_on_mp1 = $free_inodes_on_mp1 / ($total_inodes_on_mp1 / 100); |
| 96 | my $free_inode_percentage_on_mp2 = $free_inodes_on_mp2 / ($total_inodes_on_mp2 / 100); | 102 | |
| 97 | 103 | # # print("free inodes on mp1: " . $free_inodes_on_mp1 . "\n"); | |
| 98 | # print("free inodes on mp2: " . $free_inodes_on_mp2 . "\n"); | 104 | # # print("total inodes on mp1: " . $total_inodes_on_mp1 . "\n"); |
| 99 | # print("total inodes on mp2: " . $total_inodes_on_mp2 . "\n"); | 105 | # # print("free inode percentage on mp1: " . $free_inode_percentage_on_mp1 . "\n"); |
| 100 | # print("free inode percentage on mp2: " . $free_inode_percentage_on_mp2 . "\n"); | 106 | |
| 101 | 107 | # my $used_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; | |
| 102 | my $avg_inode_free_percentage = ceil(($free_inode_percentage_on_mp1 + $free_inode_percentage_on_mp2)/2); | 108 | # my $total_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; |
| 103 | my ($more_inode_free, $less_inode_free); | 109 | # my $free_inodes_on_mp2 = $total_inodes_on_mp2 - $used_inodes_on_mp2; |
| 104 | if ($free_inode_percentage_on_mp1 > $free_inode_percentage_on_mp2) { | 110 | # my $free_inode_percentage_on_mp2 = $free_inodes_on_mp2 / ($total_inodes_on_mp2 / 100); |
| 105 | $more_inode_free = $mountpoint_valid; | 111 | |
| 106 | $less_inode_free = $mountpoint2_valid; | 112 | # # print("free inodes on mp2: " . $free_inodes_on_mp2 . "\n"); |
| 107 | } elsif ($free_inode_percentage_on_mp1 < $free_inode_percentage_on_mp2) { | 113 | # # print("total inodes on mp2: " . $total_inodes_on_mp2 . "\n"); |
| 108 | $more_inode_free = $mountpoint2_valid; | 114 | # # print("free inode percentage on mp2: " . $free_inode_percentage_on_mp2 . "\n"); |
| 109 | $less_inode_free = $mountpoint_valid; | 115 | |
| 110 | } else { | 116 | # my $avg_inode_free_percentage = ceil(($free_inode_percentage_on_mp1 + $free_inode_percentage_on_mp2)/2); |
| 111 | die "Two mountpoints with same inodes free - cannot do rest of test"; | 117 | # if ($free_inode_percentage_on_mp1 > $free_inode_percentage_on_mp2) { |
| 112 | } | 118 | # $more_inode_free = $mountpoint_valid; |
| 113 | if($free_inode_percentage_on_mp1 == $avg_inode_free_percentage || $free_inode_percentage_on_mp2 == $avg_inode_free_percentage) { | 119 | # $less_inode_free = $mountpoint2_valid; |
| 114 | die "One mountpoints has average inodes free - cannot do rest of test"; | 120 | # } elsif ($free_inode_percentage_on_mp1 < $free_inode_percentage_on_mp2) { |
| 115 | } | 121 | # $more_inode_free = $mountpoint2_valid; |
| 122 | # $less_inode_free = $mountpoint_valid; | ||
| 123 | # } else { | ||
| 124 | # die "Two mountpoints with same inodes free - cannot do rest of test"; | ||
| 125 | # } | ||
| 126 | # if($free_inode_percentage_on_mp1 == $avg_inode_free_percentage || $free_inode_percentage_on_mp2 == $avg_inode_free_percentage) { | ||
| 127 | # die "One mountpoints has average inodes free - cannot do rest of test"; | ||
| 128 | # } | ||
| 129 | # } else { | ||
| 130 | # $have_inodes = 0; | ||
| 131 | # } | ||
| 116 | 132 | ||
| 117 | # Verify performance data | 133 | # Verify performance data |
| 118 | # First check absolute thresholds... | 134 | # First check absolute thresholds... |
| @@ -144,8 +160,8 @@ my $warn_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[ | |||
| 144 | my $crit_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'crit'}->{'end'}->{'value'}; | 160 | my $crit_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'crit'}->{'end'}->{'value'}; |
| 145 | my $total_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | 161 | my $total_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'max'}->{'value'}; |
| 146 | 162 | ||
| 147 | print("warn_percth_data: " . $warn_percth_data . "\n"); | 163 | # print("warn_percth_data: " . $warn_percth_data . "\n"); |
| 148 | print("crit_percth_data: " . $crit_percth_data . "\n"); | 164 | # print("crit_percth_data: " . $crit_percth_data . "\n"); |
| 149 | 165 | ||
| 150 | is (int($warn_percth_data), int((20/100)*$total_percth_data), "Wrong warning in perf data using percent thresholds. Got " . $warn_percth_data . " with total " . $total_percth_data); | 166 | is (int($warn_percth_data), int((20/100)*$total_percth_data), "Wrong warning in perf data using percent thresholds. Got " . $warn_percth_data . " with total " . $total_percth_data); |
| 151 | is (int($crit_percth_data), int((10/100)*$total_percth_data), "Wrong critical in perf data using percent thresholds. Got " . $crit_percth_data . " with total " . $total_percth_data); | 167 | is (int($crit_percth_data), int((10/100)*$total_percth_data), "Wrong critical in perf data using percent thresholds. Got " . $crit_percth_data . " with total " . $total_percth_data); |
| @@ -161,6 +177,18 @@ cmp_ok( $result->return_code, "==", 0, "with JSON test format result should alwa | |||
| 161 | my @perfdata2; | 177 | my @perfdata2; |
| 162 | @perfdata2[0] = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]; | 178 | @perfdata2[0] = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]; |
| 163 | @perfdata2[1] = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]; | 179 | @perfdata2[1] = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]; |
| 180 | |||
| 181 | my $free_on_mp1 = ($perfdata2[1]->{'max'}->{'value'} - $perfdata2[1]->{'value'}->{'value'}); | ||
| 182 | my $free_on_mp2 = ($perfdata2[0]->{'max'}->{'value'} - $perfdata2[0]->{'value'}->{'value'}); | ||
| 183 | # print "free on mp1: " . $free_on_mp1 . "\n"; | ||
| 184 | # print "free on mp2: " . $free_on_mp2 . "\n"; | ||
| 185 | # Either one of those should not be zero | ||
| 186 | die "Cannot parse output: $_" unless (defined($free_on_mp1) && defined($free_on_mp2)); | ||
| 187 | |||
| 188 | my $free_on_all = $free_on_mp1 + $free_on_mp2; | ||
| 189 | |||
| 190 | # print "free on all: " . $free_on_all . "\n"; | ||
| 191 | |||
| 164 | # Decrease precision of numbers since the the fs might be modified between the two runs | 192 | # Decrease precision of numbers since the the fs might be modified between the two runs |
| 165 | $perfdata2[0]->{'value'}->{'value'} = int($perfdata2[0]->{'value'}->{'value'} / 1000000); | 193 | $perfdata2[0]->{'value'}->{'value'} = int($perfdata2[0]->{'value'}->{'value'} / 1000000); |
| 166 | $perfdata2[1]->{'value'}->{'value'} = int($perfdata2[1]->{'value'}->{'value'} / 1000000); | 194 | $perfdata2[1]->{'value'}->{'value'} = int($perfdata2[1]->{'value'}->{'value'} / 1000000); |
| @@ -175,12 +203,6 @@ $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free $ | |||
| 175 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); | 203 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 176 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "At least 1 MB available on $more_free and $less_free"); | 204 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "At least 1 MB available on $more_free and $less_free"); |
| 177 | 205 | ||
| 178 | my $free_mb_on_mp1 =$result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'} / (1024 * 1024); | ||
| 179 | my $free_mb_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'}/ (1024 * 1024); | ||
| 180 | die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); | ||
| 181 | |||
| 182 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; | ||
| 183 | |||
| 184 | 206 | ||
| 185 | $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free $output_format" ); | 207 | $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free $output_format" ); |
| 186 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); | 208 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| @@ -248,55 +270,45 @@ cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make | |||
| 248 | 270 | ||
| 249 | 271 | ||
| 250 | # Basic inode checks for sizes | 272 | # Basic inode checks for sizes |
| 273 | SKIP: { | ||
| 274 | skip "No inode data", 14 if 1 eq 1; | ||
| 251 | 275 | ||
| 252 | $result = NPTest->testCmd( "./check_disk --icritical 1% --iwarning 1% -p $more_inode_free" ); | 276 | # $result = NPTest->testCmd( "./check_disk --icritical 1% --iwarning 1% -p $more_inode_free" ); |
| 253 | is( $result->return_code, 0, "At least 1% free on inodes for both mountpoints"); | 277 | # is( $result->return_code, 0, "At least 1% free on inodes for both mountpoints"); |
| 254 | |||
| 255 | $result = NPTest->testCmd( "./check_disk -K 100% -W 100% -p $less_inode_free" ); | ||
| 256 | is( $result->return_code, 2, "Critical requesting 100% free inodes for both mountpoints"); | ||
| 257 | |||
| 258 | $result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" ); | ||
| 259 | is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free"); | ||
| 260 | |||
| 261 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free" ); | ||
| 262 | is( $result->return_code, 1, "Get warning on less_inode_free, when checking average"); | ||
| 263 | |||
| 264 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free "); | ||
| 265 | is( $result->return_code, 0, "Get ok on more_inode_free when checking average"); | ||
| 266 | 278 | ||
| 267 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); | 279 | # $result = NPTest->testCmd( "./check_disk -K 100% -W 100% -p $less_inode_free" ); |
| 268 | is ($result->return_code, 1, "Combine above two tests, get warning"); | 280 | # is( $result->return_code, 2, "Critical requesting 100% free inodes for both mountpoints"); |
| 269 | $all_disks = $result->output; | ||
| 270 | 281 | ||
| 271 | $result = NPTest->testCmd( "./check_disk -e -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); | 282 | # $result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" ); |
| 272 | isnt( $result->output, $all_disks, "-e gives different output"); | 283 | # is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free"); |
| 273 | like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free"); | ||
| 274 | unlike( $result->only_output, qr/$more_inode_free\s/, "Has ignored $more_inode_free as not a problem"); | ||
| 275 | like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data"); | ||
| 276 | |||
| 277 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); | ||
| 278 | is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average"); | ||
| 279 | |||
| 280 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); | ||
| 281 | is( $result->return_code, 2, "Get critical on less_inode_free, checking average"); | ||
| 282 | 284 | ||
| 283 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); | 285 | # $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free" ); |
| 284 | is( $result->return_code, 2, "Combining above two tests, get critical"); | 286 | # is( $result->return_code, 1, "Get warning on less_inode_free, when checking average"); |
| 285 | 287 | ||
| 286 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); | 288 | # $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free "); |
| 287 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); | 289 | # is( $result->return_code, 0, "Get ok on more_inode_free when checking average"); |
| 288 | 290 | ||
| 291 | # $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); | ||
| 292 | # is ($result->return_code, 1, "Combine above two tests, get warning"); | ||
| 293 | # $all_disks = $result->output; | ||
| 289 | 294 | ||
| 295 | # $result = NPTest->testCmd( "./check_disk -e -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); | ||
| 296 | # isnt( $result->output, $all_disks, "-e gives different output"); | ||
| 297 | # like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free"); | ||
| 298 | # unlike( $result->only_output, qr/$more_inode_free\s/, "Has ignored $more_inode_free as not a problem"); | ||
| 299 | # like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data"); | ||
| 290 | 300 | ||
| 301 | # $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); | ||
| 302 | # is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average"); | ||
| 291 | 303 | ||
| 304 | # $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); | ||
| 305 | # is( $result->return_code, 2, "Get critical on less_inode_free, checking average"); | ||
| 292 | 306 | ||
| 307 | # $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); | ||
| 308 | # is( $result->return_code, 2, "Combining above two tests, get critical"); | ||
| 293 | 309 | ||
| 294 | TODO: { | 310 | # $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); |
| 295 | local $TODO = "Invalid percent figures"; | 311 | # cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); |
| 296 | $result = NPTest->testCmd( | ||
| 297 | "./check_disk -w 10% -c 15% -p $mountpoint_valid" | ||
| 298 | ); | ||
| 299 | cmp_ok( $result->return_code, '==', 3, "Invalid command line options" ); | ||
| 300 | } | 312 | } |
| 301 | 313 | ||
| 302 | $result = NPTest->testCmd( | 314 | $result = NPTest->testCmd( |
| @@ -371,20 +383,23 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoi | |||
| 371 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); | 383 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 372 | cmp_ok(scalar $result->{'mp_test_result'}->{'checks'}, '>', 1, "-C invokes matchall logic again"); | 384 | cmp_ok(scalar $result->{'mp_test_result'}->{'checks'}, '>', 1, "-C invokes matchall logic again"); |
| 373 | 385 | ||
| 386 | my $value_below = ($free_on_all - (10**6)) % (10**5) * (10**5); | ||
| 387 | my $value_above = $free_on_all + (10**6) % (10**5) * (10**5); | ||
| 388 | |||
| 374 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit | 389 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit |
| 375 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); | 390 | $result = NPTest->testCmd( "./check_disk -u Bytes -w ". $value_above ." -c ". $value_above ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); |
| 376 | cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit\nInstead received: " . $result->output); | 391 | cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit"); |
| 377 | 392 | ||
| 378 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c | 393 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c |
| 379 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all - 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); | 394 | $result = NPTest->testCmd( "./check_disk -u Bytes -w ". $value_above ." -c ". $value_below ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); |
| 380 | cmp_ok( $result->return_code, '==', 1, "grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c "); | 395 | cmp_ok( $result->return_code, '==', 1, "grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c "); |
| 381 | 396 | ||
| 382 | # grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit | 397 | # grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit |
| 383 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); | 398 | $result = NPTest->testCmd( "./check_disk -u Bytes -w ". $value_below ." -c ". $value_below ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); |
| 384 | cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); | 399 | cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free megs on mp1+mp2 is more than warn/crit"); |
| 385 | 400 | ||
| 386 | # grouping: exit unknown if group name is given after -p | 401 | # grouping: exit unknown if group name is given after -p |
| 387 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" ); | 402 | $result = NPTest->testCmd( "./check_disk -u Bytes -w ". $value_below ." -c ". $value_below ." -p $mountpoint_valid -g group -p $mountpoint2_valid" ); |
| 388 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); | 403 | cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname"); |
| 389 | 404 | ||
| 390 | # regex: exit unknown if given regex is not compilable | 405 | # regex: exit unknown if given regex is not compilable |
