Change location of VES5.0 code
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_training / 06-username-password / 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 != 5)
17   {
18     fprintf(stderr,
19             "Usage: %s <FQDN>|<IP address> <port> "
20             "<username> <password>\n", argv[0]);
21     exit(-1);
22   }
23
24   /***************************************************************************/
25   /* Initialize                                                              */
26   /***************************************************************************/
27   if (evel_initialize(argv[1],                      /* FQDN                  */
28                       atoi(argv[2]),                /* Port                  */
29                       NULL,                         /* optional path         */
30                       NULL,                         /* optional topic        */
31                       0,                            /* HTTPS?                */
32                       argv[3],                      /* Username              */
33                       argv[4],                      /* Password              */
34                       EVEL_SOURCE_VIRTUAL_MACHINE,  /* Source type           */
35                       "EVEL training demo",         /* Role                  */
36                       0))                           /* Verbosity             */
37   {
38     fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n");
39     exit(-1);
40   }
41   else
42   {
43     printf("\nInitialization completed\n");
44   }
45
46   /***************************************************************************/
47   /* Send a heartbeat just to show we're alive!                              */
48   /***************************************************************************/
49   heartbeat = evel_new_heartbeat();
50   if (heartbeat != NULL)
51   {
52     evel_rc = evel_post_event(heartbeat);
53     if (evel_rc != EVEL_SUCCESS)
54     {
55       printf("Post failed %d (%s)", evel_rc, evel_error_string());
56     }
57   }
58   else
59   {
60     printf("New heartbeat failed");
61   }
62
63   /***************************************************************************/
64   /* Raise a fault                                                           */
65   /***************************************************************************/
66   fault = evel_new_fault("My alarm condition",
67                          "It broke very badly",
68                          EVEL_PRIORITY_NORMAL,
69                          EVEL_SEVERITY_MAJOR,
70                          EVEL_SOURCE_HOST,
71                          EVEL_VF_STATUS_PREP_TERMINATE);
72   if (fault != NULL)
73   {
74     printf("New fault created...\n");
75     evel_rc = evel_post_event((EVENT_HEADER *)fault);
76     if (evel_rc == EVEL_SUCCESS)
77     {
78       printf("Fault posted OK!\n");
79     }
80     else
81     {
82       printf("Post failed %d (%s)\n", evel_rc, evel_error_string());
83     }
84   }
85   else
86   {
87     printf("New fault failed (%s)\n", evel_error_string());
88   }
89
90   /***************************************************************************/
91   /* Terminate                                                               */
92   /***************************************************************************/
93   sleep(1);
94   evel_terminate();
95   printf("Terminated\n");
96
97   return 0;
98 }