summaryrefslogtreecommitdiffstats
path: root/vnfs/VES/code/evel_library/evel_strings.c
blob: 9e215462341a88366d19bb1148efa66f81c9922c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/**************************************************************************//**
 * @file
 * Implementation of EVEL functions to convert common enum types to strings.
 *
 * License
 * -------
 *
 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

#include <string.h>
#include <assert.h>
#include <stdlib.h>

#include "evel_internal.h"

/**************************************************************************//**
 * Map an ::EVEL_COUNTER_CRITICALITIES enum value to the equivalent string.
 *
 * @param criticality   The criticality to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_criticality(const EVEL_COUNTER_CRITICALITIES criticality)
{
  char * result;

  EVEL_ENTER();

  switch (criticality)
  {
    case EVEL_COUNTER_CRITICALITY_CRIT:
      result = "CRIT";
      break;

    case EVEL_COUNTER_CRITICALITY_MAJ:
      result = "MAJ";
      break;

    default:
      EVEL_ERROR("Unexpected counter criticality %d", criticality);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Map an ::EVEL_SEVERITIES enum value to the equivalent string.
 *
 * @param severity      The severity to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_severity(const EVEL_SEVERITIES severity)
{
  char * result;

  EVEL_ENTER();

  switch (severity)
  {
    case EVEL_SEVERITY_CRITICAL:
      result = "CRITICAL";
      break;

    case EVEL_SEVERITY_MAJOR:
      result = "MAJOR";
      break;

    case EVEL_SEVERITY_MINOR:
      result = "MINOR";
      break;

    case EVEL_SEVERITY_WARNING:
      result = "WARNING";
      break;

    case EVEL_SEVERITY_NORMAL:
      result = "NORMAL";
      break;

    default:
      EVEL_ERROR("Unexpected event severity %d", severity);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Map an ::EVEL_ALERT_ACTIONS enum value to the equivalent string.
 *
 * @param alert_action  The alert_action to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_alert_action(const EVEL_ALERT_ACTIONS alert_action)
{
  char * result;

  EVEL_ENTER();

  switch (alert_action)
  {
    case EVEL_ALERT_ACTION_CLEAR:
      result = "CLEAR";
      break;

    case EVEL_ALERT_ACTION_CONT:
      result = "CONT";
      break;

    case EVEL_ALERT_ACTION_SET:
      result = "SET";
      break;

    default:
      EVEL_ERROR("Unexpected alert action %d", alert_action);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Map an ::EVEL_ALERT_TYPES enum value to the equivalent string.
 *
 * @param alert_type    The alert_type to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_alert_type(const EVEL_ALERT_TYPES alert_type)
{
  char * result;

  EVEL_ENTER();

  switch (alert_type)
  {
    case EVEL_ALERT_TYPE_CARD:
      result = "CARD-ANOMALY";
      break;

    case EVEL_ALERT_TYPE_ELEMENT:
      result = "ELEMENT-ANOMALY";
      break;

    case EVEL_ALERT_TYPE_INTERFACE:
      result = "INTERFACE-ANOMALY";
      break;

    case EVEL_ALERT_TYPE_SERVICE:
      result = "SERVICE-ANOMALY";
      break;

    default:
      EVEL_ERROR("Unexpected alert type %d", alert_type);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Map an ::EVEL_EVENT_DOMAINS enum value to the equivalent string.
 *
 * @param domain        The domain to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_event_domain(const EVEL_EVENT_DOMAINS domain)
{
  char * result;

  EVEL_ENTER();

  switch (domain)
  {
    case EVEL_DOMAIN_HEARTBEAT:
      result = "heartbeat";
      break;

    case EVEL_DOMAIN_FAULT:
      result = "fault";
      break;

    case EVEL_DOMAIN_MEASUREMENT:
      result = "measurementsForVfScaling";
      break;

    case EVEL_DOMAIN_REPORT:
      result = "measurementsForVfReporting";
      break;

    case EVEL_DOMAIN_MOBILE_FLOW:
      result = "mobileFlow";
      break;

    case EVEL_DOMAIN_SERVICE:
      result = "serviceEvents";
      break;

    case EVEL_DOMAIN_SIGNALING:
      result = "signaling";
      break;

    case EVEL_DOMAIN_STATE_CHANGE:
      result = "stateChange";
      break;

    case EVEL_DOMAIN_SYSLOG:
      result = "syslog";
      break;

    case EVEL_DOMAIN_OTHER:
      result = "other";
      break;

    default:
      result = NULL;
      EVEL_ERROR("Unexpected domain %d", domain);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Map an ::EVEL_EVENT_PRIORITIES enum value to the equivalent string.
 *
 * @param priority      The priority to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_event_priority(const EVEL_EVENT_PRIORITIES priority)
{
  char * result;

  EVEL_ENTER();

  switch (priority)
  {
    case EVEL_PRIORITY_HIGH:
      result = "High";
      break;

    case EVEL_PRIORITY_MEDIUM:
      result = "Medium";
      break;

    case EVEL_PRIORITY_NORMAL:
      result = "Normal";
      break;

    case EVEL_PRIORITY_LOW:
      result = "Low";
      break;

    default:
      result = NULL;
      EVEL_ERROR("Unexpected priority %d", priority);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Map an ::EVEL_SOURCE_TYPES enum value to the equivalent string.
 *
 * @param source_type   The source type to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_source_type(const EVEL_SOURCE_TYPES source_type)
{
  char * result;

  EVEL_ENTER();

  switch (source_type)
  {
    case EVEL_SOURCE_OTHER:
      result = "other";
      break;

    case EVEL_SOURCE_ROUTER:
      result = "router";
      break;

    case EVEL_SOURCE_SWITCH:
      result = "switch";
      break;

    case EVEL_SOURCE_HOST:
      result = "host";
      break;

    case EVEL_SOURCE_CARD:
      result = "card";
      break;

    case EVEL_SOURCE_PORT:
      result = "port";
      break;

    case EVEL_SOURCE_SLOT_THRESHOLD:
      result = "slotThreshold";
      break;

    case EVEL_SOURCE_PORT_THRESHOLD:
      result = "portThreshold";
      break;

    case EVEL_SOURCE_VIRTUAL_MACHINE:
      result = "virtualMachine";
      break;

    case EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION:
      result = "virtualNetworkFunction";
      break;

    default:
      result = NULL;
      EVEL_ERROR("Unexpected Event Source Type %d", (int) source_type);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Map an ::EVEL_VF_STATUSES enum value to the equivalent string.
 *
 * @param vf_status     The vf_status to convert.
 * @returns The equivalent string.
 *****************************************************************************/
