nagios插件之监控RTTI返回情况(模拟坐席发起)

vi check_nrpe_rtti_search.c

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
#include <sys/select.h>

#define OK       0   
#define WARNING  1   
#define CRITICAL 2   
#define UNKNOWN  3   

//#define LEN 1023
#define LEN 40000

#define HIS_PORT 80
//#define HIS_IPADDR "114.66.80.122"
#define HIS_IPADDR "114.66.80.126"

//cookie
char Cookie_JSESSIONID[LEN];

//token
char token[30];

//safe sleep
void safe_sleep(unsigned int sec) {
        while(sec=sleep(sec));
}

int get_url(char url_request[LEN],char url_response[LEN]) {
	int ret,i;
//	char readbuf[40960];
	char readbuf[LEN];

        int mark=0;
        char *p,*str;

	fd_set   rfds;
	struct timeval  time;

	int sd;
	struct sockaddr_in his_end;

//	printf("------------------------------\n");
//	printf("%s\n",url_request);

	sd=socket(AF_INET,SOCK_STREAM,0);
////	printf("------------------------sd=%d\n",sd);
	if(sd==-1) {
		fprintf(stderr,"socket error.\n");
		return -1;
	}

	his_end.sin_family=AF_INET;

	if(strstr(url_request,"CallCenter/cngw")) {
		his_end.sin_port=htons(8199);
		his_end.sin_addr.s_addr=inet_addr("114.66.80.170");
	}
	else {
		his_end.sin_port=htons(HIS_PORT);
		his_end.sin_addr.s_addr=inet_addr(HIS_IPADDR);
	}

	ret=connect(sd,(struct sockaddr *)&his_end,sizeof(his_end));
	if(ret==-1) {
		perror("connect()");
		return -1;
	}

	//send data
	ret=write(sd,url_request,strlen(url_request));
	if(ret<0) {
		perror("write() error");
		return -1;
	}
	else {
	//	printf("client write %d bytes .\n",ret);
	}


        while(1) {
		memset(readbuf,0,LEN);

		FD_ZERO(&rfds);
		FD_SET(sd,&rfds);

                time.tv_sec=1;
                time.tv_usec=0;

		ret=select(sd+1,&rfds,NULL,NULL,&time);
	//	printf("select ret=%d\n",ret);
                if(ret<0) {
                	fprintf(stderr,"select() error,ret=%d.\n",ret);
                	return -1;
		//	continue;
                }
		else if(ret>0) {
                        ret=read(sd,readbuf,LEN);
                        if(ret<0){
				fprintf(stderr,"read() error.\n");
				return -1;
				
                               // close(sd);
                           ////     return -1;
                        }
			else if(ret>0) {

	                   ////     printf("readbuf start--------------------\n");
             	//	printf("%s\n",readbuf);
		//	strcpy(url_response,readbuf);
				strcat(url_response,readbuf);
       			////	printf("readbuf end--------------------\n");

			}
			else {
				break;
			}
		//	printf("------------------test---------------------\n");
			/*
                       // for(p=strtok(readbuf,"^M$\r\n");p;p=strtok(NULL,"^M$\r\n")) {
                        for(p=strtok(readbuf,"\r\n");p;p=strtok(NULL,"\r\n")) {
                                str=p;
                                mark++;

                               // if(mark==13)
                                if(mark==7)
                                        break;

                        }
                      //  printf("%s\n",str);
			strcpy(url_response,str);
		      */

		//	break;
	//	}

                }
		else {
                      break;
		}
	//	sleep(2);
	}



	ret=close(sd);
	if(ret==-1) {
		fprintf(stderr,"close() error.\n");
		return -1;
	}

	return 0;
}

