mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
support warning and critical environment variables
Like the mainline plugins do.
This commit is contained in:
parent
8fbe0ebe27
commit
cbfa6b4578
10 changed files with 60 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue