return ret;
}
+static void add_attrtibutes(sr_val_t **values_list, size_t *values_cnt, struct lyd_node *node)
+{
+ struct lyd_node *iter = NULL;
+
+ LY_TREE_FOR(node->child, iter) {
+ if (op_add_srval(values_list, values_cnt, iter)) {
+ printf("Could not transform libyang into sysrepo values...\n");
+ return;
+ }
+ if (iter->schema->nodetype == LYS_CONTAINER || iter->schema->nodetype == LYS_LIST)
+ {
+ add_attrtibutes(values_list, values_cnt, iter);
+ }
+ }
+}
+
static int send_dummy_notif(sr_session_ctx_t *sess, const char *module_name, const char *notif_object)
{
}
}
- data = lyd_parse_mem(ctx, notif_object, LYD_JSON, LYD_OPT_NOTIF);
+ printf("Successfully loaded schemas, trying now to parse the JSON...\n");
+
+ data = lyd_parse_mem(ctx, notif_object, LYD_JSON, LYD_OPT_NOTIF, NULL);
if (data == NULL)
{
printf("Could not create JSON object, not valid!\n");
return SR_ERR_VALIDATION_FAILED;
}
- LY_TREE_FOR(data->child, iter) {
- if (op_add_srval(&vnotif, &num_values, iter)) {
- printf("Could not transform libyang into sysrepo values...\n");
- return SR_ERR_OPERATION_FAILED;
- }
- }
+ printf("Successfully parsed the JSON notification object...\n");
+
+ add_attrtibutes(&vnotif, &num_values, data);
if (num_values == 0)
{
return SR_ERR_OPERATION_FAILED;
}
+ lyd_free(data);
+ ly_ctx_destroy(ctx, NULL);
+
+ sr_free_values(vnotif, num_values);
+
+ printf("Successfully sent notification from module=%s with %d number of atttributes\n", module_name, num_values);
+
return rc;
}
if (rc != SR_ERR_OK)
{
printf("Could not get Notification Counters for device with uuid=\"%s\"", current_device->device_id);
- }
+ }
+
+ char device_name[200];
+ sprintf(device_name, "%s-%d", getenv("CONTAINER_NAME"), current_device->device_number);
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, current_device->device_id, "device-ip");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, device_name, "device-ip");
v[current_num_of_values - 1].type = SR_STRING_T;
v[current_num_of_values - 1].data.string_val = getenv("NTS_IP");
{
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, current_device->device_id, "device-port");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, device_name, "device-port");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = current_device->netconf_port + i;
}
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, current_device->device_id, "is-mounted");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, device_name, "is-mounted");
v[current_num_of_values - 1].type = SR_BOOL_T;
v[current_num_of_values - 1].data.bool_val = current_device->is_mounted;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, current_device->device_id, "operational-state");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/%s", xpath, device_name, "operational-state");
sr_val_build_str_data(&v[current_num_of_values - 1], SR_ENUM_T, "%s", operational_state);
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, current_device->device_id, "normal");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, device_name, "normal");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = vesCount.normal;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, current_device->device_id, "warning");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, device_name, "warning");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = vesCount.warning;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, current_device->device_id, "minor");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, device_name, "minor");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = vesCount.minor;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, current_device->device_id, "major");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, device_name, "major");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = vesCount.major;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, current_device->device_id, "critical");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/ves-notifications/%s", xpath, device_name, "critical");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = vesCount.critical;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, current_device->device_id, "normal");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, device_name, "normal");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = netconfCount.normal;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, current_device->device_id, "warning");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, device_name, "warning");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = netconfCount.warning;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, current_device->device_id, "minor");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, device_name, "minor");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = netconfCount.minor;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, current_device->device_id, "major");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, device_name, "major");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = netconfCount.major;
CREATE_NEW_VALUE(rc, v, current_num_of_values);
- sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, current_device->device_id, "critical");
+ sr_val_build_xpath(&v[current_num_of_values - 1], "%s[uuid='%s']/notification-count/netconf-notifications/%s", xpath, device_name, "critical");
v[current_num_of_values - 1].type = SR_UINT32_T;
v[current_num_of_values - 1].data.uint32_val = netconfCount.critical;
bool is_mounted = true;
int port = 0;
- char device_name[100];
+ char device_name[200];
sprintf(device_name, "%s-%d", getenv("CONTAINER_NAME"), current_device->device_number);
//This is where we hardcoded: 7 devices will have SSH connections and 3 devices will have TLS connections
curl_easy_reset(curl);
set_curl_common_info();
- char url[100];
+ char url[500];
sprintf(url, "http:/v%s/exec/%s/start", getenv("DOCKER_ENGINE_VERSION"), exec_id);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_reset(curl);
set_curl_common_info();
- char url[100];
+ char url[500];
sprintf(url, "http:/v%s/exec/%s/json", getenv("DOCKER_ENGINE_VERSION"), exec_id);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_reset(curl);
set_curl_common_info();
- char url[100];
+ char url[300];
sprintf(url, "http:/v%s/containers/%s/exec", getenv("DOCKER_ENGINE_VERSION"), device_id);
curl_easy_setopt(curl, CURLOPT_URL, url);
cJSON *cmd_string_2 = cJSON_CreateString("-c");
cJSON_AddItemToArray(cmd_array, cmd_string_2);
- char string_command[500];
+ //some notifications require a really long notification object
+ char string_command[1000000];
sprintf(string_command, "/usr/local/bin/generic-notifications %s '%s'", module_name, notification_string);
cJSON *cmd_string_3 = cJSON_CreateString(string_command);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&curl_response_mem);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 300L);
+
res = curl_easy_perform(curl);
if (res != CURLE_OK)