int parse_url_get_session(char get_url_respons[LEN]) {
	int ret;
	int mark=0;
	char *p,*str;
	char readbuf[LEN];
	char readbuf_cookie[LEN];

	strcpy(readbuf,get_url_respons);

	/*
	for(p=strtok(readbuf,"\r\n");p;p=strtok(NULL,"\r\n")) {
       		str=p;
               	mark++;
		*/

		if(str=strstr(readbuf,"Set-Cookie: JSESSIONID=")) {
//			printf("1111111111111111111111\n");
			ret=sscanf(str,"Set-Cookie: JSESSIONID=%32s;",Cookie_JSESSIONID);
//			printf("ret=%d\n",ret);

		//	sscanf(str,"Set-Cookie: JSESSIONID=%[^;]",JSESSIONID);
		//	for(p=strtok(get_url_respons,"=;");p;p=strtok(NULL,"=;")) {

		}

		/*
               // if(mark==13)
             	if(mark==7) {
			strcpy(readbuf_cookie,str);

			for(p=strtok(get_url_respons,"=;");p;p=strtok(NULL,"=;")) {
				
			}

			break;
		}
		*/
//	}

////	printf("JSESSIONID=%s\n",JSESSIONID);

/*	
//	if(strstr(get_url_respons,"JSESSIONID")) {

		for(p=strtok(get_url_respons,"=;");p;p=strtok(NULL,"=;")) {
		//	printf("----------%s\n",get_url_respons);

			str=p;

			mark++;
			if(mark==6) {
				strcpy(JSESSIONID,str);
				break;
			}

			printf("-----------------------\n");
		}

		printf("JSESSIONID=%s\n",JSESSIONID);
//	}
	*/


//

	return 0;
}

int search_token(char *buffer,char *token) {
	int ret;
        int num=0;
	char *str;
	char tmp_str[LEN];
	char separator[]="\"";

	strcpy(tmp_str,buffer);

//	printf("find_the\n");

	/*
	for (str=strtok(tmp_str,separator);str!=NULL;str=strtok(NULL,separator)) {
       		if (strcmp(word,str)==0) {
               		num++; 
		} 
        }
	*/

	str=strstr(buffer,"token=");

	ret=sscanf(str,"token=%8s",token);
	if(ret==-1) {
		fprintf(stderr,"search_token() sscanf error.\n");
		return -1;
	}

        return 0;
}

int search_word_count(char *buffer,char *word) {
        int num=0;
	char *str;
	char tmp_str[LEN];
	char separator[]=":\{:\'";

	strcpy(tmp_str,buffer);

//	printf("find_the\n");

	for (str=strtok(tmp_str,separator);str!=NULL;str=strtok(NULL,separator)) {
       		if (strcmp(word,str)==0) {
               		num++; 
		} 
        }

        return num;
}

