2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

support warning and critical environment variables

Like the mainline plugins do.
This commit is contained in:
Helmut Grohne 2013-01-30 12:14:28 +01:00
parent 8fbe0ebe27
commit cbfa6b4578
10 changed files with 60 additions and 5 deletions

View File

@ -1,5 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h>
extern char **environ;
int writeyes(void) { int writeyes(void) {
puts("yes"); puts("yes");
@ -21,3 +25,42 @@ int getenvint(const char *name, int defvalue) {
return defvalue; return defvalue;
return atoi(value); 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);
}

View File

@ -6,5 +6,9 @@
int writeyes(void); int writeyes(void);
int writeno(const char *); int writeno(const char *);
int getenvint(const char *, int); 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 #endif

View File

@ -17,6 +17,7 @@ int entropy(int argc, char **argv) {
"graph_info This graph shows the amount of entropy available in the system.\n" "graph_info This graph shows the amount of entropy available in the system.\n"
"entropy.label entropy\n" "entropy.label entropy\n"
"entropy.info The number of random bytes available. This is typically used by cryptographic applications."); "entropy.info The number of random bytes available. This is typically used by cryptographic applications.");
print_warncrit("entropy");
return 0; return 0;
} }
if(!strcmp(argv[1], "autoconf")) if(!strcmp(argv[1], "autoconf"))

View File

@ -18,6 +18,7 @@ int forks(int argc, char **argv) {
"forks.min 0\n" "forks.min 0\n"
"forks.max 100000\n" "forks.max 100000\n"
"forks.info The number of forks per second."); "forks.info The number of forks per second.");
print_warncrit("forks");
return 0; return 0;
} }
if(!strcmp(argv[1], "autoconf")) { if(!strcmp(argv[1], "autoconf")) {

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "common.h"
#define PROC_NET_DEV "/proc/net/dev" #define PROC_NET_DEV "/proc/net/dev"
@ -74,6 +75,8 @@ int if_err_(int argc, char **argv) {
"trans.type COUNTER\n" "trans.type COUNTER\n"
"trans.negative rcvd\n" "trans.negative rcvd\n"
"trans.warning 1"); "trans.warning 1");
print_warncrit("rcvd");
print_warncrit("trans");
return 0; return 0;
} }
} }

View File

@ -23,6 +23,8 @@ int interrupts(int argc, char **argv) {
"ctx.max 100000\n" "ctx.max 100000\n"
"intr.min 0\n" "intr.min 0\n"
"ctx.min 0"); "ctx.min 0");
print_warncrit("intr");
print_warncrit("ctx");
return 0; return 0;
} }
if(!strcmp(argv[1], "autoconf")) { if(!strcmp(argv[1], "autoconf")) {

View File

@ -16,9 +16,7 @@ int load(int argc, char **argv) {
"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", print_warncrit("load");
getenvint("load_warn", 10),
getenvint("load_crit", 120));
return 0; return 0;
} }
if(!strcmp(argv[1], "autoconf")) if(!strcmp(argv[1], "autoconf"))

View File

@ -19,7 +19,8 @@ int open_inodes(int argc, char **argv) {
"used.info The number of currently open inodes.\n" "used.info The number of currently open inodes.\n"
"max.label inode table size\n" "max.label inode table size\n"
"max.info The size of the system inode table. This is dynamically adjusted by the kernel."); "max.info The size of the system inode table. This is dynamically adjusted by the kernel.");
print_warncrit("used");
print_warncrit("max");
return 0; return 0;
} }
if(!strcmp(argv[1], "autoconf")) { if(!strcmp(argv[1], "autoconf")) {

View File

@ -23,7 +23,8 @@ int swap(int argc, char **argv) {
"swap_out.max 100000\n" "swap_out.max 100000\n"
"swap_out.min 0\n" "swap_out.min 0\n"
"swap_out.negative swap_in"); "swap_out.negative swap_in");
print_warncrit("swap_in");
print_warncrit("swap_out");
return 0; return 0;
} }
if(!strcmp(argv[1], "autoconf")) { if(!strcmp(argv[1], "autoconf")) {

View File

@ -12,6 +12,7 @@ int uptime(int argc, char **argv) {
"graph_vlabel uptime in days\n" "graph_vlabel uptime in days\n"
"uptime.label uptime\n" "uptime.label uptime\n"
"uptime.draw AREA"); "uptime.draw AREA");
print_warncrit("uptime");
return 0; return 0;
} }
if(!strcmp(argv[1], "autoconf")) if(!strcmp(argv[1], "autoconf"))