1 /*************************************************************************//**
3 * Main Agent which spins up monitoring threads
5 * Version 1.0: Gokul Singaraju gs244f Tech Mahindra Inc.
7 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 ****************************************************************************/
23 #include <string.h> /* for strncpy */
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <sys/ioctl.h>
28 #include <netinet/in.h>
30 #include <arpa/inet.h>
33 #include "afx_ves_reporter.h"
36 /**************************************************************************//**
37 * Utility function to Create and send fault events.
38 *****************************************************************************/
39 void report_fault( char* evname, char *evid, EVEL_SEVERITIES sevty, char *categ, char *intf, char *trapname, char *descr, char *rem_router, char *routername, char *router_ip, int status )
41 EVENT_FAULT * fault = NULL;
42 EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
44 /***************************************************************************/
46 /***************************************************************************/
47 if (status == 1) /** ACTIVE **/
49 fault = evel_new_fault(evname,
56 EVEL_VF_STATUS_ACTIVE);
60 fault = evel_new_fault(evname,
72 evel_header_type_set((EVENT_HEADER *)fault, "applicationVnf");
73 evel_nfcnamingcode_set((EVENT_HEADER *)fault, "AFX");
74 evel_nfnamingcode_set((EVENT_HEADER *)fault, "AFX");
76 evel_fault_category_set(fault, categ);
78 evel_fault_interface_set(fault, intf );
80 if( strstr(evname,"Fault_vAfx_Link") != NULL || strstr(evname,"Fault_vAfx_bgp") != NULL)
82 evel_fault_addl_info_add(fault, "remote_router", rem_router);
83 evel_fault_addl_info_add(fault, "router_name", routername);
86 if( strstr(evname,"Fault_vAfx_bgp") != NULL )
87 evel_fault_addl_info_add(fault, "router_ip", router_ip);
89 evel_rc = evel_post_event((EVENT_HEADER *)fault);
90 if (evel_rc != EVEL_SUCCESS)
92 EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
97 EVEL_ERROR("New Fault failed");
99 printf(" Generated Fault event\n");
103 int file_is_modified(const char *path, time_t *oldMTime) {
104 struct stat file_stat;
105 int err = stat(path, &file_stat);
107 perror(" [file_is_modified] stat");
110 if( file_stat.st_mtime > *oldMTime)
112 *oldMTime = file_stat.st_mtime;
119 void remove_spaces(char* source)
133 char *get_oam_intfaddr()
140 fd = socket(AF_INET, SOCK_DGRAM, 0);
142 /* I want to get an IPv4 IP address */
143 ifr.ifr_addr.sa_family = AF_INET;
145 /* I want IP address attached to "eth0" */
146 strncpy(ifr.ifr_name, OAM_INTERFACE, IFNAMSIZ-1);
148 ret = ioctl(fd, SIOCGIFADDR, &ifr);
155 sprintf(oamaddr,"%s", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));
156 //printf("Loopback address %s\n", oamaddr);
159 sprintf(oamaddr,"127.0.0.1");
161 return strdup(oamaddr);
165 char *escape_json(char *in) {
170 for (c = in; *c != '\0'; c++) {
172 case '"': strcat(o,"\\\"");o+=2; break;
173 case '\\': strcat(o, "\\\\");o+=2; break;
174 case '\b': strcat(o, "\\b");o+=2; break;
175 case '\f': strcat(o, "\\f");o+=2; break;
176 case '\n': strcat(o, "\\n");o+=2; break;
177 case '\r': strcat(o, "\\r");o+=2; break;
178 case '\t': strcat(o, "\\t");o+=2; break;
180 if ('\x00' <= *c && *c <= '\x1f') {
183 sprintf(tmp,"%04X",(int)*c);