2009-01-22 15:30:31 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2013-01-30 12:14:28 +01:00
|
|
|
#include "common.h"
|
2009-01-22 15:30:31 +01:00
|
|
|
|
|
|
|
#define PROC_NET_DEV "/proc/net/dev"
|
|
|
|
|
|
|
|
int if_err_(int argc, char **argv) {
|
|
|
|
char *interface;
|
2013-02-05 12:38:12 +01:00
|
|
|
size_t interface_len;
|
2009-01-22 15:30:31 +01:00
|
|
|
FILE *f;
|
|
|
|
char buff[256], *s;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
interface = basename(argv[0]);
|
2013-02-05 12:38:12 +01:00
|
|
|
if(strncmp(interface, "if_err_", 7) != 0)
|
|
|
|
return fail("if_err_ invoked with invalid basename");
|
2009-01-22 15:30:31 +01:00
|
|
|
interface += 7;
|
2013-02-05 12:38:12 +01:00
|
|
|
interface_len = strlen(interface);
|
2009-01-22 15:30:31 +01:00
|
|
|
|
|
|
|
if(argc > 1) {
|
2013-02-05 12:38:12 +01:00
|
|
|
if(!strcmp(argv[1], "autoconf"))
|
|
|
|
return autoconf_check_readable(PROC_NET_DEV);
|
2009-01-22 15:30:31 +01:00
|
|
|
if(!strcmp(argv[1], "suggest")) {
|
|
|
|
if(NULL == (f = fopen(PROC_NET_DEV, "r")))
|
|
|
|
return 1;
|
|
|
|
while(fgets(buff, 256, f)) {
|
|
|
|
for(s=buff;*s == ' ';++s)
|
|
|
|
;
|
|
|
|
i = 0;
|
2013-02-04 21:50:26 +01:00
|
|
|
if(!strncmp(s, "lo:", 3))
|
2009-01-22 15:30:31 +01:00
|
|
|
continue;
|
2013-02-04 21:50:26 +01:00
|
|
|
if(!strncmp(s, "sit", 3)) {
|
|
|
|
for(i=3; isdigit(s[i]); ++i)
|
|
|
|
;
|
|
|
|
if(s[i] == ':')
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while(s[i] != ':' && s[i] != '\0')
|
2009-01-22 15:30:31 +01:00
|
|
|
++i;
|
|
|
|
if(s[i] != ':')
|
2013-02-04 21:50:26 +01:00
|
|
|
continue; /* a header line */
|
2009-01-22 15:30:31 +01:00
|
|
|
s[i] = '\0';
|
|
|
|
puts(s);
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!strcmp(argv[1], "config")) {
|
|
|
|
puts("graph_order rcvd trans");
|
|
|
|
printf("graph_title %s errors\n", interface);
|
|
|
|
puts("graph_args --base 1000\n"
|
|
|
|
"graph_vlabel packets in (-) / out (+) per "
|
|
|
|
"${graph_period}\n"
|
|
|
|
"graph_category network");
|
|
|
|
printf("graph_info This graph shows the amount of "
|
|
|
|
"errors on the %s network interface.\n",
|
|
|
|
interface);
|
|
|
|
puts("rcvd.label packets\n"
|
|
|
|
"rcvd.type COUNTER\n"
|
|
|
|
"rcvd.graph no\n"
|
|
|
|
"rcvd.warning 1\n"
|
|
|
|
"trans.label packets\n"
|
|
|
|
"trans.type COUNTER\n"
|
|
|
|
"trans.negative rcvd\n"
|
|
|
|
"trans.warning 1");
|
2013-01-30 12:14:28 +01:00
|
|
|
print_warncrit("rcvd");
|
|
|
|
print_warncrit("trans");
|
2009-01-22 15:30:31 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(NULL == (f = fopen(PROC_NET_DEV, "r")))
|
|
|
|
return 1;
|
|
|
|
while(fgets(buff, 256, f)) {
|
|
|
|
for(s=buff;*s == ' ';++s)
|
|
|
|
;
|
2013-02-05 12:38:12 +01:00
|
|
|
if(0 != strncmp(s, interface, interface_len))
|
2009-01-22 15:30:31 +01:00
|
|
|
continue;
|
2013-02-05 12:38:12 +01:00
|
|
|
s += interface_len;
|
2009-01-22 15:30:31 +01:00
|
|
|
if(*s != ':')
|
|
|
|
continue;
|
|
|
|
++s;
|
|
|
|
|
|
|
|
while(*s == ' ')
|
|
|
|
++s;
|
|
|
|
|
|
|
|
for(i=1;i<3;++i) {
|
|
|
|
while(isdigit(*s))
|
|
|
|
++s;
|
|
|
|
while(isspace(*s))
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
for(i=0;isdigit(s[i]);++i)
|
|
|
|
;
|
|
|
|
printf("rcvd.value ");
|
|
|
|
fwrite(s, 1, i, stdout);
|
|
|
|
putchar('\n');
|
|
|
|
s += i;
|
|
|
|
while(isspace(*s))
|
|
|
|
++s;
|
|
|
|
|
|
|
|
for(i=4;i<11;++i) {
|
|
|
|
while(isdigit(*s))
|
|
|
|
++s;
|
|
|
|
while(isspace(*s))
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
for(i=0;isdigit(s[i]);++i)
|
|
|
|
;
|
|
|
|
printf("trans.value ");
|
|
|
|
fwrite(s, 1, i, stdout);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2013-02-05 12:40:56 +01:00
|
|
|
fclose(f);
|
2009-01-22 15:30:31 +01:00
|
|
|
return 0;
|
|
|
|
}
|