add use_prtg config option

This commit is contained in:
Martijn Scheepers
2019-08-16 08:58:31 +02:00
parent a57be607ce
commit 6c5dcf690b
4 changed files with 24 additions and 9 deletions

View File

@@ -37,6 +37,7 @@ int config_read(struct config_t *config, char *filepath){
//CFG_SIMPLE_INT("debug", &debug),
//CFG_SIMPLE_FLOAT("delay", &delay),
CFG_SIMPLE_BOOL("use_prtg", &config->useprtg),
CFG_SIMPLE_STR("wsenhost", &config->wsenhost),
CFG_SIMPLE_STR("sensor", &config->sensor),
CFG_SIMPLE_INT("interval", &config->interval),
@@ -149,6 +150,7 @@ int config_check(struct config_t *config){
void config_print(struct config_t *config, char *filepath){
printf("------------- configfile ----------\r\n");
printf("filepath: %s\r\n", filepath);
printf("use prtg: %s\n", config->useprtg ? "true" : "false");
printf("wsenhost: %s\r\n", config->wsenhost);
printf("sensor: %s\r\n", config->sensor);
printf("interval: %ld min\r\n", config->interval);

View File

@@ -5,11 +5,11 @@
struct input_t {
unsigned int input;
cfg_bool_t enable;
//char name[50];
char *name;
};
struct config_t {
cfg_bool_t useprtg;
char *wsenhost;
char *sensor;
long int interval;

View File

@@ -1,3 +1,4 @@
use_prtg=false
wsenhost="https://prtg.sdnsupport.nl:5051"
sensor="WSEN0000"
interval=10

28
web.c
View File

@@ -105,11 +105,17 @@ void web_request(char *url, const char *json){
void web_prtg_post(struct config_t *config){
char *url;
if(asprintf(&url, "%s/%s", config->wsenhost, config->sensor) <= 0){
writesyslog(LOG_ERR, "web_prtg_post: url asprintf failed");
return;
if(config->useprtg == cfg_true){
if(asprintf(&url, "%s/%s", config->wsenhost, config->sensor) <= 0){
writesyslog(LOG_ERR, "web_prtg_post: url asprintf failed");
return;
}
}else{
if(asprintf(&url, "%s", config->wsenhost) <= 0){
writesyslog(LOG_ERR, "web_prtg_post: url asprintf failed");
return;
}
}
#ifdef TEST
printf("URL: %s\n", url);
@@ -118,11 +124,17 @@ void web_prtg_post(struct config_t *config){
cJSON *root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "sensor", config->sensor);
cJSON *prtg = cJSON_CreateObject();
cJSON_AddItemToObject(root, "prtg", prtg);
cJSON *channels = cJSON_CreateArray();
cJSON_AddItemToObject(prtg, "result", channels);
if(config->useprtg == cfg_true){
cJSON *prtg = cJSON_CreateObject();
cJSON_AddItemToObject(root, "prtg", prtg);
//cJSON *channels = cJSON_CreateArray();
cJSON_AddItemToObject(prtg, "result", channels);
}else{
//cJSON *channels = cJSON_CreateArray();
cJSON_AddItemToObject(root, "result", channels);
}
unsigned int i;
for (i = 1; i <= 8; ++i)