| 1 |
|
/* |
| 2 |
|
* i-scream central monitoring system |
| 3 |
|
* http://www.i-scream.org |
| 4 |
< |
* Copyright (C) 2000-2003 i-scream |
| 4 |
> |
* Copyright (C) 2000-2004 i-scream |
| 5 |
|
* |
| 6 |
|
* This program is free software; you can redistribute it and/or |
| 7 |
|
* modify it under the terms of the GNU General Public License |
| 16 |
|
* You should have received a copy of the GNU General Public License |
| 17 |
|
* along with this program; if not, write to the Free Software |
| 18 |
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
+ |
* |
| 20 |
+ |
* $Id$ |
| 21 |
|
*/ |
| 22 |
|
|
| 23 |
|
#ifdef HAVE_CONFIG_H |
| 37 |
|
FLOAT, |
| 38 |
|
DOUBLE, |
| 39 |
|
STRING, |
| 40 |
< |
INT |
| 40 |
> |
INT, |
| 41 |
> |
BOOL, |
| 42 |
> |
DUPLEX |
| 43 |
|
} stat_type; |
| 44 |
|
|
| 45 |
|
typedef enum { |
| 350 |
|
void populate_net() { |
| 351 |
|
int n, i; |
| 352 |
|
network_stat_t *net; |
| 353 |
+ |
network_iface_stat_t *iface; |
| 354 |
|
|
| 355 |
|
net = use_diffs ? get_network_stats_diff(&n) : get_network_stats(&n); |
| 356 |
|
if (net != NULL) { |
| 363 |
|
"net", name, "tx", NULL); |
| 364 |
|
add_stat(LONG_LONG, &net[i].rx, |
| 365 |
|
"net", name, "rx", NULL); |
| 366 |
+ |
add_stat(LONG_LONG, &net[i].ipackets, |
| 367 |
+ |
"net", name, "ipackets", NULL); |
| 368 |
+ |
add_stat(LONG_LONG, &net[i].opackets, |
| 369 |
+ |
"net", name, "opackets", NULL); |
| 370 |
+ |
add_stat(LONG_LONG, &net[i].ierrors, |
| 371 |
+ |
"net", name, "ierrors", NULL); |
| 372 |
+ |
add_stat(LONG_LONG, &net[i].oerrors, |
| 373 |
+ |
"net", name, "oerrors", NULL); |
| 374 |
+ |
add_stat(LONG_LONG, &net[i].collisions, |
| 375 |
+ |
"net", name, "collisions", NULL); |
| 376 |
|
add_stat(TIME_T, &net[i].systime, |
| 377 |
|
"net", name, "systime", NULL); |
| 378 |
|
} |
| 379 |
|
} |
| 380 |
+ |
|
| 381 |
+ |
iface = get_network_iface_stats(&n); |
| 382 |
+ |
if (iface != NULL) { |
| 383 |
+ |
for (i = 0; i < n; i++) { |
| 384 |
+ |
const char *name = iface[i].interface_name; |
| 385 |
+ |
|
| 386 |
+ |
add_stat(INT, &iface[i].speed, |
| 387 |
+ |
"net", name, "speed", NULL); |
| 388 |
+ |
add_stat(BOOL, &iface[i].up, |
| 389 |
+ |
"net", name, "up", NULL); |
| 390 |
+ |
add_stat(DUPLEX, &iface[i].dup, |
| 391 |
+ |
"net", name, "duplex", NULL); |
| 392 |
+ |
} |
| 393 |
+ |
} |
| 394 |
|
} |
| 395 |
|
|
| 396 |
|
void populate_page() { |
| 459 |
|
t->populate(); |
| 460 |
|
} |
| 461 |
|
|
| 462 |
< |
qsort(stats, num_stats, sizeof *stats, stats_compare); |
| 462 |
> |
if (stats != NULL) |
| 463 |
> |
qsort(stats, num_stats, sizeof *stats, stats_compare); |
| 464 |
|
} |
| 465 |
|
|
| 466 |
|
/* Print the value of a stat. */ |
| 488 |
|
case INT: |
| 489 |
|
printf("%d", *(int *)v); |
| 490 |
|
break; |
| 491 |
+ |
case BOOL: |
| 492 |
+ |
printf("%s", *(int *)v ? "true" : "false"); |
| 493 |
+ |
break; |
| 494 |
+ |
case DUPLEX: |
| 495 |
+ |
switch (*(statgrab_duplex *) v) { |
| 496 |
+ |
case FULL_DUPLEX: |
| 497 |
+ |
printf("full"); |
| 498 |
+ |
break; |
| 499 |
+ |
case HALF_DUPLEX: |
| 500 |
+ |
printf("half"); |
| 501 |
+ |
break; |
| 502 |
+ |
default: |
| 503 |
+ |
printf("unknown"); |
| 504 |
+ |
break; |
| 505 |
+ |
} |
| 506 |
+ |
break; |
| 507 |
|
} |
| 508 |
|
} |
| 509 |
|
|
| 546 |
|
else |
| 547 |
|
compare = stats_compare; |
| 548 |
|
|
| 549 |
< |
s = (const stat *)bsearch(&key, stats, num_stats, |
| 550 |
< |
sizeof *stats, compare); |
| 549 |
> |
if (stats == NULL) { |
| 550 |
> |
s = NULL; |
| 551 |
> |
} else { |
| 552 |
> |
s = (const stat *)bsearch(&key, stats, |
| 553 |
> |
num_stats, |
| 554 |
> |
sizeof *stats, |
| 555 |
> |
compare); |
| 556 |
> |
} |
| 557 |
> |
|
| 558 |
|
if (s == NULL) { |
| 559 |
|
printf("Unknown stat %s\n", name); |
| 560 |
|
continue; |
| 661 |
|
/* We don't care if statgrab_init fails, because we can just display |
| 662 |
|
the statistics that can be read as non-root. */ |
| 663 |
|
statgrab_init(); |
| 664 |
< |
#ifdef ALLBSD |
| 665 |
< |
if (setegid(getgid()) != 0) |
| 613 |
< |
die("Failed to lose effective group"); |
| 614 |
< |
#endif |
| 615 |
< |
#ifdef SOLARIS |
| 616 |
< |
if (seteuid(getuid()) != 0) |
| 617 |
< |
die("Failed to lose effective user"); |
| 618 |
< |
#endif |
| 664 |
> |
if (statgrab_drop_privileges() != 0) |
| 665 |
> |
die("Failed to drop setuid/setgid privileges"); |
| 666 |
|
|
| 667 |
|
switch (repeat_mode) { |
| 668 |
|
case REPEAT_NONE: |