int main(int argc, char *argv[]) {
	int ret,i;

	int exitstatus=OK;
	char *exit_status[4]={"OK","WARNING","CRITICAL","UNKNOWN"}; 

	char status_information[LEN];
	char performance_data[LEN];

	//------------------------------------------------------------------------------
	//wss login.action
	char http_url_login_action_request[LEN];
	char http_url_login_action_response[LEN];

	memset(http_url_login_action_request,0,LEN);
	memset(http_url_login_action_response,0,LEN);

	strcat(http_url_login_action_request,"POST /csp/login/login.action HTTP/1.1\n");
	strcat(http_url_login_action_request,"Accept: image/jpeg, image/gif, image/pjpeg, */*\n");
	strcat(http_url_login_action_request,"Referer: http://114.66.80.122/csp/login/init.action\n");
	strcat(http_url_login_action_request,"Accept-Language: zh-CN\n");
	strcat(http_url_login_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_login_action_request,"Content-Type: application/x-www-form-urlencoded\n");
	strcat(http_url_login_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_login_action_request,"Host: 114.66.80.XXX\n");
	strcat(http_url_login_action_request,"Content-Length: 31\n");
	strcat(http_url_login_action_request,"Connection: Keep-Alive\n");
	strcat(http_url_login_action_request,"Cache-Control: no-cache\n");
	strcat(http_url_login_action_request,"Cookie: JSESSIONID=337E3862BB20E7B21C298CB923061A07\n\r\n");
	strcat(http_url_login_action_request,"username=XXXXXX&password=XXXXXX");

//	printf("login.action request=%s",http_url_login_action_request);
//	printf("\n----------------------------------------------------------\n");

	//get_url
	ret=get_url(http_url_login_action_request,http_url_login_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("login.action response=%s\n",http_url_login_action_response);
//	printf("\n----------------------------------------------------------\n");

	//parse_url_get_session
	ret=parse_url_get_session(http_url_login_action_response);
	if(ret!=0) {
		fprintf(stderr,"parse_url_get_session() error.\n");
	}
//	printf("JSESSIONID=%s\n",Cookie_JSESSIONID);
//	printf("\n----------------------------------------------------------\n");
//	printf("\n----------------------------------------------------------\n");

	//------------------------------------------------------------------------------
	//initSession.action -- first
	char http_url_initSession_action_request[LEN];
	char http_url_initSession_action_response[LEN];

	memset(http_url_initSession_action_request,0,LEN);
	memset(http_url_initSession_action_response,0,LEN);

	strcat(http_url_initSession_action_request,"GET /csp/csp/initSession.action HTTP/1.1\n");
	strcat(http_url_initSession_action_request,"Accept: image/jpeg, image/gif, image/pjpeg, */*\n");
	strcat(http_url_initSession_action_request,"Referer: http://114.66.80.122/csp/login/init.action\n");
	strcat(http_url_initSession_action_request,"Accept-Language: zh-CN\n");
	strcat(http_url_initSession_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2)\n");
	strcat(http_url_initSession_action_request,"UA-CPU: AMD64\n");
	strcat(http_url_initSession_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_initSession_action_request,"Host: 114.66.80.122\n");
	strcat(http_url_initSession_action_request,"Connection: Keep-Alive\n");
	strcat(http_url_initSession_action_request,"Cache-Control: no-cache\n");
//	strcat(http_url_initSession_action_request,"Cookie: JSESSIONID=B19DEFB41CCD39058A036E618F5B709B\n\r\n");

	strcat(http_url_initSession_action_request,"Cookie: JSESSIONID=");
	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_initSession_action_request,Cookie_JSESSIONID);

//	printf("initSession.action request=%s",http_url_initSession_action_request);
//	printf("*************************************************************\n");

	//get_url
	ret=get_url(http_url_initSession_action_request,http_url_initSession_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("initSession.action response=%s\n",http_url_initSession_action_response);
//	printf("\n----------------------------------------------------------\n");


	//------------------------------------------------------------------------------
	//j_security_check
	char http_url_j_security_check_request[LEN];
	char http_url_j_security_check_response[LEN];

	memset(http_url_j_security_check_request,0,LEN);
	memset(http_url_j_security_check_response,0,LEN);

	strcat(http_url_j_security_check_request,"GET /csp/j_security_check?j_username=CU-TSP&j_password=123456 HTTP/1.1\n");
	strcat(http_url_j_security_check_request,"Accept: image/jpeg, image/gif, image/pjpeg, */*\n");
	strcat(http_url_j_security_check_request,"Referer: http://114.66.80.122/csp/login/init.action\n");
	strcat(http_url_j_security_check_request,"Accept-Language: zh-CN\n");
	strcat(http_url_j_security_check_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2)\n");
	strcat(http_url_j_security_check_request,"UA-CPU: AMD64\n");
	strcat(http_url_j_security_check_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_j_security_check_request,"Host: 114.66.80.122\n");
	strcat(http_url_j_security_check_request,"Connection: Keep-Alive\n");
	strcat(http_url_j_security_check_request,"Cache-Control: no-cache\n");

	strcat(http_url_j_security_check_request,"Cookie: JSESSIONID=");
////	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_j_security_check_request,Cookie_JSESSIONID);

//	printf("j_security_check request=%s",http_url_j_security_check_request);
//	printf("*************************************************************\n");

	//get_url
	ret=get_url(http_url_j_security_check_request,http_url_j_security_check_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("j_security_check response=%s\n",http_url_j_security_check_response);
//	printf("\n----------------------------------------------------------\n");


	//------------------------------------------------------------------------------
	//initSession.action -- second
	memset(http_url_initSession_action_request,0,LEN);
	memset(http_url_initSession_action_response,0,LEN);

	strcat(http_url_initSession_action_request,"GET /csp/csp/initSession.action HTTP/1.1\n");
	strcat(http_url_initSession_action_request,"Accept: image/jpeg, image/gif, image/pjpeg, */*\n");
	strcat(http_url_initSession_action_request,"Referer: http://114.66.80.122/csp/login/init.action\n");
	strcat(http_url_initSession_action_request,"Accept-Language: zh-CN\n");
	strcat(http_url_initSession_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2)\n");
	strcat(http_url_initSession_action_request,"UA-CPU: AMD64\n");
	strcat(http_url_initSession_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_initSession_action_request,"Host: 114.66.80.122\n");
	strcat(http_url_initSession_action_request,"Connection: Keep-Alive\n");
	strcat(http_url_initSession_action_request,"Cache-Control: no-cache\n");
//	strcat(http_url_initSession_action_request,"Cookie: JSESSIONID=B19DEFB41CCD39058A036E618F5B709B\n\r\n");

	strcat(http_url_initSession_action_request,"Cookie: JSESSIONID=");
////	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_initSession_action_request,Cookie_JSESSIONID);

//	printf("initSession.action request=%s",http_url_initSession_action_request);
//	printf("*************************************************************\n");

	//get_url
	ret=get_url(http_url_initSession_action_request,http_url_initSession_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("initSession.action response=%s\n",http_url_initSession_action_response);
//	printf("\n----------------------------------------------------------\n");

	//---------------------------------------------------------------------------------
	//rtti serviceRequest_viewService.action
/*
	char http_url_rtti_serviceRequest_viewService_action_request[LEN];
	char http_url_rtti_serviceRequest_viewService_action_response[LEN];

	memset(http_url_rtti_serviceRequest_viewService_action_request,0,LEN);
	memset(http_url_rtti_serviceRequest_viewService_action_response,0,LEN);

	strcat(http_url_rtti_serviceRequest_viewService_action_request,"GET /csp/serviceRequest_viewService.action?srId=&takeService=false&dojo.preventCache=1385293169028 HTTP/1.1\n");
*/
//	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Accept: */*\n");
/*	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Accept-Language: zh-cn\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,"x-requested-with: XMLHttpRequest\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Content-Type: application/x-www-form-urlencoded\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Host: 114.66.80.122\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Connection: Keep-Alive\n");

	strcat(http_url_rtti_serviceRequest_viewService_action_request,"Cookie: JSESSIONID=");
////	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_rtti_serviceRequest_viewService_action_request,Cookie_JSESSIONID);

	printf("serviceRequest_viewService.action request=%s",http_url_rtti_serviceRequest_viewService_action_request);
	printf("*************************************************************\n");

	//get_url
	ret=get_url(http_url_rtti_serviceRequest_viewService_action_request,http_url_rtti_serviceRequest_viewService_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
	printf("serviceRequest_viewService.action response=%s\n",http_url_rtti_serviceRequest_viewService_action_response);
	printf("\n----------------------------------------------------------\n");	
*/


	//---------------------------------------------------------------------------------
	//rtti editUserSettings.action
/*
	char http_url_rtti_editUserSettings_action_request[LEN];
	char http_url_rtti_editUserSettings_action_response[LEN];

	memset(http_url_rtti_editUserSettings_action_request,0,LEN);
	memset(http_url_rtti_editUserSettings_action_response,0,LEN);

	strcat(http_url_rtti_editUserSettings_action_request,"GET /csp/csp/editUserSettings.action?dojo.preventCache=1385293169340 HTTP/1.1\n");
*/
//	strcat(http_url_rtti_editUserSettings_action_request,"Accept: */*\n");
/*	strcat(http_url_rtti_editUserSettings_action_request,"Accept-Language: zh-cn\n");
	strcat(http_url_rtti_editUserSettings_action_request,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_editUserSettings_action_request,"x-requested-with: XMLHttpRequest\n");
	strcat(http_url_rtti_editUserSettings_action_request,"Content-Type: application/x-www-form-urlencoded\n");
	strcat(http_url_rtti_editUserSettings_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_editUserSettings_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_editUserSettings_action_request,"Host: 114.66.80.122\n");
	strcat(http_url_rtti_editUserSettings_action_request,"Connection: Keep-Alive\n");

	strcat(http_url_rtti_editUserSettings_action_request,"Cookie: JSESSIONID=");
////	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_rtti_editUserSettings_action_request,Cookie_JSESSIONID);

	printf("editUserSettings.action request=%s",http_url_rtti_editUserSettings_action_request);
	printf("*************************************************************\n");

	//get_url
	ret=get_url(http_url_rtti_editUserSettings_action_request,http_url_rtti_editUserSettings_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
	printf("editUserSettings.action response=%s\n",http_url_rtti_editUserSettings_action_response);
	printf("\n----------------------------------------------------------\n");	
*/

	
	//---------------------------------------------------------------------------------
	//rtti trafficFlowUrl.action
	char http_url_rtti_trafficFlowUrl_action_request[LEN];
	char http_url_rtti_trafficFlowUrl_action_response[LEN];

	memset(http_url_rtti_trafficFlowUrl_action_request,0,LEN);
	memset(http_url_rtti_trafficFlowUrl_action_response,0,LEN);

	strcat(http_url_rtti_trafficFlowUrl_action_request,"POST /csp/trafficFlowUrl.action HTTP/1.1\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Accept: */*\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Accept-Language: zh-cn\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"x-requested-with: XMLHttpRequest\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Content-Type: application/x-www-form-urlencoded\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Host: 114.66.80.122\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Content-Length: 45\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Connection: Keep-Alive\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,"Cache-Control: no-cache\n");

	strcat(http_url_rtti_trafficFlowUrl_action_request,"Cookie: JSESSIONID=");
////	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_rtti_trafficFlowUrl_action_request,Cookie_JSESSIONID);

	strcat(http_url_rtti_trafficFlowUrl_action_request,"requestId=-10&dojo.preventCache=1396785270395\n");

//	printf("rtti trafficFlowUrl.action request=%s",http_url_rtti_trafficFlowUrl_action_request);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_trafficFlowUrl_action_request,http_url_rtti_trafficFlowUrl_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti trafficFlowUrl.action response=%s\n",http_url_rtti_trafficFlowUrl_action_response);

	//search token
	ret=search_token(http_url_rtti_trafficFlowUrl_action_response,token);

//	printf("token=%s\n",token);
//	sleep(2);
//	printf("\n----------------------------------------------------------\n");
	
	

	//---------------------------------------------------------------------------------
	//rtti trafficEventUrl.action
	char http_url_rtti_trafficEventUrl_action_request[LEN];
	char http_url_rtti_trafficEventUrl_action_response[LEN];

	memset(http_url_rtti_trafficEventUrl_action_request,0,LEN);
	memset(http_url_rtti_trafficEventUrl_action_response,0,LEN);
	
	strcat(http_url_rtti_trafficEventUrl_action_request,"POST /csp/trafficEventUrl.action HTTP/1.1\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Accept: */*\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Accept-Language: zh-cn\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"x-requested-with: XMLHttpRequest\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Content-Type: application/x-www-form-urlencoded\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Host: 114.66.80.122\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Content-Length: 45\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Connection: Keep-Alive\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,"Cache-Control: no-cache\n");

	strcat(http_url_rtti_trafficEventUrl_action_request,"Cookie: JSESSIONID=");
////	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_rtti_trafficEventUrl_action_request,Cookie_JSESSIONID);

	strcat(http_url_rtti_trafficEventUrl_action_request,"requestId=-10&dojo.preventCache=1396785270395");
	


//	printf("rtti trafficEventUrl.action request=%s",http_url_rtti_trafficEventUrl_action_request);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_trafficEventUrl_action_request,http_url_rtti_trafficEventUrl_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti trafficEventUrl.action response=%s\n",http_url_rtti_trafficEventUrl_action_response);
/*
	//search token
	ret=search_token(http_url_rtti_trafficEventUrl_action_response,token);

	printf("token=%s\n",token);
	printf("\n----------------------------------------------------------\n");
*/
	

	//---------------------------------------------------------------------------------

	//
	//
	//--------------------------------------------------------------------
	//rtti CallCenter/cngw?token
	char http_url_rtti_CallCenter_cngw_request[LEN];
	char http_url_rtti_CallCenter_cngw_response[LEN];

	memset(http_url_rtti_CallCenter_cngw_request,0,LEN);
	memset(http_url_rtti_CallCenter_cngw_response,0,LEN);

	strcat(http_url_rtti_CallCenter_cngw_request,"GET /CallCenter/cngw?token=");
	strcat(http_url_rtti_CallCenter_cngw_request,token);
	strcat(http_url_rtti_CallCenter_cngw_request,"&REQUEST=GetMap&WIDTH=256&HEIGHT=256&FORMAT=image%2Fpng&BBOX=12836529.120512001,4852833.7110016,12914800.637465601,4931105.2279552 HTTP/1.1\n");//12836529.120512001,4852833.7110016,12914800.637465601,4931105.2279552

//	strcat(http_url_rtti_CallCenter_cngw_request,"&REQUEST=GetMap&WIDTH=256&HEIGHT=256&FORMAT=image%2Fpng&BBOX=12914800.6374656,4774562.194048,12993072.1544192,4852833.711001599 HTTP/1.1\n");

	strcat(http_url_rtti_CallCenter_cngw_request,"Accept: */*\n");
	strcat(http_url_rtti_CallCenter_cngw_request,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_CallCenter_cngw_request,"Accept-Language: zh-CN\n");
	strcat(http_url_rtti_CallCenter_cngw_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_CallCenter_cngw_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_CallCenter_cngw_request,"Host: 114.66.80.170:8199\n");
	strcat(http_url_rtti_CallCenter_cngw_request,"Connection: Keep-Alive\n\r\n");
	

//	printf("rtti CallCenter/cngw request=%s",http_url_rtti_CallCenter_cngw_request);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_CallCenter_cngw_request,http_url_rtti_CallCenter_cngw_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti CallCenter/cngw response=%s\n",http_url_rtti_CallCenter_cngw_response);
//	printf("\n----------------------------------------------------------\n");


	//--------------------------------------------------------------------
	//rtti CallCenter/cngw?token
	char http_url_rtti_CallCenter_cngw_request_2[LEN];
	char http_url_rtti_CallCenter_cngw_response_2[LEN];

	memset(http_url_rtti_CallCenter_cngw_request_2,0,LEN);
	memset(http_url_rtti_CallCenter_cngw_response_2,0,LEN);

	strcat(http_url_rtti_CallCenter_cngw_request_2,"GET /CallCenter/cngw?token=");
	strcat(http_url_rtti_CallCenter_cngw_request_2,token);
	strcat(http_url_rtti_CallCenter_cngw_request_2,"&REQUEST=GetMap&WIDTH=256&HEIGHT=256&FORMAT=image%2Fpng&BBOX=12836529.120512001,4774562.194048,12914800.637465601,4852833.711001599 HTTP/1.1\n");//12836529.120512001,4774562.194048,12914800.637465601,4852833.711001599
	

	strcat(http_url_rtti_CallCenter_cngw_request_2,"Accept: */*\n");
	strcat(http_url_rtti_CallCenter_cngw_request_2,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_CallCenter_cngw_request_2,"Accept-Language: zh-CN\n");
	strcat(http_url_rtti_CallCenter_cngw_request_2,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_CallCenter_cngw_request_2,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_CallCenter_cngw_request_2,"Host: 114.66.80.170:8199\n");
	strcat(http_url_rtti_CallCenter_cngw_request_2,"Connection: Keep-Alive\n\r\n");
	
//	printf("rtti CallCenter/cngw request_2=%s",http_url_rtti_CallCenter_cngw_request_2);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_CallCenter_cngw_request_2,http_url_rtti_CallCenter_cngw_response_2);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti CallCenter/cngw response_2=%s\n",http_url_rtti_CallCenter_cngw_response_2);
//	printf("\n----------------------------------------------------------\n");


	//--------------------------------------------------------------------
	//rtti CallCenter/cngw?token
	char http_url_rtti_CallCenter_cngw_request_3[LEN];
	char http_url_rtti_CallCenter_cngw_response_3[LEN];

	memset(http_url_rtti_CallCenter_cngw_request_3,0,LEN);
	memset(http_url_rtti_CallCenter_cngw_response_3,0,LEN);

	strcat(http_url_rtti_CallCenter_cngw_request_3,"GET /CallCenter/cngw?token=");
	strcat(http_url_rtti_CallCenter_cngw_request_3,token);
	strcat(http_url_rtti_CallCenter_cngw_request_3,"&REQUEST=GetMap&WIDTH=256&HEIGHT=256&FORMAT=image%2Fpng&BBOX=12914800.6374656,4852833.7110016,12993072.1544192,4931105.2279552 HTTP/1.1\n");//12914800.6374656,4852833.7110016,12993072.1544192,4931105.2279552
	strcat(http_url_rtti_CallCenter_cngw_request_3,"Accept: */*\n");
	strcat(http_url_rtti_CallCenter_cngw_request_3,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_CallCenter_cngw_request_3,"Accept-Language: zh-CN\n");
	strcat(http_url_rtti_CallCenter_cngw_request_3,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_CallCenter_cngw_request_3,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_CallCenter_cngw_request_3,"Host: 114.66.80.170:8199\n");
	strcat(http_url_rtti_CallCenter_cngw_request_3,"Connection: Keep-Alive\n\r\n");
	

//	printf("rtti CallCenter/cngw request_3=%s",http_url_rtti_CallCenter_cngw_request_3);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_CallCenter_cngw_request_3,http_url_rtti_CallCenter_cngw_response_3);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti CallCenter/cngw response_3=%s\n",http_url_rtti_CallCenter_cngw_response_3);
//	printf("\n----------------------------------------------------------\n");

		//--------------------------------------------------------------------
	//rtti CallCenter/cngw?token
	char http_url_rtti_CallCenter_cngw_request_4[LEN];
	char http_url_rtti_CallCenter_cngw_response_4[LEN];

	memset(http_url_rtti_CallCenter_cngw_request_4,0,LEN);
	memset(http_url_rtti_CallCenter_cngw_response_4,0,LEN);

	strcat(http_url_rtti_CallCenter_cngw_request_4,"GET /CallCenter/cngw?token=");
	strcat(http_url_rtti_CallCenter_cngw_request_4,token);
	strcat(http_url_rtti_CallCenter_cngw_request_4,"&REQUEST=GetMap&WIDTH=256&HEIGHT=256&FORMAT=image%2Fpng&BBOX=12914800.6374656,4774562.194048,12993072.1544192,4852833.711001599 HTTP/1.1\n");//12914800.6374656,4774562.194048,12993072.1544192,4852833.711001599


	strcat(http_url_rtti_CallCenter_cngw_request_4,"Accept: */*\n");
	strcat(http_url_rtti_CallCenter_cngw_request_4,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_CallCenter_cngw_request_4,"Accept-Language: zh-CN\n");
	strcat(http_url_rtti_CallCenter_cngw_request_4,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_CallCenter_cngw_request_4,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_CallCenter_cngw_request_4,"Host: 114.66.80.170:8199\n");
	strcat(http_url_rtti_CallCenter_cngw_request_4,"Connection: Keep-Alive\n\r\n");
	

//	printf("rtti CallCenter/cngw request_4=%s",http_url_rtti_CallCenter_cngw_request_4);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_CallCenter_cngw_request_4,http_url_rtti_CallCenter_cngw_response_4);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti CallCenter/cngw response_4=%s\n",http_url_rtti_CallCenter_cngw_response_4);
//	printf("\n------------------------------------\n");

	//--------------------------------------------------------------------
	//rtti CallCenter/cngw?token
	char http_url_rtti_CallCenter_cngw_request_5[LEN];
	char http_url_rtti_CallCenter_cngw_response_5[LEN];

	memset(http_url_rtti_CallCenter_cngw_request_5,0,LEN);
	memset(http_url_rtti_CallCenter_cngw_response_5,0,LEN);

	strcat(http_url_rtti_CallCenter_cngw_request_5,"GET /CallCenter/cngw?token=");
	strcat(http_url_rtti_CallCenter_cngw_request_5,token);
	strcat(http_url_rtti_CallCenter_cngw_request_5,"&REQUEST=GetMap&WIDTH=256&HEIGHT=256&FORMAT=image%2Fpng&BBOX=12993072.154419202,4852833.7110016,13071343.671372802,4931105.2279552 HTTP/1.1\n");//12993072.154419202,4852833.7110016,13071343.671372802,4931105.2279552


	strcat(http_url_rtti_CallCenter_cngw_request_5,"Accept: */*\n");
	strcat(http_url_rtti_CallCenter_cngw_request_5,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_CallCenter_cngw_request_5,"Accept-Language: zh-CN\n");
	strcat(http_url_rtti_CallCenter_cngw_request_5,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_CallCenter_cngw_request_5,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_CallCenter_cngw_request_5,"Host: 114.66.80.170:8199\n");
	strcat(http_url_rtti_CallCenter_cngw_request_5,"Connection: Keep-Alive\n\r\n");
	

//	printf("rtti CallCenter/cngw request_5=%s",http_url_rtti_CallCenter_cngw_request_5);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_CallCenter_cngw_request_5,http_url_rtti_CallCenter_cngw_response_5);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti CallCenter/cngw response_5=%s\n",http_url_rtti_CallCenter_cngw_response_5);
//	printf("\n------------------------------------\n");


	//--------------------------------------------------------------------
	//rtti CallCenter/cngw?token
	char http_url_rtti_CallCenter_cngw_request_6[LEN];
	char http_url_rtti_CallCenter_cngw_response_6[LEN];

	memset(http_url_rtti_CallCenter_cngw_request_6,0,LEN);
	memset(http_url_rtti_CallCenter_cngw_response_6,0,LEN);

	strcat(http_url_rtti_CallCenter_cngw_request_6,"GET /CallCenter/cngw?token=");
	strcat(http_url_rtti_CallCenter_cngw_request_6,token);
	strcat(http_url_rtti_CallCenter_cngw_request_6,"&REQUEST=GetMap&WIDTH=256&HEIGHT=256&FORMAT=image%2Fpng&BBOX=12993072.154419202,4774562.194048,13071343.671372802,4852833.711001599 HTTP/1.1\n");//12993072.154419202,4774562.194048,13071343.671372802,4852833.711001599


	strcat(http_url_rtti_CallCenter_cngw_request_6,"Accept: */*\n");
	strcat(http_url_rtti_CallCenter_cngw_request_6,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_CallCenter_cngw_request_6,"Accept-Language: zh-CN\n");
	strcat(http_url_rtti_CallCenter_cngw_request_6,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_CallCenter_cngw_request_6,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_CallCenter_cngw_request_6,"Host: 114.66.80.170:8199\n");
	strcat(http_url_rtti_CallCenter_cngw_request_6,"Connection: Keep-Alive\n\r\n");
	

//	printf("rtti CallCenter/cngw request_6=%s",http_url_rtti_CallCenter_cngw_request_6);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_CallCenter_cngw_request_6,http_url_rtti_CallCenter_cngw_response_6);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti CallCenter/cngw response_6=%s\n",http_url_rtti_CallCenter_cngw_response_6);
//	printf("\n------------------------------------\n");

	//------------------------------------------------------------------------------
	//rtti trafficEvents.action
	char http_url_rtti_trafficEvents_action_request[LEN];
	char http_url_rtti_trafficEvents_action_response[LEN];

	memset(http_url_rtti_trafficEvents_action_request,0,LEN);
	memset(http_url_rtti_trafficEvents_action_response,0,LEN);

	strcat(http_url_rtti_trafficEvents_action_request,"POST /csp/trafficEvents.action HTTP/1.1\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Accept: */*\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Accept-Language: zh-cn\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Referer: http://114.66.80.122/csp/csp/initSession.action\n");
	strcat(http_url_rtti_trafficEvents_action_request,"x-requested-with: XMLHttpRequest\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Content-Type: application/x-www-form-urlencoded\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Accept-Encoding: gzip, deflate\n");
	strcat(http_url_rtti_trafficEvents_action_request,"User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727)\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Host: 114.66.80.122\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Content-Length: 192\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Connection: Keep-Alive\n");
	strcat(http_url_rtti_trafficEvents_action_request,"Cache-Control: no-cache\n");

	strcat(http_url_rtti_trafficEvents_action_request,"Cookie: JSESSIONID=");
////	strcat(Cookie_JSESSIONID,"\n\r\n");
	strcat(http_url_rtti_trafficEvents_action_request,Cookie_JSESSIONID);

	strcat(http_url_rtti_trafficEvents_action_request,"eventUrl=http%3A%2F%2F114.66.80.170%3A8199%2FCallCenter%2Fcngw%3Ftoken%3D");

	strcat(http_url_rtti_trafficEvents_action_request,token);

	strcat(http_url_rtti_trafficEvents_action_request,"%26mod%3Devt%26BBOX%3D40.42033%2C115.75607%2C39.51308%2C117.03872&requestId=-10&dojo.preventCache=1396785274046\n");
	
//	printf("rtti trafficEvents_action request=%s",http_url_rtti_trafficEvents_action_request);
//	printf("-----------------------\n");

	//get_url
	ret=get_url(http_url_rtti_trafficEvents_action_request,http_url_rtti_trafficEvents_action_response);
	if(ret!=0) {
		printf("get_url ret=%d\n",ret);
		fprintf(stderr,"get_url() error.\n");
	}
//	printf("rtti trafficEvents response=%s\n",http_url_rtti_trafficEvents_action_response);
//	printf("\n----------------------------------------------------------\n");
	
	int color_sum=0;
	color_sum=search_word_count(http_url_rtti_trafficEvents_action_response,"color");
	if(color_sum<0) {
		fprintf(stderr,"search_word_count() color error.\n");
		return -1;
	}
//	printf("color_sum=%d\n",color_sum);

	if(color_sum<8) {
//		printf("rtti search ok, sec_sum=0\n");
		exitstatus=CRITICAL;

		sprintf(status_information,"RTTI Traffic Color_num=%d",color_sum);

		sprintf(performance_data,"Color_num=%d;;;;",color_sum);
	}
	else if(color_sum>=8) {
//		printf("rtti search warning, sec_sum=%d\n",sec_sum);
		exitstatus=OK;

		sprintf(status_information,"RTTI Traffic Color_num=%d",color_sum);

		sprintf(performance_data,"Color_num=%d;;;;",color_sum);
	}

	printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data);

	return exitstatus;
}

你可能感兴趣的:(nagios插件之监控RTTI返回情况(模拟坐席发起))