From cbfa6b45786e6b11c8f31a75f04932f14ae96af1 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 30 Jan 2013 12:14:28 +0100 Subject: [PATCH] support warning and critical environment variables Like the mainline plugins do. --- tools/munin-plugins-busybox/common.c | 43 +++++++++++++++++++++++ tools/munin-plugins-busybox/common.h | 4 +++ tools/munin-plugins-busybox/entropy.c | 1 + tools/munin-plugins-busybox/forks.c | 1 + tools/munin-plugins-busybox/if_err_.c | 3 ++ tools/munin-plugins-busybox/interrupts.c | 2 ++ tools/munin-plugins-busybox/load.c | 4 +-- tools/munin-plugins-busybox/open_inodes.c | 3 +- tools/munin-plugins-busybox/swap.c | 3 +- tools/munin-plugins-busybox/uptime.c | 1 + 10 files changed, 60 insertions(+), 5 deletions(-) diff --git a/tools/munin-plugins-busybox/common.c b/tools/munin-plugins-busybox/common.c index fd291f06..3527ef78 100644 --- a/tools/munin-plugins-busybox/common.c +++ b/tools/munin-plugins-busybox/common.c @@ -1,5 +1,9 @@ #include #include +#include +#include + +extern char **environ; int writeyes(void) { puts("yes"); @@ -21,3 +25,42 @@ int getenvint(const char *name, int defvalue) { return defvalue; return atoi(value); } + +const char *getenv_composed(const char *name1, const char *name2) { + char **p; + size_t len1 = strlen(name1), len2 = strlen(name2); + for(p = environ; *p; ++p) { + if(0 == strncmp(*p, name1, len1) && + 0 == strncmp(len1 + *p, name2, len2) && + (*p)[len1 + len2] == '=') + return len1 + len2 + 1 + *p; + } + return NULL; +} + +void print_warning(const char *name) { + const char *p; + p = getenv_composed(name, "_warning"); + if(p == NULL) + p = getenv("warning"); + if(p == NULL) + return; + + printf("%s.warning %s\n", name, p); +} + +void print_critical(const char *name) { + const char *p; + p = getenv_composed(name, "_critical"); + if(p == NULL) + p = getenv("critical"); + if(p == NULL) + return; + + printf("%s.critial %s\n", name, p); +} + +void print_warncrit(const char *name) { + print_warning(name); + print_critical(name); +} diff --git a/tools/munin-plugins-busybox/common.h b/tools/munin-plugins-busybox/common.h index 2a344085..ac4d08c8 100644 --- a/tools/munin-plugins-busybox/common.h +++ b/tools/munin-plugins-busybox/common.h @@ -6,5 +6,9 @@ int writeyes(void); int writeno(const char *); int getenvint(const char *, int); +const char *getenv_composed(const char *, const char *); +void print_warning(const char *); +void print_critical(const char *); +void print_warncrit(const char *); #endif diff --git a/tools/munin-plugins-busybox/entropy.c b/tools/munin-plugins-busybox/entropy.c index cc7791fd..57206d2a 100644 --- a/tools/munin-plugins-busybox/entropy.c +++ b/tools/munin-plugins-busybox/entropy.c @@ -17,6 +17,7 @@ int entropy(int argc, char **argv) { "graph_info This graph shows the amount of entropy available in the system.\n" "entropy.label entropy\n" "entropy.info The number of random bytes available. This is typically used by cryptographic applications."); + print_warncrit("entropy"); return 0; } if(!strcmp(argv[1], "autoconf")) diff --git a/tools/munin-plugins-busybox/forks.c b/tools/munin-plugins-busybox/forks.c index 3d4a198e..eac1ccc4 100644 --- a/tools/munin-plugins-busybox/forks.c +++ b/tools/munin-plugins-busybox/forks.c @@ -18,6 +18,7 @@ int forks(int argc, char **argv) { "forks.min 0\n" "forks.max 100000\n" "forks.info The number of forks per second."); + print_warncrit("forks"); return 0; } if(!strcmp(argv[1], "autoconf")) { diff --git a/tools/munin-plugins-busybox/if_err_.c b/tools/munin-plugins-busybox/if_err_.c index caee6b3a..9bb62570 100644 --- a/tools/munin-plugins-busybox/if_err_.c +++ b/tools/munin-plugins-busybox/if_err_.c @@ -3,6 +3,7 @@ #include #include #include +#include "common.h" #define PROC_NET_DEV "/proc/net/dev" @@ -74,6 +75,8 @@ int if_err_(int argc, char **argv) { "trans.type COUNTER\n" "trans.negative rcvd\n" "trans.warning 1"); + print_warncrit("rcvd"); + print_warncrit("trans"); return 0; } } diff --git a/tools/munin-plugins-busybox/interrupts.c b/tools/munin-plugins-busybox/interrupts.c index 32171f6d..d38e05f2 100644 --- a/tools/munin-plugins-busybox/interrupts.c +++ b/tools/munin-plugins-busybox/interrupts.c @@ -23,6 +23,8 @@ int interrupts(int argc, char **argv) { "ctx.max 100000\n" "intr.min 0\n" "ctx.min 0"); + print_warncrit("intr"); + print_warncrit("ctx"); return 0; } if(!strcmp(argv[1], "autoconf")) { diff --git a/tools/munin-plugins-busybox/load.c b/tools/munin-plugins-busybox/load.c index ee1491c1..8161890f 100644 --- a/tools/munin-plugins-busybox/load.c +++ b/tools/munin-plugins-busybox/load.c @@ -16,9 +16,7 @@ int load(int argc, char **argv) { "graph_scale no\n" "graph_category system\n" "load.label load"); - printf("load.warning %d\nload.critical %d\n", - getenvint("load_warn", 10), - getenvint("load_crit", 120)); + print_warncrit("load"); return 0; } if(!strcmp(argv[1], "autoconf")) diff --git a/tools/munin-plugins-busybox/open_inodes.c b/tools/munin-plugins-busybox/open_inodes.c index d9e86577..a8db64f6 100644 --- a/tools/munin-plugins-busybox/open_inodes.c +++ b/tools/munin-plugins-busybox/open_inodes.c @@ -19,7 +19,8 @@ int open_inodes(int argc, char **argv) { "used.info The number of currently open inodes.\n" "max.label inode table size\n" "max.info The size of the system inode table. This is dynamically adjusted by the kernel."); - + print_warncrit("used"); + print_warncrit("max"); return 0; } if(!strcmp(argv[1], "autoconf")) { diff --git a/tools/munin-plugins-busybox/swap.c b/tools/munin-plugins-busybox/swap.c index 3decfbb0..a1b67234 100644 --- a/tools/munin-plugins-busybox/swap.c +++ b/tools/munin-plugins-busybox/swap.c @@ -23,7 +23,8 @@ int swap(int argc, char **argv) { "swap_out.max 100000\n" "swap_out.min 0\n" "swap_out.negative swap_in"); - + print_warncrit("swap_in"); + print_warncrit("swap_out"); return 0; } if(!strcmp(argv[1], "autoconf")) { diff --git a/tools/munin-plugins-busybox/uptime.c b/tools/munin-plugins-busybox/uptime.c index ce6093fa..bb3e02cd 100644 --- a/tools/munin-plugins-busybox/uptime.c +++ b/tools/munin-plugins-busybox/uptime.c @@ -12,6 +12,7 @@ int uptime(int argc, char **argv) { "graph_vlabel uptime in days\n" "uptime.label uptime\n" "uptime.draw AREA"); + print_warncrit("uptime"); return 0; } if(!strcmp(argv[1], "autoconf"))