root / tools / munin-node-c / main.c @ 1d56b584
Historique | Voir | Annoter | Télécharger (1,59 ko)
| 1 |
#include <libgen.h> |
|---|---|
| 2 |
#include <string.h> |
| 3 |
#include <stdio.h> |
| 4 |
#include <unistd.h> |
| 5 |
#include <limits.h> |
| 6 |
|
| 7 |
|
| 8 |
char VERSION[] = "1.0.0"; |
| 9 |
|
| 10 |
int verbose;
|
| 11 |
|
| 12 |
char* host = ""; |
| 13 |
char* plugin_dir = "plugins"; |
| 14 |
char* spoolfetch_dir = ""; |
| 15 |
|
| 16 |
int main(int argc, char *argv[]) { |
| 17 |
|
| 18 |
int optch;
|
| 19 |
extern int opterr; |
| 20 |
int optarg_len;
|
| 21 |
|
| 22 |
char format[] = "vd:h:s:"; |
| 23 |
|
| 24 |
char line[LINE_MAX];
|
| 25 |
|
| 26 |
opterr = 1;
|
| 27 |
|
| 28 |
while ((optch = getopt(argc, argv, format)) != -1) |
| 29 |
switch (optch) {
|
| 30 |
case 'v': |
| 31 |
verbose ++; |
| 32 |
break;
|
| 33 |
case 'd': |
| 34 |
optarg_len = strlen(optarg); |
| 35 |
plugin_dir = (char *) malloc(optarg_len + 1); |
| 36 |
strcpy(plugin_dir, optarg); |
| 37 |
break;
|
| 38 |
case 'h': |
| 39 |
optarg_len = strlen(optarg); |
| 40 |
host = (char *) malloc(optarg_len + 1); |
| 41 |
strcpy(host, optarg); |
| 42 |
break;
|
| 43 |
case 's': |
| 44 |
optarg_len = strlen(optarg); |
| 45 |
spoolfetch_dir = (char *) malloc(optarg_len + 1); |
| 46 |
strcpy(spoolfetch_dir, optarg); |
| 47 |
break;
|
| 48 |
} |
| 49 |
|
| 50 |
/* get default hostname if not precised */
|
| 51 |
if (! strlen(host)) {
|
| 52 |
host = (char *) malloc(HOST_NAME_MAX + 1); |
| 53 |
gethostname(host, HOST_NAME_MAX); |
| 54 |
} |
| 55 |
|
| 56 |
printf("# munin node at %s\n", host);
|
| 57 |
while (fgets(line, LINE_MAX, stdin) != NULL) { |
| 58 |
char* cmd;
|
| 59 |
char* arg;
|
| 60 |
|
| 61 |
line[LINE_MAX-1] = '\0'; |
| 62 |
|
| 63 |
cmd = strtok(line, " \t\n");
|
| 64 |
arg = strtok(line, " \t\n");
|
| 65 |
|
| 66 |
if (strlen(cmd) == 0) continue; |
| 67 |
|
| 68 |
if (strcmp(cmd, "version") == 0) { |
| 69 |
} else if (strcmp(cmd, "nodes") == 0) { |
| 70 |
} else if (strcmp(cmd, "quit") == 0) { |
| 71 |
} else if (strcmp(cmd, "list") == 0) { |
| 72 |
} else if (strcmp(cmd, "config") == 0) { |
| 73 |
} else if (strcmp(cmd, "fetch") == 0) { |
| 74 |
} else if (strcmp(cmd, "cap") == 0) { |
| 75 |
} else if (strcmp(cmd, "spoolfetch") == 0) { |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
return 0; |
| 80 |
} |
