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:
parent
8fbe0ebe27
commit
cbfa6b4578
@ -1,5 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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"))
|
||||
|
@ -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")) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
@ -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")) {
|
||||
|
@ -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"))
|
||||
|
@ -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")) {
|
||||
|
@ -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")) {
|
||||
|
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user