1 /*****************************************************************************//***
2 * Copyright(c) <2017>, AT&T Intellectual Property. All other rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement: This product includes
14 * software developed by the AT&T.
15 * 4. Neither the name of AT&T nor the names of its contributors may be used to
16 * endorse or promote products derived from this software without specific
17 * prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *****************************************************************************/
40 #include <sys/types.h>
43 #include "afx_ves_reporter.h"
45 /**************************************************************************//**
46 * Monitor AFX services for current status
47 * returns success status 1 or failure 0.
49 * @param cmd Pointer to Shell cmd to monitor status.
50 * @param dtls Pointer to details of service
51 * Returns the start time of service
53 * @retvalue int Success 1 service running 0 service inactive
54 *****************************************************************************/
55 int monitor_afx_service( char *cmd, char *detls, char *svc )
68 printf("Failed to run command\n" );
72 /* Read the output a line at a time - output it. */
73 while (fgets(line, sizeof(line)-1, fp) != NULL) {
78 p = strtok (line, " ");
79 /* split string and append tokens to 'res' */
82 res = realloc (res, sizeof (char*) * ++n_spaces);
85 exit (-1); /* memory allocation failed */
89 p = strtok (NULL, " ");
92 /* realloc one extra element for the last NULL */
93 res = realloc (res, sizeof (char*) * (n_spaces+1));
96 if( n_spaces > 2 && lnno == 1 )
98 EVEL_DEBUG("AFX: Service %s\n",res[3]);
99 sprintf(svc,"%s",res[3]);
100 svc[strlen(svc)-1] = 0;
103 /* print the result */
104 if( n_spaces > 2 && !strcmp(res[0],"Active:") )
106 //for (i = 0; i < (n_spaces+1); ++i)
108 // printf ("res[%d] = %s\n", i, res[i]);
110 if(!strncmp(res[1],"activ",5)){
111 EVEL_DEBUG("AFX: Service Active\n");
114 EVEL_DEBUG("AFX: Service Inactive\n");
121 /* free the memory allocated */
122 if(res != NULL) free (res);
131 /**************************************************************************//**
132 * Thread function to Monitor AFX services
133 * Checks status of afx inout and afx output service every service monitor
134 * interval. It reports fault event at startup and whenever status changes
136 * @param threadarg Thread arguments for startup message
138 * @retvalue int Success 1 service running 0 service inactive
139 *****************************************************************************/
140 void *ServiceMonitorAfxThread(void *threadarg)
144 struct thread_data *my_data;
147 char *afxin = "afx@in*";
148 char *afxout = "afx@out*";
157 my_data = (struct thread_data *) threadarg;
158 taskid = my_data->thread_id;
160 hello_msg = my_data->message;
161 EVEL_INFO("AFX: Service Monitor Thread %d: %s Sum=%d\n", taskid, hello_msg, sum);
165 /* invokes afx service monitor function and collects return value */
166 sprintf(cmd,"/bin/systemctl status %s ",afxin);
167 tmpstate = monitor_afx_service( cmd, details,svc );
168 if( tmpstate != instate ){
169 printf("New afxin Service report sent %d\n",tmpstate);
172 sprintf(evid,"Fault_vAfx_SvcInput_%s",oam_intfaddr);
173 if (is_critical == 1){
175 sprintf(evid,"Fault_vAfx_SvcOutput_SvcInput_%s",oam_intfaddr);
176 report_fault("Fault_vAfx_Svc_input_Output",evid,
177 EVEL_SEVERITY_NORMAL, "routing", "AFXInput and AFXOutput",
178 "AFX services input and output down alarm",
179 details, NULL, NULL, NULL, instate);
181 sprintf(evid,"Fault_vAfx_SvcInput_%s",oam_intfaddr);
182 report_fault("Fault_vAfx_SvcInput",evid,EVEL_SEVERITY_NORMAL, "routing", "AFXInput", "AFX services input up alarm", details, NULL, NULL, NULL, instate);
184 sprintf(evid,"Fault_vAfx_SvcInput_%s",oam_intfaddr);
185 report_fault("Fault_vAfx_SvcInput",evid,EVEL_SEVERITY_MAJOR, "routing", "AFXInput", "AFX services input down alarm", details, NULL, NULL, NULL, instate);
189 /* invokes afx service monitor function and collects return value */
190 sprintf(cmd,"/bin/systemctl status %s ",afxout);
191 tmpstate = monitor_afx_service( cmd, details, svc );
192 if( tmpstate != outstate ){
193 printf("New afxout Service report sent %d\n",tmpstate);
196 if (is_critical == 1){
198 sprintf(evid,"Fault_vAfx_SvcOutput_SvcInput_%s",oam_intfaddr);
199 report_fault("Fault_vAfx_Svc_input_Output",evid,
200 EVEL_SEVERITY_NORMAL, "routing", "AFXInput and AFXOutput",
201 "AFX services input and output down alarm",
202 details, NULL, NULL, NULL, outstate);
204 sprintf(evid,"Fault_vAfx_SvcOutput_%s",oam_intfaddr);
205 report_fault("Fault_vAfx_SvcOutput",evid,EVEL_SEVERITY_NORMAL, "routing", "AFXOutput", "AFX services output up alarm", details, NULL, NULL, NULL, outstate );
207 sprintf(evid,"Fault_vAfx_SvcOutput_%s",oam_intfaddr);
208 report_fault("Fault_vAfx_SvcOutput",evid,EVEL_SEVERITY_MAJOR, "routing", "AFXOutput", "AFX services output down alarm", details, NULL, NULL, NULL, outstate);
211 if((instate == 0) && (outstate == 0) && (is_critical == 0))
215 sprintf(evid,"Fault_vAfx_SvcOutput_SvcInput_%s",oam_intfaddr);
216 report_fault("Fault_vAfx_Svc_input_Output",evid,EVEL_SEVERITY_CRITICAL,
217 "routing", "AFXInput and AFXOutput",
218 "AFX services input and output down alarm", details,
219 NULL, NULL, NULL, instate);
222 sleep(SERVICE_MONITOR_INTERVAL);