- 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", MAX_CONF_KEY_LEN);
+ cur_host->name = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "interval", MAX_CONF_KEY_LEN);
+ cur_host->ping_interval = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "max_delay", MAX_CONF_KEY_LEN);
+ cur_host->max_delay = iniparser_getint(conf, key_buf, -1);
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "up_cmd", MAX_CONF_KEY_LEN);
+ cur_host->up_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "down_cmd", MAX_CONF_KEY_LEN);
+ cur_host->down_cmd = strdup(iniparser_getstring(conf, key_buf, NULL));
+
+ key_buf[section_len] = '\0';
+ strncat(key_buf, "start_condition", MAX_CONF_KEY_LEN);
+ const char * value = iniparser_getstring(conf, key_buf, NULL);
+ if (value) cur_host->host_up = *value == 'u' ? true : false;
+
+ 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));