1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

extract function getenvint to common.c

This commit is contained in:
Helmut Grohne 2013-01-28 16:35:25 +01:00
parent 50b2baaf69
commit c01ddbb0c0
3 changed files with 13 additions and 13 deletions

View file

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int writeyes(void) { int writeyes(void) {
puts("yes"); puts("yes");
@ -12,3 +13,11 @@ int writeno(const char *s) {
puts("no"); puts("no");
return 1; return 1;
} }
int getenvint(const char *name, int defvalue) {
const char *value;
value = getenv(name);
if(value == NULL)
return defvalue;
return atoi(value);
}

View file

@ -5,5 +5,6 @@
int writeyes(void); int writeyes(void);
int writeno(const char *); int writeno(const char *);
int getenvint(const char *, int);
#endif #endif

View file

@ -7,28 +7,18 @@
int load(int argc, char **argv) { int load(int argc, char **argv) {
FILE *f; FILE *f;
int warn, crit;
float val; float val;
char *s;
if(argc > 1) { if(argc > 1) {
if(!strcmp(argv[1], "config")) { 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" puts("graph_title Load average\n"
"graph_args --base 1000 -l 0\n" "graph_args --base 1000 -l 0\n"
"graph_vlabel load\n" "graph_vlabel load\n"
"graph_scale no\n" "graph_scale no\n"
"graph_category system\n" "graph_category system\n"
"load.label load"); "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; return 0;
} }
if(!strcmp(argv[1], "autoconf")) if(!strcmp(argv[1], "autoconf"))