AppDynamics IoT C++ SDK
AppDynamics IoT C++ library contains code that facilitates capturing availability, usage, network performance and errors of an IoT Application.
config.cpp File Reference
#include "config.hpp"
#include "beacon.hpp"
#include "log.hpp"

Functions

appd_iot_error_code_t appd_iot_init_sdk (appd_iot_sdk_config_t sdkcfg, appd_iot_device_config_t devcfg)
 This method Initializes the SDK.
This method should be called atleast once, early in your application's start up sequence. More...
 
appd_iot_error_code_t appd_iot_register_network_interface (appd_iot_http_cb_t http_cb)
 This method registers network interface
This method should be called atleast once, early in your application's start up sequence. More...
 
appd_iot_http_req_send_cb_t appd_iot_get_http_req_send_cb (void)
 Get http request send callback function pointer. More...
 
appd_iot_http_resp_done_cb_t appd_iot_get_http_resp_done_cb (void)
 Get http response done callback function pointer. More...
 
appd_iot_log_level_t appd_iot_get_log_level (void)
 Get Log Level configured as part of SDK Initialization. More...
 
appd_iot_log_write_cb_t appd_iot_get_log_write_cb (void)
 Get Log Write Callback Function Pointer. More...
 
const char * appd_iot_get_eum_collector_url (void)
 Get Configured EUM Collector URL. More...
 
const appd_iot_data_tappd_iot_get_server_correlation_headers (void)
 Get Server Correlation headers in {key,value} format that need to be added to every outgoing http request to enable capturing Business Transaction (BT). More...
 
void appd_iot_set_sdk_state (appd_iot_sdk_state_t new_state)
 Set SDK State. More...
 
appd_iot_sdk_state_t appd_iot_get_sdk_state (void)
 Get Current SDK State. More...
 
void appd_iot_disable_sdk (int http_resp_code)
 Set SDK state to disabled state based on the HTTP Response Code. More...
 
appd_iot_error_code_t appd_iot_check_app_status (void)
 Use this API to check with AppDynamics Collector on the status of IoT Application on AppDynamics Controller, whether instrumentation is enabled or not. If the Collector returns Success, SDK gets ENABLED in case it has been DISABLED previously by Collector due to license expiry, kill switch or data limit exceeded.
It is required that SDK initialization is already done using the API appd_iot_init_sdk() before calling this function. More...
 

Variables

static appd_sdk_config_t global_sdk_config
 
static std::string appd_iot_eum_collector_url_appkey_prefix = "eumcollector/iot/v1/application/"
 
static std::string appd_iot_eum_collector_url_beacons_suffix = "/beacons"
 
static std::string appd_iot_eum_collector_url_enabled_suffix = "/enabled"
 
static std::string default_eum_collector_url = "https://iot-col.eum-appdynamics.com"
 
static const appd_iot_data_t global_correlation_headers [APPD_IOT_NUM_SERVER_CORRELATION_HEADERS]
 
static appd_iot_sdk_state_t global_sdk_state = APPD_IOT_SDK_UNINITIALIZED
 

Function Documentation

◆ appd_iot_init_sdk()

appd_iot_error_code_t appd_iot_init_sdk ( appd_iot_sdk_config_t  sdkcfg,
appd_iot_device_config_t  devcfg 
)

This method Initializes the SDK.
This method should be called atleast once, early in your application's start up sequence.

This method Initializes the SDK.
This method must be called before all other SDK Apis are called.
It is recommened to call this method early in your application's start up sequence.

Parameters
sdkcfgcontains sdk configuration such as collector url, appkey etc
devcfgcontains device information such as device type/name and hw/fw/sw versions
Returns
appd_iot_error_code_t Error code indicating if the function call is a success or fail. Error code returned provides more details on the type of error occurred.
47 {
48  std::string eum_collector_url;
49  appd_iot_error_code_t retcode;
50 
51  /* Process Log Config */
52  if (sdkcfg.log_level >= APPD_IOT_LOG_OFF && sdkcfg.log_level <= APPD_IOT_LOG_ALL)
53  {
55  }
56  else
57  {
59  }
60 
62  {
64  }
65 
66  /* Process Device Config */
67  retcode = appd_iot_init_device_config(devcfg);
68 
69  if (retcode != APPD_IOT_SUCCESS)
70  {
71  appd_iot_log(APPD_IOT_LOG_ERROR, "Device Config Initialization Failed");
72  return retcode;
73  }
74 
75  /* Process SDK Config */
76  if (sdkcfg.appkey == NULL)
77  {
78  appd_iot_log(APPD_IOT_LOG_ERROR, "AppKey cannot be NULL");
80  }
81 
83 
84  if (sdkcfg.eum_collector_url == NULL)
85  {
86  eum_collector_url = default_eum_collector_url;
87  appd_iot_log(APPD_IOT_LOG_ERROR, "EUM collector URL is NULL, setting to default:%s",
89  }
90  else
91  {
92  eum_collector_url = sdkcfg.eum_collector_url;
93  }
94 
95  if (eum_collector_url.at(eum_collector_url.length() - 1) != '/')
96  {
97  eum_collector_url = eum_collector_url + "/";
98  }
99 
101  eum_collector_url + appd_iot_eum_collector_url_appkey_prefix +
103 
105  eum_collector_url + appd_iot_eum_collector_url_appkey_prefix +
107 
108  appd_iot_log(APPD_IOT_LOG_INFO, "EUM Collector URL %s", global_sdk_config.eum_collector_url.c_str());
109 
110 
111  if (sdkcfg.sdk_state_change_cb != NULL)
112  {
114  }
115 
117 
118  return APPD_IOT_SUCCESS;
119 }
void appd_iot_log(appd_iot_log_level_t log_level, const char *format,...)
Reads log message, appends log header and triggers log write callback function.
Definition: log.cpp:89
Definition: appd_iot_def.h:97
static std::string appd_iot_eum_collector_url_enabled_suffix
Definition: config.cpp:25
void appd_iot_set_sdk_state(appd_iot_sdk_state_t new_state)
Set SDK State.
Definition: config.cpp:213
std::string eum_collector_url
Definition: config.hpp:26
static std::string appd_iot_eum_collector_url_appkey_prefix
Definition: config.cpp:23
const char * eum_collector_url
Definition: appd_iot_def.h:148
appd_iot_log_write_cb_t log_write_cb
Definition: config.hpp:28
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21
Definition: appd_iot_def.h:64
appd_iot_error_code_t
Error Code Enums for SDK log.
Definition: appd_iot_def.h:27
Definition: appd_iot_def.h:109
Definition: appd_iot_def.h:103
appd_iot_log_level_t log_level
Definition: appd_iot_def.h:150
static std::string appd_iot_eum_collector_url_beacons_suffix
Definition: config.cpp:24
appd_iot_log_level_t log_level
Definition: config.hpp:30
std::string eum_appkey_enabled_url
Definition: config.hpp:27
appd_iot_sdk_state_change_cb_t sdk_state_change_cb
Definition: config.hpp:29
Definition: appd_iot_def.h:32
static std::string default_eum_collector_url
Definition: config.cpp:26
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
const char * appkey
Definition: appd_iot_def.h:146
appd_iot_error_code_t appd_iot_init_device_config(appd_iot_device_config_t devcfg)
Initializes Device Configuration It is madatory to set Device ID and Device Type.
Definition: beacon.cpp:37
appd_iot_log_write_cb_t log_write_cb
Definition: appd_iot_def.h:153
appd_iot_sdk_state_change_cb_t sdk_state_change_cb
Definition: appd_iot_def.h:155
std::string appkey
Definition: config.hpp:25

◆ appd_iot_register_network_interface()

appd_iot_error_code_t appd_iot_register_network_interface ( appd_iot_http_cb_t  http_cb)

This method registers network interface
This method should be called atleast once, early in your application's start up sequence.

This method registers network interface
This method must be called before calling appd_iot_send_all_events().

Parameters
http_cbcontains function pointers for http request send and http response done callbacks
. http request send callback will be called when appd_iot_send_all_events is triggered.
http response done callback will be called after send http request callback returns and response is processed.
Returns
appd_iot_error_code_t Error code indicating if the function call is a success or fail. Error code returned provides more details on the type of error occurred.
133 {
134  if (http_cb.http_req_send_cb == NULL)
135  {
136  appd_iot_log(APPD_IOT_LOG_ERROR, "http_req_send_cb is NULL");
138  }
139 
140  if (http_cb.http_resp_done_cb == NULL)
141  {
142  appd_iot_log(APPD_IOT_LOG_ERROR, "http_resp_done_cb is NULL");
144  }
145 
148 
149  return APPD_IOT_SUCCESS;
150 }
void appd_iot_log(appd_iot_log_level_t log_level, const char *format,...)
Reads log message, appends log header and triggers log write callback function.
Definition: log.cpp:89
appd_iot_http_req_send_cb_t http_req_send_cb
Definition: appd_iot_def.h:416
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21
appd_iot_http_cb_t http_cb
Definition: config.hpp:32
Definition: appd_iot_def.h:32
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
appd_iot_http_resp_done_cb_t http_resp_done_cb
Definition: appd_iot_def.h:417

◆ appd_iot_get_http_req_send_cb()

appd_iot_http_req_send_cb_t appd_iot_get_http_req_send_cb ( void  )

Get http request send callback function pointer.

Returns
callback function pointer
157 {
159 }
appd_iot_http_req_send_cb_t http_req_send_cb
Definition: appd_iot_def.h:416
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21
appd_iot_http_cb_t http_cb
Definition: config.hpp:32

◆ appd_iot_get_http_resp_done_cb()

appd_iot_http_resp_done_cb_t appd_iot_get_http_resp_done_cb ( void  )

Get http response done callback function pointer.

Returns
callback function pointer
166 {
168 }
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21
appd_iot_http_cb_t http_cb
Definition: config.hpp:32
appd_iot_http_resp_done_cb_t http_resp_done_cb
Definition: appd_iot_def.h:417

◆ appd_iot_get_log_level()

appd_iot_log_level_t appd_iot_get_log_level ( void  )

Get Log Level configured as part of SDK Initialization.

Get configured Log Level as part of SDK Initialization.

Returns
appd_iot_log_level_t contains log level enum
175 {
177 }
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21
appd_iot_log_level_t log_level
Definition: config.hpp:30

◆ appd_iot_get_log_write_cb()

appd_iot_log_write_cb_t appd_iot_get_log_write_cb ( void  )

Get Log Write Callback Function Pointer.

Returns
appd_iot_log_write_cb_t contains log_write_cb fun ptr
185 {
187 }
appd_iot_log_write_cb_t log_write_cb
Definition: config.hpp:28
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21

◆ appd_iot_get_eum_collector_url()

const char* appd_iot_get_eum_collector_url ( void  )

Get Configured EUM Collector URL.

Returns
URL in string format
194 {
195  return global_sdk_config.eum_collector_url.c_str();
196 }
std::string eum_collector_url
Definition: config.hpp:26
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21

◆ appd_iot_get_server_correlation_headers()

const appd_iot_data_t* appd_iot_get_server_correlation_headers ( void  )

Get Server Correlation headers in {key,value} format that need to be added to every outgoing http request to enable capturing Business Transaction (BT).

Returns
Server Correlation Headers. Total number of headers present is given by macro APPD_IOT_NUM_SERVER_CORRELATION_HEADERS. Do not modify or free returned headers.
205 {
207 }
static const appd_iot_data_t global_correlation_headers[APPD_IOT_NUM_SERVER_CORRELATION_HEADERS]
Definition: config.cpp:29

◆ appd_iot_set_sdk_state()

void appd_iot_set_sdk_state ( appd_iot_sdk_state_t  new_state)

Set SDK State.

Parameters
new_stateindicates the new sdk state that need to be set
214 {
215  if (global_sdk_state == new_state)
216  {
217  appd_iot_log(APPD_IOT_LOG_WARN, "SDK state update with same state as current:%s",
219  return;
220  }
221 
222  global_sdk_state = new_state;
223 
225 
227  {
229  }
230 }
void appd_iot_log(appd_iot_log_level_t log_level, const char *format,...)
Reads log message, appends log header and triggers log write callback function.
Definition: log.cpp:89
Definition: appd_iot_def.h:101
static appd_iot_sdk_state_t global_sdk_state
Definition: config.cpp:35
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21
Definition: appd_iot_def.h:103
appd_iot_sdk_state_change_cb_t sdk_state_change_cb
Definition: config.hpp:29
const char * appd_iot_sdk_state_to_str(appd_iot_sdk_state_t sdk_state) __APPD_IOT_API
Convert sdk state to string.
Definition: log.cpp:203

◆ appd_iot_get_sdk_state()

appd_iot_sdk_state_t appd_iot_get_sdk_state ( void  )

Get Current SDK State.

Returns
appd_iot_sdk_state_t with current sdk state
237 {
238  return global_sdk_state;
239 }
static appd_iot_sdk_state_t global_sdk_state
Definition: config.cpp:35

◆ appd_iot_disable_sdk()

void appd_iot_disable_sdk ( int  http_resp_code)

Set SDK state to disabled state based on the HTTP Response Code.

Parameters
http_resp_codeindicates the response code from the Collector
246 {
247  if (http_resp_code == 403)
248  {
249  appd_iot_log(APPD_IOT_LOG_ERROR, "Resp Code:%d Application on Controller is Disabled",
250  http_resp_code);
252  }
253  else if (http_resp_code == 429)
254  {
255  appd_iot_log(APPD_IOT_LOG_ERROR, "Resp Code:%d Application Data Limit Exceeded", http_resp_code);
257  }
258  else if (http_resp_code == 402)
259  {
260  appd_iot_log(APPD_IOT_LOG_ERROR, "Resp Code:%d Application License Expired", http_resp_code);
262  }
263  else
264  {
265  appd_iot_log(APPD_IOT_LOG_INFO, "Resp Code:%d not supported to disable SDK", http_resp_code);
266  }
267 }
void appd_iot_log(appd_iot_log_level_t log_level, const char *format,...)
Reads log message, appends log header and triggers log write callback function.
Definition: log.cpp:89
void appd_iot_set_sdk_state(appd_iot_sdk_state_t new_state)
Set SDK State.
Definition: config.cpp:213
Definition: appd_iot_def.h:103
Definition: appd_iot_def.h:68
Definition: appd_iot_def.h:66
Definition: appd_iot_def.h:99
Definition: appd_iot_def.h:70

◆ appd_iot_check_app_status()

appd_iot_error_code_t appd_iot_check_app_status ( void  )

Use this API to check with AppDynamics Collector on the status of IoT Application on AppDynamics Controller, whether instrumentation is enabled or not. If the Collector returns Success, SDK gets ENABLED in case it has been DISABLED previously by Collector due to license expiry, kill switch or data limit exceeded.
It is required that SDK initialization is already done using the API appd_iot_init_sdk() before calling this function.

Returns
appd_iot_error_code_t will indicate success if app is enabled
281 {
282  appd_iot_sdk_state_t curr_sdk_state = appd_iot_get_sdk_state();
283 
284  if (curr_sdk_state == APPD_IOT_SDK_UNINITIALIZED)
285  {
286  appd_iot_log(APPD_IOT_LOG_ERROR, "SDK is Uninitalized. Call Init SDK before calling this API");
288  }
289 
290  /* Init all the data structures - REQ and RESP */
291  appd_iot_http_req_t http_req;
292  appd_iot_http_resp_t* http_resp = NULL;
296 
297  if (http_req_send_cb == NULL)
298  {
299  appd_iot_log(APPD_IOT_LOG_ERROR, "Network Interface Not Available");
301  }
302 
303  appd_iot_init_to_zero(&http_req, sizeof(http_req));
304 
305  http_req.type = "GET";
306  http_req.url = global_sdk_config.eum_appkey_enabled_url.c_str();
307 
308  http_resp = http_req_send_cb(&http_req);
309 
310  /* check if any error present in http response */
311  if (http_resp != NULL)
312  {
313  retcode = http_resp->error;
314  }
315  else
316  {
317  appd_iot_log(APPD_IOT_LOG_ERROR, "NULL HTTP Response Returned");
318  retcode = APPD_IOT_ERR_NULL_PTR;
319  }
320 
321  /* Return if there is an error executing http req */
322  if (retcode != APPD_IOT_SUCCESS)
323  {
324  appd_iot_log(APPD_IOT_LOG_ERROR, "Error Executing HTTP Request, ErrorCode:%d", retcode);
325 
326  if (http_resp_done_cb != NULL)
327  {
328  http_resp_done_cb(http_resp);
329  }
330 
331  return retcode;
332  }
333 
334  if (http_resp->resp_code >= 200 && http_resp->resp_code < 300)
335  {
337  appd_iot_log(APPD_IOT_LOG_INFO, "RespCode:%d Application is Enabled on Controller", http_resp->resp_code);
338  retcode = APPD_IOT_SUCCESS;
339  }
340  else if ((http_resp->resp_code == 402) ||
341  (http_resp->resp_code == 403) ||
342  (http_resp->resp_code == 429))
343  {
344  appd_iot_disable_sdk(http_resp->resp_code);
345  retcode = APPD_IOT_ERR_NETWORK_REJECT;
346  }
347  else
348  {
349  appd_iot_log(APPD_IOT_LOG_ERROR, "Resp Code:%d Network Request to Check App Status Failed",
350  http_resp->resp_code);
351  retcode = APPD_IOT_ERR_NETWORK_ERROR;
352  }
353 
354  if (http_resp_done_cb != NULL)
355  {
356  http_resp_done_cb(http_resp);
357  }
358 
359  return retcode;
360 }
Definition: appd_iot_def.h:50
appd_iot_sdk_state_t
Enums for SDK State.
Definition: appd_iot_def.h:59
Definition: appd_iot_def.h:44
Definition: appd_iot_def.h:42
Definition: appd_iot_def.h:62
void appd_iot_log(appd_iot_log_level_t log_level, const char *format,...)
Reads log message, appends log header and triggers log write callback function.
Definition: log.cpp:89
Definition: appd_iot_def.h:36
void appd_iot_set_sdk_state(appd_iot_sdk_state_t new_state)
Set SDK State.
Definition: config.cpp:213
Definition: appd_iot_def.h:38
appd_iot_sdk_state_t appd_iot_get_sdk_state(void)
Get Current SDK State.
Definition: config.cpp:236
appd_iot_http_req_send_cb_t appd_iot_get_http_req_send_cb(void)
Get http request send callback function pointer.
Definition: config.cpp:156
static appd_sdk_config_t global_sdk_config
Definition: config.cpp:21
Definition: appd_iot_def.h:64
appd_iot_error_code_t
Error Code Enums for SDK log.
Definition: appd_iot_def.h:27
Definition: appd_iot_def.h:103
const char * url
Definition: appd_iot_def.h:349
static void appd_iot_init_to_zero(void *ptr, size_t size)
Initializes memory block pointed by ptr to zero.
Definition: appd_iot_def.h:478
AppDynamics HTTP Response Structure Mandatory: One of the resp_code or error fields should be popul...
Definition: appd_iot_def.h:365
void(* appd_iot_http_resp_done_cb_t)(appd_iot_http_resp_t *http_resp)
Http Response Done Callback is triggered after http send callback returns and http response is proc...
Definition: appd_iot_def.h:407
appd_iot_http_resp_t *(* appd_iot_http_req_send_cb_t)(const appd_iot_http_req_t *http_req)
Http Request Send Callback implements the functionality to send HTTP Request The callback implement...
Definition: appd_iot_def.h:395
std::string eum_appkey_enabled_url
Definition: config.hpp:27
AppDynamics HTTP Request Structure Mandatory: All Fields Data is provided in raw format...
Definition: appd_iot_def.h:346
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
int resp_code
Definition: appd_iot_def.h:368
void appd_iot_disable_sdk(int http_resp_code)
Set SDK state to disabled state based on the HTTP Response Code.
Definition: config.cpp:245
const char * type
Definition: appd_iot_def.h:355
appd_iot_error_code_t error
Definition: appd_iot_def.h:382
appd_iot_http_resp_done_cb_t appd_iot_get_http_resp_done_cb(void)
Get http response done callback function pointer.
Definition: config.cpp:165

Variable Documentation

◆ global_sdk_config

appd_sdk_config_t global_sdk_config
static

◆ appd_iot_eum_collector_url_appkey_prefix

std::string appd_iot_eum_collector_url_appkey_prefix = "eumcollector/iot/v1/application/"
static

◆ appd_iot_eum_collector_url_beacons_suffix

std::string appd_iot_eum_collector_url_beacons_suffix = "/beacons"
static

◆ appd_iot_eum_collector_url_enabled_suffix

std::string appd_iot_eum_collector_url_enabled_suffix = "/enabled"
static

◆ default_eum_collector_url

std::string default_eum_collector_url = "https://iot-col.eum-appdynamics.com"
static

◆ global_correlation_headers

const appd_iot_data_t global_correlation_headers[APPD_IOT_NUM_SERVER_CORRELATION_HEADERS]
static
Initial value:
=
{
{"ADRUM", {"isAjax:true"}, APPD_IOT_STRING},
{"ADRUM_1", {"isMobile:true"}, APPD_IOT_STRING}
}
Definition: appd_iot_def.h:192

◆ global_sdk_state