From 078c69d2ddf6b7dd2dfef5ca0f3013a723ec0268 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Mon, 25 Oct 2021 17:34:13 +0200
Subject: Recognice IEC binary units and format accordingly to base2 (always)
---
plugins/check_disk.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index a2735195..07862283 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -574,21 +574,24 @@ process_arguments (int argc, char **argv)
case 'u':
if (units)
free(units);
- if (! strcmp (optarg, "bytes")) {
+ if (! strcasecmp (optarg, "bytes")) {
mult = (uintmax_t)1;
units = strdup ("B");
- } else if (! strcmp (optarg, "kB")) {
+ } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) {
mult = (uintmax_t)1024;
- units = strdup ("kB");
- } else if (! strcmp (optarg, "MB")) {
+ units = strdup ("kiB");
+ } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) {
mult = (uintmax_t)1024 * 1024;
- units = strdup ("MB");
- } else if (! strcmp (optarg, "GB")) {
+ units = strdup ("MiB");
+ } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) {
mult = (uintmax_t)1024 * 1024 * 1024;
- units = strdup ("GB");
- } else if (! strcmp (optarg, "TB")) {
+ units = strdup ("GiB");
+ } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) {
mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
- units = strdup ("TB");
+ units = strdup ("TiB");
+ } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) {
+ mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024;
+ units = strdup ("PiB");
} else {
die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
}
@@ -599,13 +602,13 @@ process_arguments (int argc, char **argv)
mult = 1024;
if (units)
free(units);
- units = strdup ("kB");
+ units = strdup ("kiB");
break;
case 'm': /* display mountpoint */
mult = 1024 * 1024;
if (units)
free(units);
- units = strdup ("MB");
+ units = strdup ("MiB");
break;
case 'L':
stat_remote_fs = 1;
@@ -812,7 +815,7 @@ process_arguments (int argc, char **argv)
}
if (units == NULL) {
- units = strdup ("MB");
+ units = strdup ("MiB");
mult = (uintmax_t)1024 * 1024;
}
--
cgit v1.2.3-74-g34f1
From 8f2cfd1c805f68a21e221f9ea629800be1c88af8 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Mon, 25 Oct 2021 17:35:29 +0200
Subject: Reformat a little bit for easier reading
---
plugins/check_disk.c | 48 ++++++++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 07862283..00afcad2 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -288,8 +288,17 @@ main (int argc, char **argv)
get_stats (path, &fsp);
if (verbose >= 3) {
- printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n",
- me->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult);
+ printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n",
+ me->me_mountdir,
+ path->dused_pct,
+ path->dfree_pct,
+ path->dused_units,
+ path->dfree_units,
+ path->dtotal_units,
+ path->dused_inodes_percent,
+ path->dfree_inodes_percent,
+ fsp.fsu_blocksize,
+ mult);
}
/* Threshold comparisons */
@@ -344,12 +353,13 @@ main (int argc, char **argv)
/* Nb: *_high_tide are unset when == UINT_MAX */
xasprintf (&perf, "%s %s", perf,
- perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
- path->dused_units, units,
- (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide,
- (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide,
- TRUE, 0,
- TRUE, path->dtotal_units));
+ perfdata_uint64 (
+ (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
+ path->dused_units * mult, "B",
+ (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide * mult,
+ (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide * mult,
+ TRUE, 0,
+ TRUE, path->dtotal_units * mult));
if (display_inodes_perfdata) {
/* *_high_tide must be reinitialized at each run */
@@ -366,12 +376,12 @@ main (int argc, char **argv)
xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
/* Nb: *_high_tide are unset when == UINT_MAX */
xasprintf (&perf, "%s %s", perf,
- perfdata (perf_ilabel,
- path->inodes_used, "",
- (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide,
- (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide,
- TRUE, 0,
- TRUE, path->inodes_total));
+ perfdata_uint64 (perf_ilabel,
+ path->inodes_used, "",
+ (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
+ (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
+ TRUE, 0,
+ TRUE, path->inodes_total));
}
if (disk_result==STATE_OK && erronly && !verbose)
@@ -1055,8 +1065,14 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
}
if (verbose >= 3)
printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
- p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units,
- p->dfree_units, p->dtotal_units, mult);
+ p->group,
+ tmpfsp.fsu_bavail,
+ tmpfsp.fsu_blocksize,
+ p->best_match->me_mountdir,
+ p->dused_units,
+ p->dfree_units,
+ p->dtotal_units,
+ mult);
}
/* modify devname and mountdir for output */
p->best_match->me_mountdir = p->best_match->me_devname = p->group;
--
cgit v1.2.3-74-g34f1
From 50fc9b73a2127c8ed1944b8e3fd5f0f7b64ca8ec Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Mon, 25 Oct 2021 17:36:58 +0200
Subject: Switch to uint64_t
---
lib/utils_disk.h | 2 +-
plugins/check_disk.c | 24 +++++++++++-------------
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 999270cd..bf52e4ce 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -27,7 +27,7 @@ struct parameter_list
uintmax_t total, available, available_to_root, used,
inodes_free, inodes_free_to_root, inodes_used, inodes_total;
double dfree_pct, dused_pct;
- double dused_units, dfree_units, dtotal_units;
+ uint64_t dused_units, dfree_units, dtotal_units;
double dused_inodes_percent, dfree_inodes_percent;
};
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 00afcad2..ecde4e59 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -172,8 +172,6 @@ main (int argc, char **argv)
char *preamble;
char *flag_header;
double inode_space_pct;
- double warning_high_tide;
- double critical_high_tide;
int temp_result;
struct mount_entry *me;
@@ -335,23 +333,23 @@ main (int argc, char **argv)
*/
/* *_high_tide must be reinitialized at each run */
- warning_high_tide = UINT_MAX;
- critical_high_tide = UINT_MAX;
+ uint64_t warning_high_tide = UINT64_MAX;
+ uint64_t critical_high_tide = UINT64_MAX;
if (path->freespace_units->warning != NULL) {
warning_high_tide = path->dtotal_units - path->freespace_units->warning->end;
}
if (path->freespace_percent->warning != NULL) {
- warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units ));
+ warning_high_tide = llabs( min( (double) warning_high_tide, (1.0 - path->freespace_percent->warning->end / 100 * path->dtotal_units) ));
}
if (path->freespace_units->critical != NULL) {
critical_high_tide = path->dtotal_units - path->freespace_units->critical->end;
}
if (path->freespace_percent->critical != NULL) {
- critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units ));
+ critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units ));
}
- /* Nb: *_high_tide are unset when == UINT_MAX */
+ /* Nb: *_high_tide are unset when == UINT64_MAX */
xasprintf (&perf, "%s %s", perf,
perfdata_uint64 (
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
@@ -363,18 +361,18 @@ main (int argc, char **argv)
if (display_inodes_perfdata) {
/* *_high_tide must be reinitialized at each run */
- warning_high_tide = UINT_MAX;
- critical_high_tide = UINT_MAX;
+ warning_high_tide = UINT64_MAX;
+ critical_high_tide = UINT64_MAX;
if (path->freeinodes_percent->warning != NULL) {
- warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
+ warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
}
if (path->freeinodes_percent->critical != NULL) {
- critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
+ critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
}
xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
- /* Nb: *_high_tide are unset when == UINT_MAX */
+ /* Nb: *_high_tide are unset when == UINT64_MAX */
xasprintf (&perf, "%s %s", perf,
perfdata_uint64 (perf_ilabel,
path->inodes_used, "",
@@ -392,7 +390,7 @@ main (int argc, char **argv)
} else {
xasprintf(&flag_header, "");
}
- xasprintf (&output, "%s%s %s %.0f %s (%.0f%%",
+ xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
output, flag_header,
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
path->dfree_units,
--
cgit v1.2.3-74-g34f1
From d3af7a353e75dadf283c58ad49cfe2dc81a4c9ce Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Mon, 25 Oct 2021 17:42:00 +0200
Subject: Remove useless lines and fix some formatting
---
plugins/utils.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/plugins/utils.c b/plugins/utils.c
index f7f8952f..ff0e55d4 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -601,12 +601,16 @@ char *perfdata (const char *label,
char *perfdata_uint64 (const char *label,
uint64_t val,
const char *uom,
+
int warnp,
uint64_t warn,
+
int critp,
uint64_t crit,
+
int minp,
uint64_t minv,
+
int maxp,
uint64_t maxv)
{
@@ -618,20 +622,16 @@ char *perfdata_uint64 (const char *label,
xasprintf (&data, "%s=%ld%s;", label, val, uom);
if (warnp)
- xasprintf (&data, "%s%ld;", data, warn);
- else
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%lu;", data, warn);
if (critp)
- xasprintf (&data, "%s%ld;", data, crit);
- else
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%lu;", data, crit);
if (minp)
- xasprintf (&data, "%s%ld", data, minv);
+ xasprintf (&data, "%s%lu", data, minv);
if (maxp)
- xasprintf (&data, "%s;%ld", data, maxv);
+ xasprintf (&data, "%s;%lu", data, maxv);
return data;
}
@@ -658,13 +658,9 @@ char *perfdata_int64 (const char *label,
if (warnp)
xasprintf (&data, "%s%ld;", data, warn);
- else
- xasprintf (&data, "%s;", data);
if (critp)
xasprintf (&data, "%s%ld;", data, crit);
- else
- xasprintf (&data, "%s;", data);
if (minp)
xasprintf (&data, "%s%ld", data, minv);
--
cgit v1.2.3-74-g34f1
From 726a29a3ac4b155536099b8cae2bd517d56fb5f8 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Tue, 26 Oct 2021 12:50:14 +0200
Subject: Fix some tests
---
plugins/t/check_disk.t | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index fdd8769b..ec527e7f 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -88,8 +88,9 @@ $result = NPTest->testCmd(
);
$_ = $result->perf_output;
my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/);
-is ($warn_absth_data, $total_absth_data - 20, "Wrong warning in perf data using absolute thresholds");
-is ($crit_absth_data, $total_absth_data - 10, "Wrong critical in perf data using absolute thresholds");
+# default unit is MiB, but perfdata is always bytes
+is ($warn_absth_data, $total_absth_data - (20 * (2 ** 20)), "Wrong warning in perf data using absolute thresholds");
+is ($crit_absth_data, $total_absth_data - (10 * (2 ** 20)), "Wrong critical in perf data using absolute thresholds");
# Then check percent thresholds.
$result = NPTest->testCmd(
@@ -119,7 +120,7 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text");
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
$_ = $result->output;
-my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g);
+my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g);
my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
--
cgit v1.2.3-74-g34f1
From 1c0882def0d9ce4ed5b2d443884138622e6d839b Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Tue, 26 Oct 2021 13:05:57 +0200
Subject: hopefully fix warning high tide with percentage
---
plugins/check_disk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index ecde4e59..1778b613 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -340,7 +340,7 @@ main (int argc, char **argv)
warning_high_tide = path->dtotal_units - path->freespace_units->warning->end;
}
if (path->freespace_percent->warning != NULL) {
- warning_high_tide = llabs( min( (double) warning_high_tide, (1.0 - path->freespace_percent->warning->end / 100 * path->dtotal_units) ));
+ warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)* path->dtotal_units ));
}
if (path->freespace_units->critical != NULL) {
critical_high_tide = path->dtotal_units - path->freespace_units->critical->end;
--
cgit v1.2.3-74-g34f1
From 6e0586c8e35c3990631f73d8cdb89b70751994c3 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Tue, 26 Oct 2021 16:53:01 +0200
Subject: Reform some arithmetical operations for more clarity
---
plugins/check_disk.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 1778b613..71eab531 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -334,19 +334,21 @@ main (int argc, char **argv)
/* *_high_tide must be reinitialized at each run */
uint64_t warning_high_tide = UINT64_MAX;
- uint64_t critical_high_tide = UINT64_MAX;
if (path->freespace_units->warning != NULL) {
- warning_high_tide = path->dtotal_units - path->freespace_units->warning->end;
+ warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult;
}
if (path->freespace_percent->warning != NULL) {
- warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)* path->dtotal_units ));
+ warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) );
}
+
+ uint64_t critical_high_tide = UINT64_MAX;
+
if (path->freespace_units->critical != NULL) {
- critical_high_tide = path->dtotal_units - path->freespace_units->critical->end;
+ critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult;
}
if (path->freespace_percent->critical != NULL) {
- critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units ));
+ critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) );
}
/* Nb: *_high_tide are unset when == UINT64_MAX */
@@ -354,8 +356,8 @@ main (int argc, char **argv)
perfdata_uint64 (
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
path->dused_units * mult, "B",
- (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide * mult,
- (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide * mult,
+ (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
+ (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
TRUE, 0,
TRUE, path->dtotal_units * mult));
--
cgit v1.2.3-74-g34f1
From 73ed8109e5ba1c61f8ba435fd4324318d0751f18 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Tue, 26 Oct 2021 20:47:28 +0200
Subject: Re-add separation semicolons for perfdata, which I deleted
---
plugins/utils.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/plugins/utils.c b/plugins/utils.c
index ff0e55d4..c0dce255 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -617,18 +617,22 @@ char *perfdata_uint64 (const char *label,
char *data = NULL;
if (strpbrk (label, "'= "))
- xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
+ xasprintf (&data, "'%s'=%ld%s", label, val, uom);
else
- xasprintf (&data, "%s=%ld%s;", label, val, uom);
+ xasprintf (&data, "%s=%ld%s", label, val, uom);
+ xasprintf (&data, "%s;", data);
if (warnp)
- xasprintf (&data, "%s%lu;", data, warn);
+ xasprintf (&data, "%s%lu", data, warn);
+ xasprintf (&data, "%s;", data);
if (critp)
- xasprintf (&data, "%s%lu;", data, crit);
+ xasprintf (&data, "%s%lu", data, crit);
+ xasprintf (&data, "%s;", data);
if (minp)
xasprintf (&data, "%s%lu", data, minv);
+ xasprintf (&data, "%s;", data);
if (maxp)
xasprintf (&data, "%s;%lu", data, maxv);
@@ -652,18 +656,22 @@ char *perfdata_int64 (const char *label,
char *data = NULL;
if (strpbrk (label, "'= "))
- xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
+ xasprintf (&data, "'%s'=%ld%s", label, val, uom);
else
- xasprintf (&data, "%s=%ld%s;", label, val, uom);
+ xasprintf (&data, "%s=%ld%s", label, val, uom);
+ xasprintf (&data, "%s;", data);
if (warnp)
- xasprintf (&data, "%s%ld;", data, warn);
+ xasprintf (&data, "%s%ld", data, warn);
+ xasprintf (&data, "%s;", data);
if (critp)
- xasprintf (&data, "%s%ld;", data, crit);
+ xasprintf (&data, "%s%ld", data, crit);
+ xasprintf (&data, "%s;", data);
if (minp)
xasprintf (&data, "%s%ld", data, minv);
+ xasprintf (&data, "%s;", data);
if (maxp)
xasprintf (&data, "%s;%ld", data, maxv);
--
cgit v1.2.3-74-g34f1
From 4c8ab67dd31c526d1c73653319ba537cec3000a5 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Tue, 26 Oct 2021 21:09:55 +0200
Subject: Fix my own errors for real this time and add some comments, so I wont
do them again
---
plugins/utils.c | 64 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 32 insertions(+), 32 deletions(-)
diff --git a/plugins/utils.c b/plugins/utils.c
index c0dce255..ebdae2e1 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -601,41 +601,39 @@ char *perfdata (const char *label,
char *perfdata_uint64 (const char *label,
uint64_t val,
const char *uom,
-
- int warnp,
+ int warnp, /* Warning present */
uint64_t warn,
-
- int critp,
+ int critp, /* Critical present */
uint64_t crit,
-
- int minp,
+ int minp, /* Minimum present */
uint64_t minv,
-
- int maxp,
+ int maxp, /* Maximum present */
uint64_t maxv)
{
char *data = NULL;
if (strpbrk (label, "'= "))
- xasprintf (&data, "'%s'=%ld%s", label, val, uom);
+ xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
else
- xasprintf (&data, "%s=%ld%s", label, val, uom);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s=%ld%s;", label, val, uom);
if (warnp)
- xasprintf (&data, "%s%lu", data, warn);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%lu;", data, warn);
+ else
+ xasprintf (&data, "%s;", data);
if (critp)
- xasprintf (&data, "%s%lu", data, crit);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%lu;", data, crit);
+ else
+ xasprintf (&data, "%s;", data);
if (minp)
- xasprintf (&data, "%s%lu", data, minv);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%lu;", data, minv);
+ else
+ xasprintf (&data, "%s;", data);
if (maxp)
- xasprintf (&data, "%s;%lu", data, maxv);
+ xasprintf (&data, "%s%lu", data, maxv);
return data;
}
@@ -644,37 +642,39 @@ char *perfdata_uint64 (const char *label,
char *perfdata_int64 (const char *label,
int64_t val,
const char *uom,
- int warnp,
+ int warnp, /* Warning present */
int64_t warn,
- int critp,
+ int critp, /* Critical present */
int64_t crit,
- int minp,
+ int minp, /* Minimum present */
int64_t minv,
- int maxp,
+ int maxp, /* Maximum present */
int64_t maxv)
{
char *data = NULL;
if (strpbrk (label, "'= "))
- xasprintf (&data, "'%s'=%ld%s", label, val, uom);
+ xasprintf (&data, "'%s'=%ld%s;", label, val, uom);
else
- xasprintf (&data, "%s=%ld%s", label, val, uom);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s=%ld%s;", label, val, uom);
if (warnp)
- xasprintf (&data, "%s%ld", data, warn);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%ld;", data, warn);
+ else
+ xasprintf (&data, "%s;", data);
if (critp)
- xasprintf (&data, "%s%ld", data, crit);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%ld;", data, crit);
+ else
+ xasprintf (&data, "%s;", data);
if (minp)
- xasprintf (&data, "%s%ld", data, minv);
- xasprintf (&data, "%s;", data);
+ xasprintf (&data, "%s%ld;", data, minv);
+ else
+ xasprintf (&data, "%s;", data);
if (maxp)
- xasprintf (&data, "%s;%ld", data, maxv);
+ xasprintf (&data, "%s%ld", data, maxv);
return data;
}
--
cgit v1.2.3-74-g34f1
From 5974b0481c280d8de9c52ff2d7b99fcf4be99b5d Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Wed, 27 Oct 2021 12:44:21 +0200
Subject: Remove whitespace at the end of lines
---
plugins/check_disk.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 71eab531..cc6dbb70 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -1,29 +1,29 @@
/*****************************************************************************
-*
+*
* Monitoring check_disk plugin
-*
+*
* License: GPL
* Copyright (c) 1999-2008 Monitoring Plugins Development Team
-*
+*
* Description:
-*
+*
* This file contains the check_disk plugin
-*
-*
+*
+*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
-*
+*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-*
+*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
-*
-*
+*
+*
*****************************************************************************/
const char *progname = "check_disk";
@@ -253,7 +253,7 @@ main (int argc, char **argv)
/* Remove filesystems already seen */
if (np_seen_name(seen, me->me_mountdir)) {
continue;
- }
+ }
np_add_name(&seen, me->me_mountdir);
if (path->group == NULL) {
@@ -1039,20 +1039,20 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
if (p_list->group && ! (strcmp(p_list->group, p->group))) {
stat_path(p_list);
get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp);
- get_path_stats(p_list, &tmpfsp);
+ get_path_stats(p_list, &tmpfsp);
if (verbose >= 3)
printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units,
p_list->dtotal_units, mult);
- /* prevent counting the first FS of a group twice since its parameter_list entry
+ /* prevent counting the first FS of a group twice since its parameter_list entry
* is used to carry the information of all file systems of the entire group */
if (! first) {
p->total += p_list->total;
p->available += p_list->available;
p->available_to_root += p_list->available_to_root;
p->used += p_list->used;
-
+
p->dused_units += p_list->dused_units;
p->dfree_units += p_list->dfree_units;
p->dtotal_units += p_list->dtotal_units;
@@ -1063,7 +1063,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
}
first = 0;
}
- if (verbose >= 3)
+ if (verbose >= 3)
printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
p->group,
tmpfsp.fsu_bavail,
@@ -1082,7 +1082,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
p->dfree_pct = 100 - p->dused_pct;
p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
-
+
}
void
@@ -1097,7 +1097,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
/* default behaviour : take all the blocks into account */
p->total = fsp->fsu_blocks;
}
-
+
p->dused_units = p->used*fsp->fsu_blocksize/mult;
p->dfree_units = p->available*fsp->fsu_blocksize/mult;
p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
--
cgit v1.2.3-74-g34f1
From 884327ee21b25be3ce1b5627bb40339e14545256 Mon Sep 17 00:00:00 2001
From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com>
Date: Wed, 27 Oct 2021 12:47:08 +0200
Subject: Replace tabs with spaces and do some formatting
---
plugins/check_disk.c | 109 +++++++++++++++++++++++++--------------------------
1 file changed, 54 insertions(+), 55 deletions(-)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index cc6dbb70..c526d056 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
#include
#include "fsusage.h"
#include "mountlist.h"
-#include "intprops.h" /* necessary for TYPE_MAXIMUM */
+#include "intprops.h" /* necessary for TYPE_MAXIMUM */
#if HAVE_LIMITS_H
# include
#endif
@@ -243,10 +243,10 @@ main (int argc, char **argv)
#ifdef __CYGWIN__
if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11)
- continue;
+ continue;
snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10);
if (GetDriveType(mountdir) != DRIVE_FIXED)
- me->me_remote = 1;
+ me->me_remote = 1;
#endif
/* Filters */
@@ -287,16 +287,16 @@ main (int argc, char **argv)
if (verbose >= 3) {
printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n",
- me->me_mountdir,
- path->dused_pct,
- path->dfree_pct,
- path->dused_units,
- path->dfree_units,
- path->dtotal_units,
- path->dused_inodes_percent,
- path->dfree_inodes_percent,
- fsp.fsu_blocksize,
- mult);
+ me->me_mountdir,
+ path->dused_pct,
+ path->dfree_pct,
+ path->dused_units,
+ path->dfree_units,
+ path->dtotal_units,
+ path->dused_inodes_percent,
+ path->dfree_inodes_percent,
+ fsp.fsu_blocksize,
+ mult);
}
/* Threshold comparisons */
@@ -333,7 +333,7 @@ main (int argc, char **argv)
*/
/* *_high_tide must be reinitialized at each run */
- uint64_t warning_high_tide = UINT64_MAX;
+ uint64_t warning_high_tide = UINT64_MAX;
if (path->freespace_units->warning != NULL) {
warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult;
@@ -342,7 +342,7 @@ main (int argc, char **argv)
warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) );
}
- uint64_t critical_high_tide = UINT64_MAX;
+ uint64_t critical_high_tide = UINT64_MAX;
if (path->freespace_units->critical != NULL) {
critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult;
@@ -353,13 +353,13 @@ main (int argc, char **argv)
/* Nb: *_high_tide are unset when == UINT64_MAX */
xasprintf (&perf, "%s %s", perf,
- perfdata_uint64 (
- (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
- path->dused_units * mult, "B",
- (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
- (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
- TRUE, 0,
- TRUE, path->dtotal_units * mult));
+ perfdata_uint64 (
+ (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
+ path->dused_units * mult, "B",
+ (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
+ (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
+ TRUE, 0,
+ TRUE, path->dtotal_units * mult));
if (display_inodes_perfdata) {
/* *_high_tide must be reinitialized at each run */
@@ -376,37 +376,36 @@ main (int argc, char **argv)
xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
/* Nb: *_high_tide are unset when == UINT64_MAX */
xasprintf (&perf, "%s %s", perf,
- perfdata_uint64 (perf_ilabel,
- path->inodes_used, "",
- (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
- (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
- TRUE, 0,
- TRUE, path->inodes_total));
+ perfdata_uint64 (perf_ilabel,
+ path->inodes_used, "",
+ (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
+ (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
+ TRUE, 0,
+ TRUE, path->inodes_total));
}
if (disk_result==STATE_OK && erronly && !verbose)
continue;
- if(disk_result && verbose >= 1) {
- xasprintf(&flag_header, " %s [", state_text (disk_result));
- } else {
- xasprintf(&flag_header, "");
- }
- xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
- output, flag_header,
- (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
- path->dfree_units,
- units,
- path->dfree_pct);
- if (path->dused_inodes_percent < 0) {
- xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
- } else {
- xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
- }
+ if(disk_result && verbose >= 1) {
+ xasprintf(&flag_header, " %s [", state_text (disk_result));
+ } else {
+ xasprintf(&flag_header, "");
+ }
+ xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
+ output, flag_header,
+ (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
+ path->dfree_units,
+ units,
+ path->dfree_pct);
+ if (path->dused_inodes_percent < 0) {
+ xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
+ } else {
+ xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : ""));
+ }
free(flag_header);
/* TODO: Need to do a similar debug line
- xasprintf (&details, _("%s\n\
-%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
+ xasprintf (&details, _("%s\n\%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct,
me->me_devname, me->me_type, me->me_mountdir,
(unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp);
@@ -567,14 +566,14 @@ process_arguments (int argc, char **argv)
}
break;
- case 'W': /* warning inode threshold */
+ case 'W': /* warning inode threshold */
if (*optarg == '@') {
warn_freeinodes_percent = optarg;
} else {
xasprintf(&warn_freeinodes_percent, "@%s", optarg);
}
break;
- case 'K': /* critical inode threshold */
+ case 'K': /* critical inode threshold */
if (*optarg == '@') {
crit_freeinodes_percent = optarg;
} else {
@@ -1066,19 +1065,19 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
if (verbose >= 3)
printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
p->group,
- tmpfsp.fsu_bavail,
- tmpfsp.fsu_blocksize,
- p->best_match->me_mountdir,
- p->dused_units,
+ tmpfsp.fsu_bavail,
+ tmpfsp.fsu_blocksize,
+ p->best_match->me_mountdir,
+ p->dused_units,
p->dfree_units,
- p->dtotal_units,
- mult);
+ p->dtotal_units,
+ mult);
}
/* modify devname and mountdir for output */
p->best_match->me_mountdir = p->best_match->me_devname = p->group;
}
/* finally calculate percentages for either plain FS or summed up group */
- p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
+ p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
p->dfree_pct = 100 - p->dused_pct;
p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
--
cgit v1.2.3-74-g34f1