static void s_get_custom_metrics_data()

in source/device_defender.c [660:713]


static void s_get_custom_metrics_data(
    const struct aws_iotdevice_defender_task *defender_task,
    struct defender_custom_metric_data *custom_metric_data,
    const size_t custom_metrics_len) {
    if (custom_metrics_len != 0) {
        for (size_t metric_index = 0; metric_index < custom_metrics_len; ++metric_index) {
            aws_array_list_get_at(
                &defender_task->config.custom_metrics, (void *)&custom_metric_data[metric_index].metric, metric_index);

            AWS_LOGF_DEBUG(
                AWS_LS_IOTDEVICE_DEFENDER_TASK,
                "id=%p Retrieving value for custom metric %s",
                (void *)defender_task,
                aws_string_c_str(custom_metric_data[metric_index].metric->metric_name));

            switch (custom_metric_data[metric_index].metric->type) {
                case DD_METRIC_NUMBER:
                    custom_metric_data[metric_index].callback_result =
                        custom_metric_data[metric_index].metric->supplier_fn.get_number_fn(
                            &custom_metric_data[metric_index].data.number,
                            custom_metric_data[metric_index].metric->metric_cb_userdata);
                    break;
                case DD_METRIC_NUMBER_LIST:
                    custom_metric_data[metric_index].callback_result =
                        custom_metric_data[metric_index].metric->supplier_fn.get_number_list_fn(
                            &custom_metric_data[metric_index].data.list,
                            custom_metric_data[metric_index].metric->metric_cb_userdata);
                    break;
                case DD_METRIC_STRING_LIST:
                    custom_metric_data[metric_index].callback_result =
                        custom_metric_data[metric_index].metric->supplier_fn.get_string_list_fn(
                            &custom_metric_data[metric_index].data.list,
                            custom_metric_data[metric_index].metric->metric_cb_userdata);
                    break;
                case DD_METRIC_IP_LIST:
                    custom_metric_data[metric_index].callback_result =
                        custom_metric_data[metric_index].metric->supplier_fn.get_ip_list_fn(
                            &custom_metric_data[metric_index].data.list,
                            custom_metric_data[metric_index].metric->metric_cb_userdata);
                    break;
                case DD_METRIC_UNKNOWN:
                default:
                    AWS_LOGF_ERROR(
                        AWS_LS_IOTDEVICE_DEFENDER_TASK,
                        "id=%p: Cannot retreive metric for unknown metric type: %d, name: %s",
                        (void *)defender_task,
                        custom_metric_data[metric_index].metric->type,
                        aws_string_c_str(custom_metric_data[metric_index].metric->metric_name));
                    continue;
                    break;
            }
        }
    }
}