1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 18:07:20 +00:00

mnc,mpc: move them to own repo

This commit is contained in:
Steve Schnepp 2013-03-02 20:22:46 +01:00
parent e5ceabe428
commit 2e03d0c551
21 changed files with 5 additions and 1220 deletions

View file

@ -1,24 +0,0 @@
CC=gcc
CFLAGS=-W -Wall -pedantic -Wextra -g -O2
OBJS=main.o
LINKS=
%.o: %.c
${CC} ${CFLAGS} -c $< -o $@
all: munin-node-c
munin-node-c: ${OBJS}
${CC} ${CFLAGS} $^ -o $@
clean:
rm -f munin-node-c ${OBJS} ${LINKS}
rm -Rf plugins
plugins: plugins/.munin-plugins-busybox.installed
plugins/.munin-plugins-busybox.installed:
mkdir -p plugins
cd ../munin-plugins-busybox && $(MAKE)
cd plugins && for i in $$(find ../../munin-plugins-busybox -type l); do ln -s $$i; done
touch plugins/.munin-plugins-busybox.installed
.PHONY: all clean plugins

View file

@ -1,28 +1,5 @@
This is a rewrite of munin node in C.
Pro:
----
It has moved together with munin-plugins-c to its own repo:
The purpose is multiple:
* reducing resource usage for embedded plateforms, specially when paired
with the C rewrite of the core plugins.
* no need for Perl
* Everything runs from inetd.
Cons:
-----
* You lose flexibility
It is compiled code, so you have to create binaries. Even one for each
architecture.
* Not all the features are implemented
- root uid is not supported. All plugins are run with a single user, usually nobody.
- no socket is opened. Everything runs from inetd.
GPLv2 - (C) 2013 Steve SCHNEPP <steve.schnepp@pwkf.org>
munin-c.git

View file

@ -1,145 +0,0 @@
#include <libgen.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
char VERSION[] = "1.0.0";
int verbose = 0;
char* host = "";
char* plugin_dir = "plugins";
char* spoolfetch_dir = "";
int main(int argc, char *argv[]) {
int optch;
extern int opterr;
int optarg_len;
char format[] = "vd:h:s:";
char line[LINE_MAX];
opterr = 1;
while ((optch = getopt(argc, argv, format)) != -1)
switch (optch) {
case 'v':
verbose ++;
break;
case 'd':
optarg_len = strlen(optarg);
plugin_dir = (char *) malloc(optarg_len + 1);
strcpy(plugin_dir, optarg);
break;
case 'h':
optarg_len = strlen(optarg);
host = (char *) malloc(optarg_len + 1);
strcpy(host, optarg);
break;
case 's':
optarg_len = strlen(optarg);
spoolfetch_dir = (char *) malloc(optarg_len + 1);
strcpy(spoolfetch_dir, optarg);
break;
}
/* get default hostname if not precised */
if (! strlen(host)) {
host = (char *) malloc(HOST_NAME_MAX + 1);
gethostname(host, HOST_NAME_MAX);
}
printf("# munin node at %s\n", host);
while (fgets(line, LINE_MAX, stdin) != NULL) {
char* cmd;
char* arg;
line[LINE_MAX-1] = '\0';
cmd = strtok(line, " \t\n");
if(cmd == NULL)
arg = NULL;
else
arg = strtok(NULL, " \t\n");
if (!cmd || strlen(cmd) == 0) {
printf("# empty cmd\n");
} else if (strcmp(cmd, "version") == 0) {
printf("munin c node version: %s\n", VERSION);
} else if (strcmp(cmd, "nodes") == 0) {
printf("%s\n", host);
printf(".\n");
} else if (strcmp(cmd, "quit") == 0) {
return(0);
} else if (strcmp(cmd, "list") == 0) {
DIR* dirp = opendir(plugin_dir);
struct dirent* dp;
while ((dp = readdir(dirp)) != NULL) {
char cmdline[LINE_MAX];
char* plugin_filename = dp->d_name;;
if (plugin_filename[0] == '.') {
/* No dotted plugin */
continue;
}
snprintf(cmdline, LINE_MAX, "%s/%s", plugin_dir, plugin_filename);
if (access(cmdline, X_OK) == 0) {
printf("%s ", plugin_filename);
}
}
printf("\n");
closedir(dirp);
} else if (
strcmp(cmd, "config") == 0 ||
strcmp(cmd, "fetch") == 0
) {
char cmdline[LINE_MAX];
pid_t pid;
if(arg == NULL) {
printf("# no plugin given\n");
continue;
}
if(arg[0] == '.' || strchr(arg, '/')) {
printf("# invalid plugin character");
continue;
}
snprintf(cmdline, LINE_MAX, "%s/%s", plugin_dir, arg);
if (access(cmdline, X_OK) == -1) {
printf("# unknown plugin: %s\n", arg);
continue;
}
if(0 == (pid = vfork())) {
execl(cmdline, arg, cmd, NULL);
/* according to vfork(2) we must use _exit */
_exit(1);
} else if(pid < 0) {
printf("# fork failed\n");
continue;
} else {
waitpid(pid, NULL, 0);
}
printf(".\n");
} else if (strcmp(cmd, "cap") == 0) {
printf("cap ");
if (strlen(spoolfetch_dir)) {
printf("spool ");
}
printf("\n");
} else if (strcmp(cmd, "spoolfetch") == 0) {
printf("# not implem yet cmd: %s\n", cmd);
} else {
printf("# unknown cmd: %s\n", cmd);
}
}
return 0;
}