1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
3 |
> |
* http://www.i-scream.org |
4 |
|
* Copyright (C) 2000-2002 i-scream |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or |
26 |
|
#include <string.h> |
27 |
|
#include <sys/types.h> |
28 |
|
#include <sys/socket.h> |
29 |
+ |
#include <sys/ioctl.h> |
30 |
|
#include <unistd.h> |
31 |
|
#include <stdlib.h> |
32 |
|
#include <ukcprog.h> |
414 |
|
machine_data_list->diskio_data_list=NULL; |
415 |
|
*md=machine_data_list; |
416 |
|
num_hosts++; |
417 |
+ |
} else { |
418 |
+ |
xmlFree(hostname); |
419 |
|
} |
420 |
|
|
421 |
|
/* Now we want to pull out the data */ |
966 |
|
signal(SIGWINCH, sig_winch_handler); |
967 |
|
} |
968 |
|
|
969 |
+ |
void usage() { |
970 |
+ |
printf("Usage: idar [-o order] [-s server] [-p port] [-l list] [-h]\n\n"); |
971 |
+ |
printf(" -o Sets the initial sort order. Accepted arguments are one of:\n"); |
972 |
+ |
printf(" cpu load mem swap net disk\n"); |
973 |
+ |
printf(" -s Specifies the i-scream server to connect to.\n"); |
974 |
+ |
printf(" default: %s\n", DEF_SERVER_NAME); |
975 |
+ |
printf(" -p Specifies the i-scream server port.\n"); |
976 |
+ |
printf(" default: %d\n", DEF_SERVER_PORT); |
977 |
+ |
printf(" -l Sets the list of hosts to monitor in a semi-colon separated list.\n"); |
978 |
+ |
printf(" -h Displays this help information.\n"); |
979 |
+ |
printf("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
980 |
+ |
exit(1); |
981 |
+ |
} |
982 |
+ |
|
983 |
|
int main(int argc, char **argv){ |
984 |
|
WINDOW *window; |
985 |
|
fd_set infds; |
991 |
|
char *machine_list=NULL; |
992 |
|
char *response=NULL; |
993 |
|
|
994 |
< |
char *servername; |
994 |
> |
char *server_name; |
995 |
|
int server_control_port; |
996 |
|
int server_data_port; |
997 |
|
|
1007 |
|
extern int errno; |
1008 |
|
|
1009 |
|
display_config_t display_config; |
1010 |
< |
char ch; |
1010 |
> |
int ch; |
1011 |
|
|
1012 |
|
int data_fileno, stdin_fileno, biggest_fileno; |
1013 |
|
|
1055 |
|
|
1056 |
|
signal(SIGWINCH, sig_winch_handler); |
1057 |
|
|
1058 |
< |
while((cmdopt=getopt(argc, argv, "s:")) != -1){ |
1058 |
> |
server_name=DEF_SERVER_NAME; |
1059 |
> |
server_control_port=DEF_SERVER_PORT; |
1060 |
> |
|
1061 |
> |
while((cmdopt=getopt(argc, argv, "o:s:p:l:h")) != -1){ |
1062 |
|
switch(cmdopt){ |
1063 |
< |
case 's': |
1063 |
> |
case 'o': |
1064 |
|
if(!strcmp(optarg, "cpu")){ |
1065 |
|
sortby_ptr=cmp_cpu_used; |
1066 |
|
strlcpy(display_config.sortby, CPU_USED, SORTBYMAXNAME); |
1074 |
|
strlcpy(display_config.sortby, MEM, SORTBYMAXNAME); |
1075 |
|
} |
1076 |
|
if(!strcmp(optarg, "swap")){ |
1077 |
< |
sortby_ptr=cmp_swap_used_pecent; |
1078 |
< |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
1079 |
< |
} |
1077 |
> |
sortby_ptr=cmp_swap_used_pecent; |
1078 |
> |
strlcpy(display_config.sortby, SWAP, SORTBYMAXNAME); |
1079 |
> |
} |
1080 |
> |
if(!strcmp(optarg, "net")){ |
1081 |
> |
sortby_ptr=cmp_network_io_total; |
1082 |
> |
strlcpy(display_config.sortby, NETIO, SORTBYMAXNAME); |
1083 |
> |
} |
1084 |
> |
if(!strcmp(optarg, "disk")){ |
1085 |
> |
sortby_ptr=cmp_disk_io_total; |
1086 |
> |
strlcpy(display_config.sortby, DISKIO, SORTBYMAXNAME); |
1087 |
> |
} |
1088 |
|
if(sortby_ptr==NULL){ |
1089 |
< |
errf("Invalid sort type"); |
1090 |
< |
exit(1); |
1089 |
> |
errf("Invalid order given."); |
1090 |
> |
usage(); |
1091 |
|
} |
1092 |
< |
break; |
1092 |
> |
break; |
1093 |
> |
case 's': |
1094 |
> |
server_name=optarg; |
1095 |
> |
break; |
1096 |
> |
case 'p': |
1097 |
> |
server_control_port=atoi(optarg); |
1098 |
> |
break; |
1099 |
> |
case 'l': |
1100 |
> |
/* We've been passed a machine list */ |
1101 |
> |
/* list currently needs to be ; seperated */ |
1102 |
> |
machine_list=strdup(optarg); |
1103 |
> |
break; |
1104 |
> |
case 'h': |
1105 |
> |
default: |
1106 |
> |
usage(); |
1107 |
> |
break; |
1108 |
|
} |
1109 |
|
} |
1110 |
|
|
1111 |
+ |
/* Don't take any other arguments */ |
1112 |
+ |
if(argc>optind){ |
1113 |
+ |
usage(); |
1114 |
+ |
} |
1115 |
+ |
|
1116 |
|
if(sortby_ptr==NULL){ |
1117 |
|
sortby_ptr=cmp_cpu_used; |
1118 |
|
strlcpy(display_config.sortby, "CPU Used", SORTBYMAXNAME); |
1119 |
|
} |
1120 |
|
|
1121 |
< |
servername=DEF_SERVER_NAME; |
1074 |
< |
server_control_port=DEF_SERVER_PORT; |
1075 |
< |
|
1076 |
< |
if(argc>=(optind+2)){ |
1077 |
< |
servername=argv[optind]; |
1078 |
< |
server_control_port=atoi(argv[optind+1]); |
1079 |
< |
} |
1080 |
< |
|
1081 |
< |
control=create_tcp_connection(servername, server_control_port); |
1121 |
> |
control=create_tcp_connection(server_name, server_control_port); |
1122 |
|
if(control==NULL){ |
1123 |
|
errf("Failed to connect (%m)"); |
1124 |
|
exit(1); |
1125 |
|
} |
1126 |
|
|
1087 |
– |
if(argc==4){ |
1088 |
– |
/* We've been passed a machine list */ |
1089 |
– |
/* list currently needs to be ; seperated */ |
1090 |
– |
machine_list=strdup(argv[3]); |
1091 |
– |
} |
1092 |
– |
|
1127 |
|
if((tcp_comm(control, NULL, &response, "PROTOCOL 1.1"))!=0){ |
1128 |
|
errf("Incorrect version number (%s)", response); |
1129 |
|
exit(1); |
1156 |
|
exit(1); |
1157 |
|
} |
1158 |
|
|
1159 |
< |
data=create_tcp_connection(servername, server_data_port); |
1159 |
> |
data=create_tcp_connection(server_name, server_data_port); |
1160 |
|
if(data==NULL){ |
1161 |
< |
errf("Failed to connect to host %s on port %d (%m)",servername, server_data_port); |
1161 |
> |
errf("Failed to connect to host %s on port %d (%m)",server_name, server_data_port); |
1162 |
|
exit(1); |
1163 |
|
} |
1164 |
|
|