--- projects/cms/source/ihost/ihost.c 2003/08/22 14:40:11 1.41 +++ projects/cms/source/ihost/ihost.c 2004/01/05 15:22:17 1.44 @@ -1,6 +1,6 @@ /* * i-scream central monitoring system - * http://www.i-scream.org.uk + * http://www.i-scream.org * Copyright (C) 2000-2002 i-scream * * This program is free software; you can redistribute it and/or @@ -387,7 +387,7 @@ int ihost_getconfig(ihost_state_t *ihost_state){ goto error; } - printf("string : %s\n", response_ptr); + /*printf("string : %s\n", response_ptr);*/ server_udp_port=atoi(response_ptr); if (server_udp_port==0){ @@ -712,14 +712,18 @@ too_big_error: void usage(char *progname){ - fprintf(stderr, "Usage %s [options] server port\n", progname); - fprintf(stderr, "Options\n"); - fprintf(stderr, " -v Verbose mode,-vv would make even more verbose\n"); - fprintf(stderr, " -f Foreground mode, print errors to stderr\n"); - fprintf(stderr, " -s Set the machine name to be reported as\n"); - fprintf(stderr, " -i Set the IP to be reported as\n"); - fprintf(stderr, " -V Print version number\n"); - fprintf(stderr, " -h Prints this help page\n"); + fprintf(stderr, "Usage %s [-v[v]] [-f] [-n name] [-i ip] [-s server] [-p port] [-V] [-h]\n\n", progname); + fprintf(stderr, " -v Verbose mode, -vv would make even more verbose\n"); + fprintf(stderr, " -f Foreground mode, print errors to stderr\n"); + fprintf(stderr, " -n Set the machine name to be reported as\n"); + fprintf(stderr, " -i Set the IP to be reported as\n"); + fprintf(stderr, " -s Specifies the i-scream server to connect to\n"); + fprintf(stderr, " default: %s\n", DEF_SERVER_NAME); + fprintf(stderr, " -p Specifies the i-scream server port\n"); + fprintf(stderr, " default: %d\n", DEF_SERVER_PORT); + fprintf(stderr, " -V Print version number\n"); + fprintf(stderr, " -h Prints this help page\n"); + fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); exit(1); } @@ -746,7 +750,8 @@ int main(int argc, char **argv){ ihost_config.log=stderr; /* Blank ihost_state to default settings */ - ihost_state.filtermanager_host=NULL; + ihost_state.filtermanager_host=DEF_SERVER_NAME; + ihost_state.filtermanager_port=DEF_SERVER_PORT; ihost_state.host_fqdn=NULL; ihost_state.host_ip=NULL; ihost_state.preset_fqdn = 0; @@ -766,14 +771,10 @@ int main(int argc, char **argv){ ihost_config.daemon=0; break; - case 'h': - usage(argv[0]); - break; - case 'V': fprintf(stderr, "%s version %s\n", argv[0], VERSION); break; - case 's': + case 'n': ihost_state.preset_fqdn = 1; ihost_state.host_fqdn = strdup(optarg); if(ihost_state.host_fqdn == NULL){ @@ -791,20 +792,21 @@ int main(int argc, char **argv){ } break; + case 's': + ihost_state.filtermanager_host=strdup(optarg); + break; + + case 'p': + ihost_state.filtermanager_port=atoi(optarg); + break; + + case 'h': default: usage(argv[0]); exit(1); } } - if(argc!=optind+2){ - usage(argv[0]); - exit(1); - } - - ihost_state.filtermanager_host=strdup(argv[optind]); - ihost_state.filtermanager_port=atoi(argv[optind+1]); - if(gethostbyname(ihost_state.filtermanager_host)==NULL){ log_msg(LOG_CRIT, "Failed to lookup hostname. Please check settings"); exit(1); @@ -841,7 +843,13 @@ int main(int argc, char **argv){ } - log_msg(LOG_INFO, "Starting ihost"); + log_msg(LOG_INFO, "Starting ihost..."); + + log_msg(LOG_DEBUG, "Running statgrab_init()"); + if(!statgrab_init()){ + log_msg(LOG_CRIT, "statgrab_init failed (%m)"); + exit(1); + } log_msg(LOG_DEBUG,"Writing PID FILE"); @@ -858,6 +866,7 @@ int main(int argc, char **argv){ } } + /* Get the initial config from the filter manager. Should this fail, * wait, and then try again. */ @@ -869,7 +878,7 @@ int main(int argc, char **argv){ sleep(10); } - printf("%s\n%d\n", ihost_state.server_fqdn, ihost_state.server_udp_port); + /*printf("%s\n%d\n", ihost_state.server_fqdn, ihost_state.server_udp_port);*/ while((create_udp_sockinfo(&udp_sockinfo, ihost_state.server_fqdn, ihost_state.server_udp_port))!=0){ log_msg(LOG_ERR, "Failed to create udp socket"); sleep(10);