Merge "removed vFW vLB extra executables"
[demo.git] / VES5.0 / evel / evel-library / code / evel_training / 13-suppress-fault-pairs / 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 pairs (under "alarmAdditionalInformation") with  */
63   /* names "name1" and "name2".                                              */
64   /***************************************************************************/
65   printf("TestControl: test collector suppress fault pairs\n");
66   fflush(stdout);
67   evel_test_control_scenario(TC_FAULT_SUPPRESS_PAIRS,
68                              api_secure,
69                              api_fqdn,
70                              api_port);
71   sleep(1);
72
73   /***************************************************************************/
74   /* Heartbeat to pick up the suppression change.                            */
75   /***************************************************************************/
76   demo_heartbeat();
77
78   /***************************************************************************/
79   /* Raise the same fault.                                                   */
80   /***************************************************************************/
81   printf("Raise normal fault ...\n");
82   fflush(stdout);
83   demo_fault();
84   sleep(1);
85
86   /***************************************************************************/
87   /* Ask for removal of fault suppression.                                   */
88   /***************************************************************************/
89   printf("TestControl: test collector remove fault suppression\n");
90   fflush(stdout);
91   evel_test_control_scenario(TC_FAULT_SUPPRESS_NOTHING,
92                              api_secure,
93                              api_fqdn,
94                              api_port);
95   sleep(1);
96
97   /***************************************************************************/
98   /* Heartbeat to pick up the suppression change.                            */
99   /***************************************************************************/
100   demo_heartbeat();
101
102   /***************************************************************************/
103   /* Raise the same fault.                                                   */
104   /***************************************************************************/
105   printf("Raise normal fault ...\n");
106   fflush(stdout);
107   demo_fault();
108   sleep(1);
109
110   /***************************************************************************/
111   /* Terminate                                                               */
112   /***************************************************************************/
113   sleep(1);
114   evel_terminate();
115   printf("Terminated\n");
116
117   return 0;
118 }
119
120 /**************************************************************************//**
121  * Create and send a heatbeat.
122  *****************************************************************************/
123 void demo_heartbeat()
124 {
125   EVENT_HEADER * heartbeat = NULL;
126   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
127
128   heartbeat = evel_new_heartbeat();
129   if (heartbeat != NULL)
130   {
131     evel_rc = evel_post_event(heartbeat);
132     if (evel_rc != EVEL_SUCCESS)
133     {
134       printf("Post failed %d (%s)", evel_rc, evel_error_string());
135     }
136   }
137   else
138   {
139     printf("New heartbeat failed");
140   }
141 }
142
143 /**************************************************************************//**
144  * Create and send a fault event.
145  *****************************************************************************/
146 void demo_fault(void)
147 {
148   EVENT_FAULT * fault = NULL;
149   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
150
151   fault = evel_new_fault("My alarm condition",
152                          "It broke very badly",
153                          EVEL_PRIORITY_NORMAL,
154                          EVEL_SEVERITY_MAJOR,
155                          EVEL_SOURCE_HOST,
156                          EVEL_VF_STATUS_PREP_TERMINATE);
157   if (fault != NULL)
158   {
159     evel_fault_type_set(fault, "Bad things happen...");
160     evel_fault_interface_set(fault, "My Interface Card");
161     evel_fault_addl_info_add(fault, "name1", "value1");
162     evel_fault_addl_info_add(fault, "name2", "value2");
163     evel_fault_addl_info_add(fault, "name3", "value3");
164     evel_fault_addl_info_add(fault, "name4", "value4");
165     evel_rc = evel_post_event((EVENT_HEADER *)fault);
166     if (evel_rc == EVEL_SUCCESS)
167     {
168       printf("Post OK!\n");
169     }
170     else
171     {
172       printf("Post Failed %d (%s)\n", evel_rc, evel_error_string());
173     }
174   }
175   else
176   {
177     printf("Failed to create event (%s)\n", evel_error_string());
178   }
179
180   printf("   Processed Fault\n");
181 }