去掉无用代码
This commit is contained in:
@@ -32,9 +32,11 @@
|
|||||||
#define MAX_NAME_LEN 32
|
#define MAX_NAME_LEN 32
|
||||||
#define CPU_START_POS 14//stat文件的有效起始行数
|
#define CPU_START_POS 14//stat文件的有效起始行数
|
||||||
#define HTTP_TIMEOUT 100
|
#define HTTP_TIMEOUT 100
|
||||||
|
#define RET_OK 0
|
||||||
|
#define RET_ERROR -1
|
||||||
uint16_t g_http_port;
|
uint16_t g_http_port;
|
||||||
char g_http_address[MAX_STR_LEN]="";
|
|
||||||
const char *http_check_conf_file = "./plug/business/http_check/http_check.conf";
|
const char *http_check_conf_file = "./plug/business/http_check/http_check.conf";
|
||||||
|
char g_http_address[MAX_STR_LEN]="";
|
||||||
char http_check_log_path[MAX_STR_LEN] = "";
|
char http_check_log_path[MAX_STR_LEN] = "";
|
||||||
char http_check_error_log_path[MAX_STR_LEN] = "";
|
char http_check_error_log_path[MAX_STR_LEN] = "";
|
||||||
char module_name[MAX_STR_LEN] = "";
|
char module_name[MAX_STR_LEN] = "";
|
||||||
@@ -157,7 +159,7 @@ float get_cpu_stat(unsigned int pid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取默认网关地址
|
//获取默认网关地址
|
||||||
int readNlSock(int sockFd, char *bufPtr, int seqNum, int pId)
|
int readNlSock(int sockFd, char *bufPtr)
|
||||||
{
|
{
|
||||||
struct nlmsghdr *nlHdr = NULL;
|
struct nlmsghdr *nlHdr = NULL;
|
||||||
int readLen = 0, msgLen = 0;
|
int readLen = 0, msgLen = 0;
|
||||||
@@ -171,7 +173,7 @@ int readNlSock(int sockFd, char *bufPtr, int seqNum, int pId)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
printf("sock recv return for readLen < 0!");
|
//printf("sock recv return for readLen < 0!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +181,7 @@ int readNlSock(int sockFd, char *bufPtr, int seqNum, int pId)
|
|||||||
//检查header是否有效
|
//检查header是否有效
|
||||||
if((NLMSG_OK(nlHdr, readLen) == 0) || (nlHdr->nlmsg_type == NLMSG_ERROR))
|
if((NLMSG_OK(nlHdr, readLen) == 0) || (nlHdr->nlmsg_type == NLMSG_ERROR))
|
||||||
{
|
{
|
||||||
printf("sock recv return for header error!\n");
|
//printf("sock recv return for header error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,14 +204,15 @@ int readNlSock(int sockFd, char *bufPtr, int seqNum, int pId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//分析返回的路由信息
|
//分析返回的路由信息
|
||||||
void parseRoutes(struct nlmsghdr *nlHdr,char *gateway,unsigned int len)
|
int parseRoutes(struct nlmsghdr *nlHdr,char *gateway,unsigned int len)
|
||||||
{
|
{
|
||||||
struct rtmsg *rtMsg = NULL;
|
struct rtmsg *rtMsg = NULL;
|
||||||
struct rtattr *rtAttr = NULL;
|
struct rtattr *rtAttr = NULL;
|
||||||
int rtLen;
|
int rtLen;
|
||||||
char dst_address[MAX_STR_LEN] = "";
|
char dst_address[MAX_STR_LEN] = "";
|
||||||
struct route_info rtInfo;
|
struct route_info rtInfo;
|
||||||
|
int ret = RET_ERROR;
|
||||||
|
|
||||||
memset(&rtInfo, 0, sizeof(struct route_info));
|
memset(&rtInfo, 0, sizeof(struct route_info));
|
||||||
rtMsg = (struct rtmsg *)NLMSG_DATA(nlHdr);
|
rtMsg = (struct rtmsg *)NLMSG_DATA(nlHdr);
|
||||||
// If the route is not for AF_INET or does not belong to main routing table
|
// If the route is not for AF_INET or does not belong to main routing table
|
||||||
@@ -218,7 +221,7 @@ void parseRoutes(struct nlmsghdr *nlHdr,char *gateway,unsigned int len)
|
|||||||
//RT_TABLE_MAIN存储到其它主机的路由表项;
|
//RT_TABLE_MAIN存储到其它主机的路由表项;
|
||||||
if((rtMsg->rtm_family != AF_INET) || (rtMsg->rtm_table != RT_TABLE_MAIN))
|
if((rtMsg->rtm_family != AF_INET) || (rtMsg->rtm_table != RT_TABLE_MAIN))
|
||||||
{
|
{
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtAttr = (struct rtattr *)RTM_RTA(rtMsg); //路由信息
|
rtAttr = (struct rtattr *)RTM_RTA(rtMsg); //路由信息
|
||||||
@@ -245,11 +248,14 @@ void parseRoutes(struct nlmsghdr *nlHdr,char *gateway,unsigned int len)
|
|||||||
inet_ntop(AF_INET, &rtInfo.dstAddr, dst_address, MAX_STR_LEN);
|
inet_ntop(AF_INET, &rtInfo.dstAddr, dst_address, MAX_STR_LEN);
|
||||||
if (strstr(dst_address, "0.0.0.0"))
|
if (strstr(dst_address, "0.0.0.0"))
|
||||||
{
|
{
|
||||||
inet_ntop(AF_INET, &rtInfo.gateWay, gateway, len);
|
if(rtInfo.gateWay)
|
||||||
//printf("%s\n",gateway);
|
inet_ntop(AF_INET, &rtInfo.gateWay, gateway, len);
|
||||||
|
else if(rtInfo.ifName)
|
||||||
|
strncpy(gateway, rtInfo.ifName, IF_NAMESIZE);
|
||||||
|
ret = RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_gateway(char *gateway, unsigned int length)
|
int get_gateway(char *gateway, unsigned int length)
|
||||||
@@ -280,7 +286,7 @@ int get_gateway(char *gateway, unsigned int length)
|
|||||||
goto OUT;
|
goto OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((len = readNlSock(sock, msgBuf, msgSeq, getpid())) < 0)
|
if((len = readNlSock(sock, msgBuf)) < 0)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(error_log_handler, RLOG_LV_FATAL, module_name, "read from socket failed.");
|
MESA_handle_runtime_log(error_log_handler, RLOG_LV_FATAL, module_name, "read from socket failed.");
|
||||||
printf("====line:%d,%s\n",__LINE__,"read from socket failed.");
|
printf("====line:%d,%s\n",__LINE__,"read from socket failed.");
|
||||||
@@ -289,7 +295,8 @@ int get_gateway(char *gateway, unsigned int length)
|
|||||||
|
|
||||||
for(;NLMSG_OK(nlMsg,len);nlMsg = NLMSG_NEXT(nlMsg,len))
|
for(;NLMSG_OK(nlMsg,len);nlMsg = NLMSG_NEXT(nlMsg,len))
|
||||||
{
|
{
|
||||||
parseRoutes(nlMsg, gateway, length);
|
if(!parseRoutes(nlMsg, gateway, length))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
OUT:
|
OUT:
|
||||||
@@ -468,7 +475,7 @@ int http_check_init()
|
|||||||
MESA_load_profile_string_nodef(http_check_conf_file, "HTTP", "HTTP_CHECK_ERR_LOG_PATH", http_check_error_log_path, MAX_STR_LEN);
|
MESA_load_profile_string_nodef(http_check_conf_file, "HTTP", "HTTP_CHECK_ERR_LOG_PATH", http_check_error_log_path, MAX_STR_LEN);
|
||||||
MESA_load_profile_string_nodef(http_check_conf_file, "HTTP", "MODULE_NAME", module_name, MAX_STR_LEN);
|
MESA_load_profile_string_nodef(http_check_conf_file, "HTTP", "MODULE_NAME", module_name, MAX_STR_LEN);
|
||||||
MESA_load_profile_int_def(http_check_conf_file, "HTTP", "LOG_LEVEL", &log_level, 30);
|
MESA_load_profile_int_def(http_check_conf_file, "HTTP", "LOG_LEVEL", &log_level, 30);
|
||||||
printf("*v6*******read_ip:%s,read_port:%d\n",g_http_address, g_http_port);
|
printf("*v12*******read_ip:%s,read_port:%d\n",g_http_address, g_http_port);
|
||||||
|
|
||||||
http_check_log_handler = MESA_create_runtime_log_handle(http_check_log_path, RLOG_LV_INFO);
|
http_check_log_handler = MESA_create_runtime_log_handle(http_check_log_path, RLOG_LV_INFO);
|
||||||
error_log_handler = MESA_create_runtime_log_handle(http_check_error_log_path, log_level);
|
error_log_handler = MESA_create_runtime_log_handle(http_check_error_log_path, log_level);
|
||||||
|
|||||||
Reference in New Issue
Block a user