Fix for delta values reported by vFW vLB
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_training / 12-suppress-fault-fields / hello_evel_world.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include "evel.h"
6 #include "evel_test_control.h"
7
8 /*****************************************************************************/
9 /* Local prototypes.                                                         */
10 /*****************************************************************************/
11 static void demo_heartbeat();
12 static void demo_fault(void);
13
14 int main(int argc, char ** argv)
15 {
16   printf("\nHello AT&T Vendor Event world!\n");
17   fflush(stdout);
18
19   if (argc != 5)
20   {
21     fprintf(stderr,
22             "Usage: %s <FQDN>|<IP address> <port> "
23             "<username> <password>\n", argv[0]);
24     exit(-1);
25   }
26
27   char * api_fqdn = argv[1];
28   int api_port = atoi(argv[2]);
29   int api_secure = 0;
30
31   /***************************************************************************/
32   /* Initialize                                                              */
33   /***************************************************************************/
34   if (evel_initialize(api_fqdn,                     /* FQDN                  */
35                       api_port,                     /* Port                  */
36                       NULL,                         /* optional path         */
37                       NULL,                         /* optional topic        */
38                       api_secure,                   /* HTTPS?                */
39                       argv[3],                      /* Username              */
40                       argv[4],                      /* Password              */
41                       EVEL_SOURCE_VIRTUAL_MACHINE,  /* Source type           */
42                       "EVEL training demo",         /* Role                  */
43                       0))                           /* Verbosity             */
44   {
45     fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n");
46     exit(-1);
47   }
48   else
49   {
50     printf("\nInitialization completed\n");
51   }
52
53   /***************************************************************************/
54   /* Raise a fault.                                                          */
55   /***************************************************************************/
56   printf("Raise normal fault ...\n");
57   fflush(stdout);
58   demo_fault();
59   sleep(1);
60
61   /***************************************************************************/
62   /* Ask for suppression of alarmInterfaceA and alarmAdditionalInformation.  */
63   /***************************************************************************/
64   printf("TestControl: test collector suppress fault fields\n");
65   fflush(stdout);
66   evel_test_control_scenario(TC_FAULT_SUPPRESS_FIELDS,
67                              api_secure,
68                              api_fqdn,
69                              api_port);
70   sleep(1);
71
72   /***************************************************************************/
73   /* Heartbeat to pick up the suppression change.                            */
74   /***************************************************************************/
75   demo_heartbeat();
76
77   /***************************************************************************/
78   /* Raise the same fault.                                                   */
79   /***************************************************************************/
80   printf("Raise normal fault ...\n");
81   fflush(stdout);
82   demo_fault();
83   sleep(1);
84
85   /***************************************************************************/
86   /* Ask for removal of fault suppression.                                   */
87   /***************************************************************************/
88   printf("TestControl: test collector remove fault suppression\n");
89   fflush(stdout);
90   evel_test_control_scenario(TC_FAULT_SUPPRESS_NOTHING,
91                              api_secure,
92                              api_fqdn,
93                              api_port);
94   sleep(1);
95
96   /***************************************************************************/
97   /* Heartbeat to pick up the suppression change.                            */
98   /***************************************************************************/
99   demo_heartbeat();
100
101   /***************************************************************************/
102   /* Raise the same fault.                                                   */
103   /***************************************************************************/
104   printf("Raise normal fault ...\n");
105   fflush(stdout);
106   demo_fault();
107   sleep(1);
108
109   /***************************************************************************/
110   /* Terminate                                                               */
111   /***************************************************************************/
112   sleep(1);
113   evel_terminate();
114   printf("Terminated\n");
115
116   return 0;
117 }
118
119 /**************************************************************************//**
120  * Create and send a heatbeat.
121  *****************************************************************************/
122 void demo_heartbeat()
123 {
124   EVENT_HEADER * heartbeat = NULL;
125   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
126
127   heartbeat = evel_new_heartbeat();
128   if (heartbeat != NULL)
129   {
130     evel_rc = evel_post_event(heartbeat);
131     if (evel_rc != EVEL_SUCCESS)
132     {
133       printf("Post failed %d (%s)", evel_rc, evel_error_string());
134     }
135   }
136   else
137   {
138     printf("New heartbeat failed");
139   }
140 }
141
142 /**************************************************************************//**
143  * Create and send a fault event.
144  *****************************************************************************/
145 void demo_fault(void)
146 {
147   EVENT_FAULT * fault = NULL;
148   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
149
150   fault = evel_new_fault("My alarm condition",
151                          "It broke very badly",
152                          EVEL_PRIORITY_NORMAL,
153                          EVEL_SEVERITY_MAJOR,
154                         EVEL_SOURCE_HOST,
155                        EVEL_VF_STATUS_PREP_TERMINATE);
156   if (fault != NULL)
157   {
158     evel_fault_type_set(fault, "Bad things happen...");
159     evel_fault_interface_set(fault, "My Interface Card");
160     evel_fault_addl_info_add(fault, "name1", "value1");
161     evel_fault_addl_info_add(fault, "name2", "value2");
162     evel_fault_addl_info_add(fault, "name3", "value3");
163     evel_fault_addl_info_add(fault, "name4", "value4");
164     evel_rc = evel_post_event((EVENT_HEADER *)fault);
165     if (evel_rc == EVEL_SUCCESS)
166     {
167       printf("Post OK!\n");
168     }
169     else
170     {
171       printf("Post Failed %d (%s)\n", evel_rc, evel_error_string());
172     }
173   }
174   else
175   {
176     printf("Failed to create event (%s)\n", evel_error_string());
177   }
178
179   printf("   Processed Fault\n");
180 }