Merge "removed vFW vLB extra executables"
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_training / 05-raise-event / hello_evel_world.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include "evel.h"
6
7 int main(int argc, char ** argv)
8 {
9   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
10   EVENT_HEADER * heartbeat = NULL;
11   EVENT_FAULT * fault = NULL;
12
13   printf("\nHello AT&T Vendor Event world!\n");
14   fflush(stdout);
15
16   if (argc != 3)
17   {
18     fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port>\n", argv[0]);
19     exit(-1);
20   }
21
22   /***************************************************************************/
23   /* Initialize                                                              */
24   /***************************************************************************/
25   if (evel_initialize(argv[1],                      /* FQDN                  */
26                       atoi(argv[2]),                /* Port                  */
27                       NULL,                         /* optional path         */
28                       NULL,                         /* optional topic        */
29                       0,                            /* HTTPS?                */
30                       "",                           /* Username              */
31                       "",                           /* Password              */
32                       EVEL_SOURCE_VIRTUAL_MACHINE,  /* Source type           */
33                       "EVEL training demo",         /* Role                  */
34                       0))                           /* Verbosity             */
35   {
36     fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n");
37     exit(-1);
38   }
39   else
40   {
41     printf("\nInitialization completed\n");
42   }
43
44   /***************************************************************************/
45   /* Send a heartbeat just to show we're alive!                              */
46   /***************************************************************************/
47   heartbeat = evel_new_heartbeat();
48   if (heartbeat != NULL)
49   {
50     evel_rc = evel_post_event(heartbeat);
51     if (evel_rc != EVEL_SUCCESS)
52     {
53       printf("Post failed %d (%s)", evel_rc, evel_error_string());
54     }
55   }
56   else
57   {
58     printf("New heartbeat failed");
59   }
60
61   /***************************************************************************/
62   /* Raise a fault                                                           */
63   /***************************************************************************/
64   fault = evel_new_fault("My alarm condition",
65                          "It broke very badly",
66                          EVEL_PRIORITY_NORMAL,
67                          EVEL_SEVERITY_MAJOR,
68                         EVEL_SOURCE_HOST,
69                        EVEL_VF_STATUS_PREP_TERMINATE);
70   if (fault != NULL)
71   {
72     printf("New fault created...\n");
73     evel_rc = evel_post_event((EVENT_HEADER *)fault);
74     if (evel_rc == EVEL_SUCCESS)
75     {
76       printf("Fault posted OK!\n");
77     }
78     else
79     {
80       printf("Post failed %d (%s)\n", evel_rc, evel_error_string());
81     }
82   }
83   else
84   {
85     printf("New fault failed (%s)\n", evel_error_string());
86   }
87
88   /***************************************************************************/
89   /* Terminate                                                               */
90   /***************************************************************************/
91   sleep(1);
92   evel_terminate();
93   printf("Terminated\n");
94
95   return 0;
96 }