diff --git a/tools/munin-plugins-busybox/common.c b/tools/munin-plugins-busybox/common.c index 3d78e518..fd291f06 100644 --- a/tools/munin-plugins-busybox/common.c +++ b/tools/munin-plugins-busybox/common.c @@ -1,4 +1,5 @@ #include +#include int writeyes(void) { puts("yes"); @@ -12,3 +13,11 @@ int writeno(const char *s) { puts("no"); return 1; } + +int getenvint(const char *name, int defvalue) { + const char *value; + value = getenv(name); + if(value == NULL) + return defvalue; + return atoi(value); +} diff --git a/tools/munin-plugins-busybox/common.h b/tools/munin-plugins-busybox/common.h index 8db440a9..2a344085 100644 --- a/tools/munin-plugins-busybox/common.h +++ b/tools/munin-plugins-busybox/common.h @@ -5,5 +5,6 @@ int writeyes(void); int writeno(const char *); +int getenvint(const char *, int); #endif diff --git a/tools/munin-plugins-busybox/load.c b/tools/munin-plugins-busybox/load.c index 27e18437..ee1491c1 100644 --- a/tools/munin-plugins-busybox/load.c +++ b/tools/munin-plugins-busybox/load.c @@ -7,28 +7,18 @@ int load(int argc, char **argv) { FILE *f; - int warn, crit; float val; - char *s; if(argc > 1) { if(!strcmp(argv[1], "config")) { - s = getenv("load_warn"); - if(s) - warn = atoi(s); - else - warn = 10; - s = getenv("load_crit"); - if(s) - crit = atoi(s); - else - crit = 120; puts("graph_title Load average\n" "graph_args --base 1000 -l 0\n" "graph_vlabel load\n" "graph_scale no\n" "graph_category system\n" "load.label load"); - printf("load.warning %d\nload.critical %d\n", warn, crit); + printf("load.warning %d\nload.critical %d\n", + getenvint("load_warn", 10), + getenvint("load_crit", 120)); return 0; } if(!strcmp(argv[1], "autoconf"))