char * evel_vf_status(const EVEL_VF_STATUSES vf_status)
{
  char * result;

  EVEL_ENTER();

  switch (vf_status)
  {
    case EVEL_VF_STATUS_ACTIVE:
      result = "Active";
      break;

    case EVEL_VF_STATUS_IDLE:
      result = "Idle";
      break;

    case EVEL_VF_STATUS_PREP_TERMINATE:
      result = "Preparing to terminate";
      break;

    case EVEL_VF_STATUS_READY_TERMINATE:
      result = "Ready to terminate";
      break;

    case EVEL_VF_STATUS_REQ_TERMINATE:
      result = "Requesting termination";
      break;

    default:
      result = NULL;
      EVEL_ERROR("Unexpected VF Status %d", vf_status);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Convert a ::EVEL_ENTITY_STATE to it's string form for JSON encoding.
 *
 * @param state         The entity state to encode.
 *
 * @returns the corresponding string
 *****************************************************************************/
char * evel_entity_state(const EVEL_ENTITY_STATE state)
{
  char * result;

  EVEL_ENTER();

  switch (state)
  {
    case EVEL_ENTITY_STATE_IN_SERVICE:
      result = "inService";
      break;

    case EVEL_ENTITY_STATE_MAINTENANCE:
      result = "maintenance";
      break;

    case EVEL_ENTITY_STATE_OUT_OF_SERVICE:
      result = "outOfService";
      break;

    default:
      EVEL_ERROR("Unexpected entity state %d", state);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}

/**************************************************************************//**
 * Convert a ::EVEL_SERVICE_ENDPOINT_DESC to string form for JSON encoding.
 *
 * @param endpoint_desc endpoint description to encode.
 *
 * @returns the corresponding string
 *****************************************************************************/
char * evel_service_endpoint_desc(const EVEL_ENTITY_STATE endpoint_desc)
{
  char * result;

  EVEL_ENTER();

  switch (endpoint_desc)
  {
    case EVEL_SERVICE_ENDPOINT_CALLEE:
      result = "Callee";
      break;

    case EVEL_SERVICE_ENDPOINT_CALLER:
      result = "Caller";
      break;

    default:
      EVEL_ERROR("Unexpected endpoint description %d", endpoint_desc);
      assert(0);
  }

  EVEL_EXIT();

  return result;
}