AppDynamics IoT C++ SDK
AppDynamics IoT C++ library contains code that facilitates capturing availability, usage, network performance and errors of an IoT Application.
custom_event.cpp File Reference
#include <string.h>
#include "custom_event.hpp"
#include "appd_iot_interface.h"
#include "log.hpp"
#include "config.hpp"
#include "utils.hpp"

Functions

appd_iot_error_code_t appd_iot_add_custom_event (appd_iot_custom_event_t custom_event)
 converts custom event data to beacon format and adds to beacon More...
 
appd_iot_error_code_t appd_iot_clear_event_data (data_t *data)
 Clear event data. More...
 
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. More...
 
appd_iot_error_code_t appd_iot_send_all_events (void)
 send all events to collector More...
 
appd_iot_error_code_t appd_iot_clear_all_events (void)
 Clear all events to collector. More...
 

Function Documentation

◆ appd_iot_add_custom_event()

appd_iot_error_code_t appd_iot_add_custom_event ( appd_iot_custom_event_t  custom_event)

converts custom event data to beacon format and adds to beacon

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

appd_iot_error_code_t appd_iot_clear_event_data ( data_t data)

Clear event data.

Parameters
datathat needs to be cleared
Returns
appd_iot_error_code_t indicating function execution status
92 {
93  data->stringmap.clear();
94  data->integermap.clear();
95  data->boolmap.clear();
96  data->datetimemap.clear();
97  data->doublemap.clear();
98 
99  return APPD_IOT_SUCCESS;
100 }
std::map< std::string, bool > boolmap
Definition: beacon.hpp:34
std::map< std::string, std::string > stringmap
Definition: beacon.hpp:31
std::map< std::string, int64_t > integermap
Definition: beacon.hpp:32
std::map< std::string, int64_t > datetimemap
Definition: beacon.hpp:35
std::map< std::string, double > doublemap
Definition: beacon.hpp:33
Definition: appd_iot_def.h:30

◆ appd_iot_copy_event_data()

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.

Parameters
destdatacontains event data to be copied to
srcdatacontains event data to be copied from
srcdata_countcontains number of key-value pairs in user defined event data
Returns
appd_iot_error_code_t indicating function execution status
111 {
112  if (destdata == NULL)
113  {
114  appd_iot_log(APPD_IOT_LOG_ERROR, "Destination Data Pointer in NULL");
115  return APPD_IOT_ERR_INTERNAL;
116  }
117 
118  if (srcdata == NULL)
119  {
120  appd_iot_log(APPD_IOT_LOG_ERROR, "Source Data Pointer is NULL");
121  return APPD_IOT_ERR_NULL_PTR;
122  }
123 
124  for (int i = 0; i < srcdata_count; i++)
125  {
126  if ((srcdata + i) == NULL)
127  {
128  appd_iot_log(APPD_IOT_LOG_ERROR, "Event Data at Index:%d is NULL", i);
129  return APPD_IOT_ERR_NULL_PTR;
130  }
131 
132  if (srcdata[i].key == NULL)
133  {
134  appd_iot_log(APPD_IOT_LOG_ERROR, "Event <Key> at Index:%d is NULL", i);
135  return APPD_IOT_ERR_NULL_PTR;
136  }
137 
138  std::string key = appd_iot_remove_character(srcdata[i].key, '|');
139 
140  switch (srcdata[i].value_type)
141  {
142  case APPD_IOT_INTEGER:
143  {
144  destdata->integermap[key] = srcdata[i].intval;
145  break;
146  }
147 
148  case APPD_IOT_DOUBLE:
149  {
150  destdata->doublemap[key] = srcdata[i].doubleval;
151  break;
152  }
153 
154  case APPD_IOT_BOOLEAN:
155  {
156  destdata->boolmap[key] = srcdata[i].boolval;
157  break;
158  }
159 
160  case APPD_IOT_STRING:
161  {
162  if (srcdata[i].strval != NULL)
163  {
164  destdata->stringmap[key] = srcdata[i].strval;
165  }
166  else
167  {
168  appd_iot_log(APPD_IOT_LOG_WARN, "String Value is NULL for key %s", srcdata[i].key);
169  }
170 
171  break;
172  }
173 
174  case APPD_IOT_DATETIME:
175  {
176  destdata->datetimemap[key] = srcdata[i].datetimeval;
177  break;
178  }
179 
180  default:
181  {
182  appd_iot_log(APPD_IOT_LOG_ERROR, "Skip Adding event field:%s due to invalid data type:%d",
183  srcdata[i].key, srcdata[i].value_type);
184  break;
185  }
186  }
187 
188  appd_iot_log(APPD_IOT_LOG_INFO, "Added Key :%s with value type:%d", key.c_str(), srcdata[i].value_type);
189  }
190 
191  return APPD_IOT_SUCCESS;
192 }
int64_t datetimeval
Definition: appd_iot_def.h:213
Definition: appd_iot_def.h:44
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
bool boolval
Definition: appd_iot_def.h:210
Definition: appd_iot_def.h:101
Definition: appd_iot_def.h:192
double doubleval
Definition: appd_iot_def.h:212
std::map< std::string, bool > boolmap
Definition: beacon.hpp:34
std::map< std::string, std::string > stringmap
Definition: beacon.hpp:31
Definition: appd_iot_def.h:194
Definition: appd_iot_def.h:103
const char * strval
Definition: appd_iot_def.h:209
std::map< std::string, int64_t > integermap
Definition: beacon.hpp:32
Definition: appd_iot_def.h:188
std::map< std::string, int64_t > datetimemap
Definition: beacon.hpp:35
Definition: appd_iot_def.h:190
appd_iot_data_types_t value_type
Definition: appd_iot_def.h:215
int64_t intval
Definition: appd_iot_def.h:211
Definition: appd_iot_def.h:196
std::string appd_iot_remove_character(const char *input, char c)
Removes a given character from the input string.
Definition: utils.cpp:27
std::map< std::string, double > doublemap
Definition: beacon.hpp:33
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
Definition: appd_iot_def.h:46

◆ appd_iot_send_all_events()

appd_iot_error_code_t appd_iot_send_all_events ( void  )

send all events to collector

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  )

Clear all events to collector.

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