AppDynamics IoT C++ SDK
AppDynamics IoT C++ library contains code that facilitates capturing availability, usage, network performance and errors of an IoT Application.
appd_iot_interface.h File Reference
#include "appd_iot_def.h"

Go to the source code of this file.

Macros

#define __APPD_IOT_API
 

Functions

appd_iot_error_code_t appd_iot_init_sdk (appd_iot_sdk_config_t sdkcfg, appd_iot_device_config_t devcfg) __APPD_IOT_API
 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. More...
 
appd_iot_error_code_t appd_iot_register_network_interface (appd_iot_http_cb_t http_cb) __APPD_IOT_API
 This method registers network interface
This method must be called before calling appd_iot_send_all_events(). More...
 
appd_iot_error_code_t appd_iot_add_custom_event (appd_iot_custom_event_t custom_event) __APPD_IOT_API
 This method adds custom event data
Each call to add event will create a new event. More...
 
appd_iot_error_code_t appd_iot_add_network_request_event (appd_iot_network_request_event_t network_request_event) __APPD_IOT_API
 This method adds event data
Each call to add event will create a new event. More...
 
appd_iot_error_code_t appd_iot_add_error_event (appd_iot_error_event_t error_event) __APPD_IOT_API
 This method adds event data
Each call to add event will create a new event. More...
 
appd_iot_error_code_t appd_iot_send_all_events (void) __APPD_IOT_API
 This method sends all event data.
If events are sent successfuly to collector then they will be flushed out of memory.
If there is a network reject with response codes 402, 403 or 429 then events are flushed out of memory and SDK state set to DISABLED. If there is any other network error, events remain in memory for retry. Repeated calls to this API in SDK ENABLED State will retry sending the data in memory to the collector.
Use the API appd_iot_clear_all_events() to clear out events in memory if retries are unsuccessful. More...
 
appd_iot_error_code_t appd_iot_clear_all_events (void) __APPD_IOT_API
 This method removes all event data stored in memory
This call is not needed if appd_iot_send_all_events return SUCCESS. More...
 
appd_iot_error_code_t appd_iot_check_app_status (void) __APPD_IOT_API
 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...
 

Macro Definition Documentation

◆ __APPD_IOT_API

#define __APPD_IOT_API

Attribute added to all the API's that need to be made public outside of appdynamics iot shared dynamic library.

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 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 configuration 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.

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 must be called before calling appd_iot_send_all_events().

Parameters
http_cbcontains function pointers for http req send and http resp 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 req callback returns and resp 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.

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_add_custom_event()

appd_iot_error_code_t appd_iot_add_custom_event ( appd_iot_custom_event_t  custom_event)

This method adds custom event data
Each call to add event will create a new event.

Parameters
custom_eventcontains details of the event
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.

This method adds custom event data
Each call to add event will create a new event.

Parameters
custom_eventcontains event data
Returns
appd_iot_error_code_t indicating function execution status
30 {
31  appd_iot_error_code_t retcode;
32  appd_iot_sdk_state_t sdk_state;
33  custom_event_t event;
34 
35  if ((sdk_state = appd_iot_get_sdk_state()) != APPD_IOT_SDK_ENABLED)
36  {
37  appd_iot_log(APPD_IOT_LOG_ERROR, "Add Custom Event Failed. SDK Not in Enabled State:%s",
38  appd_iot_sdk_state_to_str(sdk_state));
39 
41  }
42 
43  if (custom_event.type != NULL)
44  {
45  event.type = appd_iot_remove_character(custom_event.type, '|');
46  }
47  else
48  {
49  appd_iot_log(APPD_IOT_LOG_WARN, "Custom Event Type cannot be NULL");
50  }
51 
52  if (custom_event.summary != NULL)
53  {
54  event.summary = custom_event.summary;
55  }
56  else
57  {
58  appd_iot_log(APPD_IOT_LOG_WARN, "Custom Event Summary is NULL");
59  }
60 
61  event.timestamp_ms = custom_event.timestamp_ms;
62  event.duration_ms = custom_event.duration_ms;
63  retcode = APPD_IOT_SUCCESS;
64 
65  if (custom_event.data_count > 0)
66  {
67  retcode = appd_iot_copy_event_data(&event.data, custom_event.data,
68  custom_event.data_count);
69 
70  if (retcode != APPD_IOT_SUCCESS)
71  {
72  appd_iot_log(APPD_IOT_LOG_WARN, "Failed to parse custom event data, error:%s",
74 
76  }
77  }
78 
79  appd_iot_log(APPD_IOT_LOG_INFO, "Adding Custom Event with Type:%s", event.type.c_str());
80 
81  retcode = appd_iot_add_custom_event_to_beacon(event);
82 
83  return retcode;
84 }
Definition: appd_iot_def.h:50
appd_iot_sdk_state_t
Enums for SDK State.
Definition: appd_iot_def.h:59
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
const char * summary
Definition: appd_iot_def.h:228
int64_t timestamp_ms
Definition: appd_iot_def.h:230
Definition: appd_iot_def.h:101
int data_count
Definition: appd_iot_def.h:234
appd_iot_error_code_t appd_iot_add_custom_event_to_beacon(custom_event_t event)
Adds Custom Event to Beacon.
Definition: beacon.cpp:90
const char * type
Definition: appd_iot_def.h:226
appd_iot_error_code_t appd_iot_copy_event_data(data_t *destdata, appd_iot_data_t *srcdata, int srcdata_count)
Copies User Defined Event Data to SDK Defined Event Data.
Definition: custom_event.cpp:110
appd_iot_sdk_state_t appd_iot_get_sdk_state(void)
Get Current SDK State.
Definition: config.cpp:236
const char * appd_iot_error_code_to_str(appd_iot_error_code_t error_code) __APPD_IOT_API
Convert error code to string.
Definition: log.cpp:193
Definition: appd_iot_def.h:64
appd_iot_error_code_t
Error Code Enums for SDK log.
Definition: appd_iot_def.h:27
Definition: beacon.hpp:38
Definition: appd_iot_def.h:103
appd_iot_data_t * data
Definition: appd_iot_def.h:236
int duration_ms
Definition: appd_iot_def.h:232
data_t data
Definition: beacon.hpp:44
std::string appd_iot_remove_character(const char *input, char c)
Removes a given character from the input string.
Definition: utils.cpp:27
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
std::string type
Definition: beacon.hpp:40
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_error_code_t appd_iot_clear_event_data(data_t *data)
Clear event data.
Definition: custom_event.cpp:91

◆ appd_iot_add_network_request_event()

appd_iot_error_code_t appd_iot_add_network_request_event ( appd_iot_network_request_event_t  network_request_event)

This method adds event data
Each call to add event will create a new event.

Parameters
network_request_eventcontains details of the network request
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.

This method adds event data
Each call to add event will create a new event.

Parameters
network_request_eventcontains network event data
Returns
appd_iot_error_code_t indicating function execution status
98 {
99  appd_iot_error_code_t retcode;
100  appd_iot_sdk_state_t sdk_state;
102 
103  if ((sdk_state = appd_iot_get_sdk_state()) != APPD_IOT_SDK_ENABLED)
104  {
105  appd_iot_log(APPD_IOT_LOG_ERROR, "Add Network Event Failed. SDK Not in Enabled State:%s",
106  appd_iot_sdk_state_to_str(sdk_state));
107 
109  }
110 
111  if (network_request_event.url == NULL)
112  {
113  appd_iot_log(APPD_IOT_LOG_ERROR, "URL field cannot be NULL");
115  }
116 
117  if (network_request_event.error == NULL &&
118  !appd_iot_is_valid_http_resp_code(network_request_event.resp_code))
119  {
120  appd_iot_log(APPD_IOT_LOG_WARN, "Network Error or valid Response Code needs to be populated");
121  }
122 
123  if (strncmp(network_request_event.url,
125  strlen(network_request_event.url)) == 0)
126  {
127  appd_iot_log(APPD_IOT_LOG_WARN, "Skip Adding Network Event with Event URL same as APPD EUM Collector URL:%s",
128  network_request_event.url);
130  }
131 
132  retcode = APPD_IOT_SUCCESS;
133  event.url = network_request_event.url;
134 
135  if (network_request_event.error != NULL)
136  {
137  event.error = network_request_event.error;
138  }
139 
140  if (appd_iot_is_valid_http_resp_code(network_request_event.resp_code))
141  {
142  event.resp_code = network_request_event.resp_code;
143  }
144  else
145  {
146  event.resp_code = 0;
147  }
148 
149  event.req_content_length = network_request_event.req_content_length;
150  event.resp_content_length = network_request_event.resp_content_length;
151  event.timestamp_ms = network_request_event.timestamp_ms;
152  event.duration_ms = network_request_event.duration_ms;
153 
154  if (network_request_event.resp_headers_count > 0)
155  {
157  network_request_event.resp_headers,
158  network_request_event.resp_headers_count);
159 
160  if (retcode != APPD_IOT_SUCCESS)
161  {
162  appd_iot_log(APPD_IOT_LOG_ERROR, "Failed to parse network event response headers, error:%s",
163  appd_iot_error_code_to_str(retcode));
164 
166  }
167  }
168 
169  if (network_request_event.data_count > 0)
170  {
171  retcode = appd_iot_copy_event_data(&event.data, network_request_event.data,
172  network_request_event.data_count);
173 
174  if (retcode != APPD_IOT_SUCCESS)
175  {
176  appd_iot_log(APPD_IOT_LOG_WARN, "Failed to parse Network event data, error:%s",
177  appd_iot_error_code_to_str(retcode));
178 
180  }
181  }
182 
183  appd_iot_log(APPD_IOT_LOG_INFO, "Adding Network Event with URL:%s", event.url.c_str());
184 
186 
187  return retcode;
188 }
Definition: appd_iot_def.h:50
appd_iot_sdk_state_t
Enums for SDK State.
Definition: appd_iot_def.h:59
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
int64_t timestamp_ms
Definition: appd_iot_def.h:263
Definition: appd_iot_def.h:101
appd_iot_error_code_t appd_iot_copy_event_data(data_t *destdata, appd_iot_data_t *srcdata, int srcdata_count)
Copies User Defined Event Data to SDK Defined Event Data.
Definition: custom_event.cpp:110
appd_iot_error_code_t appd_iot_add_network_request_event_to_beacon(network_request_event_t event)
Adds Network Request Event to Beacon.
Definition: beacon.cpp:115
appd_iot_sdk_state_t appd_iot_get_sdk_state(void)
Get Current SDK State.
Definition: config.cpp:236
Definition: appd_iot_def.h:48
int resp_content_length
Definition: appd_iot_def.h:255
const char * appd_iot_error_code_to_str(appd_iot_error_code_t error_code) __APPD_IOT_API
Convert error code to string.
Definition: log.cpp:193
Definition: appd_iot_def.h:64
appd_iot_error_code_t
Error Code Enums for SDK log.
Definition: appd_iot_def.h:27
int data_count
Definition: appd_iot_def.h:265
int resp_code
Definition: appd_iot_def.h:257
appd_iot_error_code_t appd_iot_copy_response_headers_data(data_t *dest_respheader, appd_iot_data_t *src_respheader, int src_respheadercount)
Copies User Defined Response Header Data to SDK Defined Structure.
Definition: network_event.cpp:39
Definition: appd_iot_def.h:103
int req_content_length
Definition: appd_iot_def.h:253
const char * url
Definition: appd_iot_def.h:247
appd_iot_data_t * resp_headers
Definition: appd_iot_def.h:261
appd_iot_data_t * data
Definition: appd_iot_def.h:267
data_t resp_headers
Definition: beacon.hpp:56
Definition: appd_iot_def.h:32
const char * error
Definition: appd_iot_def.h:249
int resp_headers_count
Definition: appd_iot_def.h:259
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
const char * appd_iot_get_eum_collector_url(void)
Get Configured EUM Collector URL.
Definition: config.cpp:193
data_t data
Definition: beacon.hpp:57
Definition: beacon.hpp:47
int duration_ms
Definition: appd_iot_def.h:251
std::string url
Definition: beacon.hpp:49
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
static bool appd_iot_is_valid_http_resp_code(int resp_code)
checks if http response code is valid
Definition: network_event.cpp:26
appd_iot_error_code_t appd_iot_clear_event_data(data_t *data)
Clear event data.
Definition: custom_event.cpp:91

◆ appd_iot_add_error_event()

appd_iot_error_code_t appd_iot_add_error_event ( appd_iot_error_event_t  error_event)

This method adds event data
Each call to add event will create a new event.

Parameters
error_eventcontains details of the error event
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.

This method adds event data
Each call to add event will create a new event.

Parameters
error_eventcontains event data
Returns
appd_iot_error_code_t indicating function execution status
35 {
36  appd_iot_error_code_t retcode;
37  appd_iot_sdk_state_t sdk_state;
38  error_event_t event;
39 
40  if ((sdk_state = appd_iot_get_sdk_state()) != APPD_IOT_SDK_ENABLED)
41  {
42  appd_iot_log(APPD_IOT_LOG_ERROR, "Add Error Event Failed. SDK Not in Enabled State:%s",
43  appd_iot_sdk_state_to_str(sdk_state));
44 
46  }
47 
48  retcode = APPD_IOT_SUCCESS;
49  event.timestamp_ms = error_event.timestamp_ms;
50  event.duration_ms = error_event.duration_ms;
51 
52  if (error_event.name != NULL)
53  {
54  event.name = error_event.name;
55  }
56  else
57  {
58  appd_iot_log(APPD_IOT_LOG_WARN, "Error Event Name cannot be NULL");
59  }
60 
61  if (error_event.message != NULL)
62  {
63  event.message = error_event.message;
64  }
65 
67  {
68  event.severity = severity_str[error_event.severity];
69  }
70  else
71  {
73  }
74 
75  if (error_event.stack_trace_count > 0)
76  {
77  if (error_event.error_stack_trace_index >= error_event.stack_trace_count)
78  {
79  appd_iot_log(APPD_IOT_LOG_ERROR, "Invalid error stack trace index, setting to index 0");
80 
81  event.error_stack_trace_index = 0;
82  }
83  else
84  {
85  event.error_stack_trace_index = error_event.error_stack_trace_index;
86  }
87 
89  error_event.stack_trace,
90  error_event.stack_trace_count);
91 
92  if (retcode != APPD_IOT_SUCCESS)
93  {
94  appd_iot_log(APPD_IOT_LOG_ERROR, "Failed to parse stack traces, error:%s",
96 
97  event.stack_trace_list.clear();
98  }
99  }
100  else
101  {
102  appd_iot_log(APPD_IOT_LOG_INFO, "No stack traces present");
103  }
104 
105  if (error_event.data_count > 0)
106  {
107  retcode = appd_iot_copy_event_data(&event.data, error_event.data,
108  error_event.data_count);
109 
110  if (retcode != APPD_IOT_SUCCESS)
111  {
112  appd_iot_log(APPD_IOT_LOG_ERROR, "Failed to parse error event data, error:%s",
113  appd_iot_error_code_to_str(retcode));
114 
116  }
117  }
118 
119  appd_iot_log(APPD_IOT_LOG_INFO, "Adding Error Event with name:%s", error_event.name);
120 
121  retcode = appd_iot_add_error_event_to_beacon(event);
122 
123  return retcode;
124 }
Definition: appd_iot_def.h:50
appd_iot_sdk_state_t
Enums for SDK State.
Definition: appd_iot_def.h:59
int duration_ms
Definition: appd_iot_def.h:326
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
appd_iot_error_code_t appd_iot_copy_event_data(data_t *destdata, appd_iot_data_t *srcdata, int srcdata_count)
Copies User Defined Event Data to SDK Defined Event Data.
Definition: custom_event.cpp:110
int data_count
Definition: appd_iot_def.h:334
appd_iot_sdk_state_t appd_iot_get_sdk_state(void)
Get Current SDK State.
Definition: config.cpp:236
int error_stack_trace_index
Definition: appd_iot_def.h:330
data_t data
Definition: beacon.hpp:87
appd_iot_stack_trace_t * stack_trace
Definition: appd_iot_def.h:332
const char * appd_iot_error_code_to_str(appd_iot_error_code_t error_code) __APPD_IOT_API
Convert error code to string.
Definition: log.cpp:193
const char * message
Definition: appd_iot_def.h:320
int stack_trace_count
Definition: appd_iot_def.h:328
Definition: appd_iot_def.h:64
appd_iot_error_code_t
Error Code Enums for SDK log.
Definition: appd_iot_def.h:27
int64_t timestamp_ms
Definition: appd_iot_def.h:324
Definition: appd_iot_def.h:103
std::list< stack_trace_t > stack_trace_list
Definition: beacon.hpp:86
static const char * severity_str[APPD_IOT_ERR_MAX_SEVERITY_LEVELS]
Definition: error_event.cpp:23
appd_iot_error_code_t appd_iot_add_error_event_to_beacon(error_event_t event)
Adds Error Event to Beacon.
Definition: beacon.cpp:141
Definition: appd_iot_def.h:87
appd_iot_data_t * data
Definition: appd_iot_def.h:336
Definition: appd_iot_def.h:83
const char * name
Definition: appd_iot_def.h:318
static appd_iot_error_code_t appd_iot_copy_stack_trace(std::list< stack_trace_t > *dest_stack_trace_list, appd_iot_stack_trace_t *src_stack_trace, int src_stack_trace_count)
Copies User Defined Stack Trace to SDK Defined Stack Trace.
Definition: error_event.cpp:134
appd_iot_error_severity_t severity
Definition: appd_iot_def.h:322
Definition: beacon.hpp:78
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
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_error_code_t appd_iot_clear_event_data(data_t *data)
Clear event data.
Definition: custom_event.cpp:91

◆ appd_iot_send_all_events()

appd_iot_error_code_t appd_iot_send_all_events ( void  )

This method sends all event data.
If events are sent successfuly to collector then they will be flushed out of memory.
If there is a network reject with response codes 402, 403 or 429 then events are flushed out of memory and SDK state set to DISABLED. If there is any other network error, events remain in memory for retry. Repeated calls to this API in SDK ENABLED State will retry sending the data in memory to the collector.
Use the API appd_iot_clear_all_events() to clear out events in memory if retries are unsuccessful.

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.

This method sends all event data.
If events are sent successfuly to collector then they will be flushed out of memory.
If there is a network reject with response codes 402, 403 or 429 then events are flushed out of memory and SDK state set to DISABLED. If there is any other network error, events remain in memory for retry. Repeated calls to this API in SDK ENABLED State will retry sending the data in memory to the collector.
Use the API appd_iot_clear_all_events() to clear out events in memory if retries are unsuccessful.

Returns
appd_iot_error_code_t indicating function execution status
200 {
201  appd_iot_sdk_state_t sdk_state;
202 
203  if ((sdk_state = appd_iot_get_sdk_state()) != APPD_IOT_SDK_ENABLED)
204  {
205  appd_iot_log(APPD_IOT_LOG_ERROR, "Send All Events Failed. SDK Not in Enabled State:%s",
206  appd_iot_sdk_state_to_str(sdk_state));
207 
209  }
210 
211  return appd_iot_send_all_beacons();
212 }
Definition: appd_iot_def.h:50
appd_iot_sdk_state_t
Enums for SDK State.
Definition: appd_iot_def.h:59
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_sdk_state_t appd_iot_get_sdk_state(void)
Get Current SDK State.
Definition: config.cpp:236
Definition: appd_iot_def.h:64
appd_iot_error_code_t appd_iot_send_all_beacons(void)
Sends Beacons in memory to collector. Max Limit on the number of events in the beacon is defined by...
Definition: beacon.cpp:189
Definition: appd_iot_def.h:99
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_clear_all_events()

appd_iot_error_code_t appd_iot_clear_all_events ( void  )

This method removes all event data stored in memory
This call is not needed if appd_iot_send_all_events return SUCCESS.

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.

This method removes all event data stored in memory
This call is not needed if appd_iot_send_all_events return SUCCESS.

Returns
appd_iot_error_code_t indicating function execution status
220 {
221  appd_iot_sdk_state_t sdk_state;
222 
223  if ((sdk_state = appd_iot_get_sdk_state()) != APPD_IOT_SDK_ENABLED)
224  {
225  appd_iot_log(APPD_IOT_LOG_ERROR, "Clear All Events Failed. SDK Not in Enabled State:%s",
226  appd_iot_sdk_state_to_str(sdk_state));
227 
229  }
230 
232 }
Definition: appd_iot_def.h:50
appd_iot_sdk_state_t
Enums for SDK State.
Definition: appd_iot_def.h:59
appd_iot_error_code_t appd_iot_clear_all_beacons(void)
Clears Beacons in memory.
Definition: beacon.cpp:167
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_sdk_state_t appd_iot_get_sdk_state(void)
Get Current SDK State.
Definition: config.cpp:236
Definition: appd_iot_def.h:64
Definition: appd_iot_def.h:99
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_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