summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2023-03-10 10:33:25 (GMT)
committerGitHub <noreply@github.com>2023-03-10 10:33:25 (GMT)
commit5077120a251980b4fafed61b4aa8fa5730a85443 (patch)
tree8500b8f5dbe774b399cfdc79f5665ba88ef7f255 /lib
parenta3de84594104ac87a91e200d569fb57edacca928 (diff)
parent269718094177fb8a7e3d3005d1310495009fe8c4 (diff)
downloadmonitoring-plugins-5077120a251980b4fafed61b4aa8fa5730a85443.tar.gz
Merge branch 'master' into master
Diffstat (limited to 'lib')
-rw-r--r--lib/tests/Makefile.am2
-rw-r--r--lib/tests/test_utils.c6
-rw-r--r--lib/utils_base.c10
-rw-r--r--lib/utils_base.h3
-rw-r--r--lib/utils_disk.c6
-rw-r--r--lib/utils_disk.h2
6 files changed, 18 insertions, 11 deletions
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index a8d7ade..31d79df 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -27,7 +27,7 @@ endif
27 27
28AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags) 28AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
29AM_LDFLAGS = $(tap_ldflags) -ltap 29AM_LDFLAGS = $(tap_ldflags) -ltap
30LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a 30LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a $(LIB_CRYPTO)
31 31
32SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c 32SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c
33 33
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index f35b7e2..bc00fac 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -309,7 +309,7 @@ main (int argc, char **argv)
309 309
310 /* This is the result of running ./test_utils */ 310 /* This is the result of running ./test_utils */
311 temp_string = (char *) _np_state_generate_key(); 311 temp_string = (char *) _np_state_generate_key();
312 ok(!strcmp(temp_string, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got hash with exe and no parameters" ) || 312 ok(!strcmp(temp_string, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got hash with exe and no parameters" ) ||
313 diag( "You are probably running in wrong directory. Must run as ./test_utils" ); 313 diag( "You are probably running in wrong directory. Must run as ./test_utils" );
314 314
315 315
@@ -319,7 +319,7 @@ main (int argc, char **argv)
319 this_monitoring_plugin->argv[2] = "--and"; 319 this_monitoring_plugin->argv[2] = "--and";
320 this_monitoring_plugin->argv[3] = "now"; 320 this_monitoring_plugin->argv[3] = "now";
321 temp_string = (char *) _np_state_generate_key(); 321 temp_string = (char *) _np_state_generate_key();
322 ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); 322 ok(!strcmp(temp_string, "bd72da9f78ff1419fad921ea5e43ce56508aef6c"), "Got based on expected argv" );
323 323
324 unsetenv("MP_STATE_PATH"); 324 unsetenv("MP_STATE_PATH");
325 temp_string = (char *) _np_state_calculate_location_prefix(); 325 temp_string = (char *) _np_state_calculate_location_prefix();
@@ -342,7 +342,7 @@ main (int argc, char **argv)
342 np_enable_state(NULL, 51); 342 np_enable_state(NULL, 51);
343 temp_state_key = this_monitoring_plugin->state; 343 temp_state_key = this_monitoring_plugin->state;
344 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 344 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
345 ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); 345 ok( !strcmp(temp_state_key->name, "e2d17f995fd4c020411b85e3e3d0ff7306d4147e"), "Got generated filename" );
346 346
347 347
348 np_enable_state("allowedchars_in_keyname", 77); 348 np_enable_state("allowedchars_in_keyname", 77);
diff --git a/lib/utils_base.c b/lib/utils_base.c
index fd7058d..eb1823b 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -128,6 +128,7 @@ range
128 temp_range->end = 0; 128 temp_range->end = 0;
129 temp_range->end_infinity = TRUE; 129 temp_range->end_infinity = TRUE;
130 temp_range->alert_on = OUTSIDE; 130 temp_range->alert_on = OUTSIDE;
131 temp_range->text = strdup(str);
131 132
132 if (str[0] == '@') { 133 if (str[0] == '@') {
133 temp_range->alert_on = INSIDE; 134 temp_range->alert_on = INSIDE;
@@ -401,20 +402,20 @@ int mp_translate_state (char *state_text) {
401 * parse of argv, so that uniqueness in parameters are reflected there. 402 * parse of argv, so that uniqueness in parameters are reflected there.
402 */ 403 */
403char *_np_state_generate_key() { 404char *_np_state_generate_key() {
404 struct sha1_ctx ctx; 405 struct sha256_ctx ctx;
405 int i; 406 int i;
406 char **argv = this_monitoring_plugin->argv; 407 char **argv = this_monitoring_plugin->argv;
407 unsigned char result[20]; 408 unsigned char result[20];
408 char keyname[41]; 409 char keyname[41];
409 char *p=NULL; 410 char *p=NULL;
410 411
411 sha1_init_ctx(&ctx); 412 sha256_init_ctx(&ctx);
412 413
413 for(i=0; i<this_monitoring_plugin->argc; i++) { 414 for(i=0; i<this_monitoring_plugin->argc; i++) {
414 sha1_process_bytes(argv[i], strlen(argv[i]), &ctx); 415 sha256_process_bytes(argv[i], strlen(argv[i]), &ctx);
415 } 416 }
416 417
417 sha1_finish_ctx(&ctx, &result); 418 sha256_finish_ctx(&ctx, &result);
418 419
419 for (i=0; i<20; ++i) { 420 for (i=0; i<20; ++i) {
420 sprintf(&keyname[2*i], "%02x", result[i]); 421 sprintf(&keyname[2*i], "%02x", result[i]);
@@ -706,4 +707,3 @@ void np_state_write_string(time_t data_time, char *data_string) {
706 707
707 np_free(temp_file); 708 np_free(temp_file);
708} 709}
709
diff --git a/lib/utils_base.h b/lib/utils_base.h
index d7e7dff..5906550 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -2,7 +2,7 @@
2#define _UTILS_BASE_ 2#define _UTILS_BASE_
3/* Header file for Monitoring Plugins utils_base.c */ 3/* Header file for Monitoring Plugins utils_base.c */
4 4
5#include "sha1.h" 5#include "sha256.h"
6 6
7/* This file holds header information for thresholds - use this in preference to 7/* This file holds header information for thresholds - use this in preference to
8 individual plugin logic */ 8 individual plugin logic */
@@ -23,6 +23,7 @@ typedef struct range_struct {
23 double end; 23 double end;
24 int end_infinity; 24 int end_infinity;
25 int alert_on; /* OUTSIDE (default) or INSIDE */ 25 int alert_on; /* OUTSIDE (default) or INSIDE */
26 char* text; /* original unparsed text input */
26 } range; 27 } range;
27 28
28typedef struct thresholds_struct { 29typedef struct thresholds_struct {
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index c7c9126..4f16068 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -28,6 +28,7 @@
28 28
29#include "common.h" 29#include "common.h"
30#include "utils_disk.h" 30#include "utils_disk.h"
31#include "gl/fsusage.h"
31 32
32void 33void
33np_add_name (struct name_list **list, const char *name) 34np_add_name (struct name_list **list, const char *name)
@@ -127,9 +128,12 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
127 size_t name_len = strlen(d->name); 128 size_t name_len = strlen(d->name);
128 size_t best_match_len = 0; 129 size_t best_match_len = 0;
129 struct mount_entry *best_match = NULL; 130 struct mount_entry *best_match = NULL;
131 struct fs_usage fsp;
130 132
131 /* set best match if path name exactly matches a mounted device name */ 133 /* set best match if path name exactly matches a mounted device name */
132 for (me = mount_list; me; me = me->me_next) { 134 for (me = mount_list; me; me = me->me_next) {
135 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
136 continue; /* skip if permissions do not suffice for accessing device */
133 if (strcmp(me->me_devname, d->name)==0) 137 if (strcmp(me->me_devname, d->name)==0)
134 best_match = me; 138 best_match = me;
135 } 139 }
@@ -137,6 +141,8 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
137 /* set best match by directory name if no match was found by devname */ 141 /* set best match by directory name if no match was found by devname */
138 if (! best_match) { 142 if (! best_match) {
139 for (me = mount_list; me; me = me->me_next) { 143 for (me = mount_list; me; me = me->me_next) {
144 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
145 continue; /* skip if permissions do not suffice for accessing device */
140 size_t len = strlen (me->me_mountdir); 146 size_t len = strlen (me->me_mountdir);
141 if ((exact == FALSE && (best_match_len <= len && len <= name_len && 147 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
142 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 148 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 999270c..bf52e4c 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -27,7 +27,7 @@ struct parameter_list
27 uintmax_t total, available, available_to_root, used, 27 uintmax_t total, available, available_to_root, used,
28 inodes_free, inodes_free_to_root, inodes_used, inodes_total; 28 inodes_free, inodes_free_to_root, inodes_used, inodes_total;
29 double dfree_pct, dused_pct; 29 double dfree_pct, dused_pct;
30 double dused_units, dfree_units, dtotal_units; 30 uint64_t dused_units, dfree_units, dtotal_units;
31 double dused_inodes_percent, dfree_inodes_percent; 31 double dused_inodes_percent, dfree_inodes_percent;
32}; 32};
33 33