96db59bd7dbb8062ec585cccd810266a1f5319fb
[vnfsdk/compliance.git] / veslibrary / ves_clibrary / evel / evel-library / code / evel_library / evel_strings.c
1 /*************************************************************************//**
2  *
3  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and 
14  * limitations under the License.
15  *
16  ****************************************************************************/
17 /**************************************************************************//**
18  * @file
19  * Implementation of EVEL functions to convert common enum types to strings.
20  *
21  ****************************************************************************/
22
23 #include <string.h>
24 #include <assert.h>
25 #include <stdlib.h>
26
27 #include "evel_internal.h"
28
29 /**************************************************************************//**
30  * Map an ::EVEL_COUNTER_CRITICALITIES enum value to the equivalent string.
31  *
32  * @param criticality   The criticality to convert.
33  * @returns The equivalent string.
34  *****************************************************************************/
35 char * evel_criticality(const EVEL_COUNTER_CRITICALITIES criticality)
36 {
37   char * result;
38
39   EVEL_ENTER();
40
41   switch (criticality)
42   {
43     case EVEL_COUNTER_CRITICALITY_CRIT:
44       result = "CRIT";
45       break;
46
47     case EVEL_COUNTER_CRITICALITY_MAJ:
48       result = "MAJ";
49       break;
50
51     default:
52       EVEL_ERROR("Unexpected counter criticality %d", criticality);
53       assert(0);
54   }
55
56   EVEL_EXIT();
57
58   return result;
59 }
60
61 /**************************************************************************//**
62  * Map an ::EVEL_SEVERITIES enum value to the equivalent string.
63  *
64  * @param severity      The severity to convert.
65  * @returns The equivalent string.
66  *****************************************************************************/
67 char * evel_severity(const EVEL_SEVERITIES severity)
68 {
69   char * result;
70
71   EVEL_ENTER();
72
73   switch (severity)
74   {
75     case EVEL_SEVERITY_CRITICAL:
76       result = "CRITICAL";
77       break;
78
79     case EVEL_SEVERITY_MAJOR:
80       result = "MAJOR";
81       break;
82
83     case EVEL_SEVERITY_MINOR:
84       result = "MINOR";
85       break;
86
87     case EVEL_SEVERITY_WARNING:
88       result = "WARNING";
89       break;
90
91     case EVEL_SEVERITY_NORMAL:
92       result = "NORMAL";
93       break;
94
95     default:
96       EVEL_ERROR("Unexpected event severity %d", severity);
97       assert(0);
98   }
99
100   EVEL_EXIT();
101
102   return result;
103 }
104
105 /**************************************************************************//**
106  * Map an ::EVEL_ALERT_ACTIONS enum value to the equivalent string.
107  *
108  * @param alert_action  The alert_action to convert.
109  * @returns The equivalent string.
110  *****************************************************************************/
111 char * evel_alert_action(const EVEL_ALERT_ACTIONS alert_action)
112 {
113   char * result;
114
115   EVEL_ENTER();
116
117   switch (alert_action)
118   {
119     case EVEL_ALERT_ACTION_CLEAR:
120       result = "CLEAR";
121       break;
122
123     case EVEL_ALERT_ACTION_CONT:
124       result = "CONT";
125       break;
126
127     case EVEL_ALERT_ACTION_SET:
128       result = "SET";
129       break;
130
131     default:
132       EVEL_ERROR("Unexpected alert action %d", alert_action);
133       assert(0);
134   }
135
136   EVEL_EXIT();
137
138   return result;
139 }
140
141 /**************************************************************************//**
142  * Map an ::EVEL_ALERT_TYPES enum value to the equivalent string.
143  *
144  * @param alert_type    The alert_type to convert.
145  * @returns The equivalent string.
146  *****************************************************************************/
147 char * evel_alert_type(const EVEL_ALERT_TYPES alert_type)
148 {
149   char * result;
150
151   EVEL_ENTER();
152
153   switch (alert_type)
154   {
155     case EVEL_ALERT_TYPE_CARD:
156       result = "CARD-ANOMALY";
157       break;
158
159     case EVEL_ALERT_TYPE_ELEMENT:
160       result = "ELEMENT-ANOMALY";
161       break;
162
163     case EVEL_ALERT_TYPE_INTERFACE:
164       result = "INTERFACE-ANOMALY";
165       break;
166
167     case EVEL_ALERT_TYPE_SERVICE:
168       result = "SERVICE-ANOMALY";
169       break;
170
171     default:
172       EVEL_ERROR("Unexpected alert type %d", alert_type);
173       assert(0);
174   }
175
176   EVEL_EXIT();
177
178   return result;
179 }
180
181 /**************************************************************************//**
182  * Map an ::EVEL_EVENT_DOMAINS enum value to the equivalent string.
183  *
184  * @param domain        The domain to convert.
185  * @returns The equivalent string.
186  *****************************************************************************/
187 char * evel_event_domain(const EVEL_EVENT_DOMAINS domain)
188 {
189   char * result;
190
191   EVEL_ENTER();
192
193   switch (domain)
194   {
195     case EVEL_DOMAIN_HEARTBEAT:
196       result = "heartbeat";
197       break;
198
199     case EVEL_DOMAIN_FAULT:
200       result = "fault";
201       break;
202
203     case EVEL_DOMAIN_MEASUREMENT:
204       result = "measurementsForVfScaling";
205       break;
206
207     case EVEL_DOMAIN_REPORT:
208       result = "measurementsForVfReporting";
209       break;
210
211     case EVEL_DOMAIN_MOBILE_FLOW:
212       result = "mobileFlow";
213       break;
214
215     case EVEL_DOMAIN_HEARTBEAT_FIELD:
216       result = "heartbeat";
217       break;
218
219     case EVEL_DOMAIN_SIPSIGNALING:
220       result = "sipSignaling";
221       break;
222
223     case EVEL_DOMAIN_STATE_CHANGE:
224       result = "stateChange";
225       break;
226
227     case EVEL_DOMAIN_SYSLOG:
228       result = "syslog";
229       break;
230
231     case EVEL_DOMAIN_OTHER:
232       result = "other";
233       break;
234
235     case EVEL_DOMAIN_VOICE_QUALITY:
236       result = "voiceQuality";
237       break;
238
239     case EVEL_DOMAIN_THRESHOLD_CROSS:
240       result = "thresholdCrossingAlert";
241       break;
242
243     default:
244       result = NULL;
245       EVEL_ERROR("Unexpected domain %d", domain);
246       assert(0);
247   }
248
249   EVEL_EXIT();
250
251   return result;
252 }
253
254 /**************************************************************************//**
255  * Map an ::EVEL_EVENT_PRIORITIES enum value to the equivalent string.
256  *
257  * @param priority      The priority to convert.
258  * @returns The equivalent string.
259  *****************************************************************************/
260 char * evel_event_priority(const EVEL_EVENT_PRIORITIES priority)
261 {
262   char * result;
263
264   EVEL_ENTER();
265
266   switch (priority)
267   {
268     case EVEL_PRIORITY_HIGH:
269       result = "High";
270       break;
271
272     case EVEL_PRIORITY_MEDIUM:
273       result = "Medium";
274       break;
275
276     case EVEL_PRIORITY_NORMAL:
277       result = "Normal";
278       break;
279
280     case EVEL_PRIORITY_LOW:
281       result = "Low";
282       break;
283
284     default:
285       result = NULL;
286       EVEL_ERROR("Unexpected priority %d", priority);
287       assert(0);
288   }
289
290   EVEL_EXIT();
291
292   return result;
293 }
294
295 /**************************************************************************//**
296  * Map an ::EVEL_SOURCE_TYPES enum value to the equivalent string.
297  *
298  * @param source_type   The source type to convert.
299  * @returns The equivalent string.
300  *****************************************************************************/
301 char * evel_source_type(const EVEL_SOURCE_TYPES source_type)
302 {
303   char * result;
304
305   EVEL_ENTER();
306
307   switch (source_type)
308   {
309     case EVEL_SOURCE_OTHER:
310       result = "other";
311       break;
312
313     case EVEL_SOURCE_ROUTER:
314       result = "router";
315       break;
316
317     case EVEL_SOURCE_SWITCH:
318       result = "switch";
319       break;
320
321     case EVEL_SOURCE_HOST:
322       result = "host";
323       break;
324
325     case EVEL_SOURCE_CARD:
326       result = "card";
327       break;
328
329     case EVEL_SOURCE_PORT:
330       result = "port";
331       break;
332
333     case EVEL_SOURCE_SLOT_THRESHOLD:
334       result = "slotThreshold";
335       break;
336
337     case EVEL_SOURCE_PORT_THRESHOLD:
338       result = "portThreshold";
339       break;
340
341     case EVEL_SOURCE_VIRTUAL_MACHINE:
342       result = "virtualMachine";
343       break;
344
345     case EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION:
346       result = "virtualNetworkFunction";
347       break;
348
349     default:
350       result = NULL;
351       EVEL_ERROR("Unexpected Event Source Type %d", (int) source_type);
352       assert(0);
353   }
354
355   EVEL_EXIT();
356
357   return result;
358 }
359
360 /**************************************************************************//**
361  * Map an ::EVEL_VF_STATUSES enum value to the equivalent string.
362  *
363  * @param vf_status     The vf_status to convert.
364  * @returns The equivalent string.
365  *****************************************************************************/
366 char * evel_vf_status(const EVEL_VF_STATUSES vf_status)
367 {
368   char * result;
369
370   EVEL_ENTER();
371
372   switch (vf_status)
373   {
374     case EVEL_VF_STATUS_ACTIVE:
375       result = "Active";
376       break;
377
378     case EVEL_VF_STATUS_IDLE:
379       result = "Idle";
380       break;
381
382     case EVEL_VF_STATUS_PREP_TERMINATE:
383       result = "Preparing to terminate";
384       break;
385
386     case EVEL_VF_STATUS_READY_TERMINATE:
387       result = "Ready to terminate";
388       break;
389
390     case EVEL_VF_STATUS_REQ_TERMINATE:
391       result = "Requesting termination";
392       break;
393
394     default:
395       result = NULL;
396       EVEL_ERROR("Unexpected VF Status %d", vf_status);
397       assert(0);
398   }
399
400   EVEL_EXIT();
401
402   return result;
403 }
404
405 /**************************************************************************//**
406  * Convert a ::EVEL_ENTITY_STATE to it's string form for JSON encoding.
407  *
408  * @param state         The entity state to encode.
409  *
410  * @returns the corresponding string
411  *****************************************************************************/
412 char * evel_entity_state(const EVEL_ENTITY_STATE state)
413 {
414   char * result;
415
416   EVEL_ENTER();
417
418   switch (state)
419   {
420     case EVEL_ENTITY_STATE_IN_SERVICE:
421       result = "inService";
422       break;
423
424     case EVEL_ENTITY_STATE_MAINTENANCE:
425       result = "maintenance";
426       break;
427
428     case EVEL_ENTITY_STATE_OUT_OF_SERVICE:
429       result = "outOfService";
430       break;
431
432     default:
433       EVEL_ERROR("Unexpected entity state %d", state);
434       assert(0);
435   }
436
437   EVEL_EXIT();
438
439   return result;
440 }
441
442 /**************************************************************************//**
443  * Convert a ::EVEL_SERVICE_ENDPOINT_DESC to string form for JSON encoding.
444  *
445  * @param endpoint_desc endpoint description to encode.
446  *
447  * @returns the corresponding string
448  *****************************************************************************/
449 char * evel_service_endpoint_desc(const EVEL_ENTITY_STATE endpoint_desc)
450 {
451   char * result;
452
453   EVEL_ENTER();
454
455   switch (endpoint_desc)
456   {
457     case EVEL_SERVICE_ENDPOINT_CALLEE:
458       result = "Callee";
459       break;
460
461     case EVEL_SERVICE_ENDPOINT_CALLER:
462       result = "Caller";
463       break;
464
465     default:
466       EVEL_ERROR("Unexpected endpoint description %d", endpoint_desc);
467       assert(0);
468   }
469
470   EVEL_EXIT();
471
472   return result;
473 }