- hosts[n] = malloc(sizeof(struct monitor_host));
- hosts[n]->name = strdup(cfg->dict[i]->name);
- hosts[n]->ping_interval = atoi (cfg->dict[i]->value[0]);
- hosts[n]->max_delay = atoi (cfg->dict[i]->value[1]);
- hosts[n]->upcmd = strdup(cfg->dict[i]->value[2]);
- hosts[n]->downcmd = strdup(cfg->dict[i]->value[3]);
-
- if (cfg->dict[i]->nvalues == 4) {
- hosts[n]->hostup = true;
- } else if (strcmp(cfg->dict[i]->value[4], "up") == 0) {
- hosts[n]->hostup = true;
- } else if (strcmp(cfg->dict[i]->value[4], "down") == 0) {
- hosts[n]->hostup = false;
- } else if (strcmp(cfg->dict[i]->value[4], "auto") == 0) {
- /* TODO: Send a ping and set initial state accordingly. */
- } else {
- fprintf(stderr, "ERROR: Illegal value %s in record %d for startup condition.\n", cfg->dict[i]->value[4], n);
+ struct host_entry * cur_host = malloc(sizeof(struct host_entry));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "host", MAXCONFKEYLEN);
+ cur_host->name = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "interval", MAXCONFKEYLEN);
+ cur_host->ping_interval = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "max_delay", MAXCONFKEYLEN);
+ cur_host->max_delay = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "up_cmd", MAXCONFKEYLEN);
+ cur_host->up_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "down_cmd", MAXCONFKEYLEN);
+ cur_host->down_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ /* TODO: Parse for up/down/auto in start_condition. */
+ /* TODO: Do a host up/down check if necessary. */
+ cur_host->host_up = true;
+
+ /* TODO: Do I want to make any checks for start_condition? */
+ if (cur_host->name == NULL || cur_host->ping_interval == -1 || cur_host->max_delay == -1) {
+ fprintf(stderr, "ERROR: Problems parsing section %s.\n", iniparser_getsecname(conf, i));