为了解决中文报警信息乱码的问题,首先想到页面编码,于是做了两个尝试。
1在apache配置文件中指定编码为utf-8
vim /usr/local/apache2/conf/httpd.conf 加入 AddDefaultCharset utf-8
当Apache不指定defaultcharset的时候,页面编码由页面自己的meta标签指定。
当Apache指定的时候,将忽略页面中的meta标签指定的编码
重启apache和nagios,nagios虽然页面可以显示中文,但仍然无法处理带有中文输出的报警信息
2在最新的nagios-3.4.1的所有c源代码中查找着两行,
如果有就在这两行下面增加:
http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n");
结果跟上面一样。
3在py脚本上找问题,不过似乎没问题,因为输出的就是utf-8的编码.
4发现了一个中文版nagios的开源项目,http://nagios-cn.sourceforge.net/。对应的nagios版本是3.2.3.经过测试。发现这个版本的报警信息不会乱码。邮件联系作者田朝阳。在他的提醒下,比对了nagios3.1.1nagios3.2.3 nagios—cn3.2.3 .
meld-1.6.1是一个很强大代码比对工具,可以同时比对三个文件。
最后在源代码/cgi/cgiutils.c中/*escapes a string used in HTML */ 和 /*escape string for html form usage */两处增加了(/*for simplicity, all other chars represented by their numeric value */前)
(这个地方贴代码排版混乱,就截图了)
对中文进行了处理,测试后不会乱码,并应用到监控机上,重新编译,问题解决
5nagios默认只显示前8KB的报警信息。
所以要修改两个定义
#define MAX_PLUGIN_OUTPUT_LENGTH /* max length of plugin output (including perf data) */
in源代码/include/nagios.h
#define MAX_EXTERNAL_COMMAND_LENGTH /* max length of an external command */
in源代码/include/common.h
并重新编译
6nrpe默认只传输1024B的信息。
它定义在
#define MAX_PACKETBUFFER_LENGTH /* max amount of data we'll send in one query/response */
in源代码/include/common.h
客户端重新编译后 ,重启nrpe。监控机17上运行nrpe脚本去抓数据。
查看客户端日志,出错。
Error: Request packet had invalid CRC32. Nov 30 11:31:54 localhost nrpe[32663]: Client request was invalid, bailing out...
将#defineMAX_PACKETBUFFER_LENGTH改回默认,再重新编译,就正常了,囧~
尚待解决
安装nagios:
http://ixdba.blog.51cto.com/2895551/752314
/***** UTF-8 MultiByte *****/
// 2 Byte charactor
else if( ( (unsigned char)input[x] >= 0xC0 && (unsigned char)input[x] <= 0xDF ) && ( (unsigned char)input[x+1] >= 0x80 && (unsigned char)input[x+1] <= 0xBF ) ){
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x];
}
// 3 Byte charactor(BOM) : 0xEF 0xBB 0xBF
else if ( ( (unsigned char)input[x] == 0xEF ) && ( (unsigned char)input[x+1] == 0xBB ) && ( (unsigned char)input[x+2] == 0xBF ) ){
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x];
}
// 3 Byte charactor
else if ( ( (unsigned char)input[x] >= 0xE0 ) && ( (unsigned char)input[x] <= 0xEF ) && ( (unsigned char)input[x+1] >= 0x80 ) && ( (unsigned char)input[x+1] <= 0xBF ) && ( (unsigned char)input[x+2] >= 0x80 ) && ( (unsigned char)input[x+2] <= 0xBF ) ){
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x];
}
// 4 Byte charactor
else if ( ( (unsigned char)input[x] >= 0xF0 ) && ( (unsigned char)input[x] <= 0xF7 ) && ( (unsigned char)input[x+1] >= 0x80 ) && ( (unsigned char)input[x+1] <= 0xBF ) && ( (unsigned char)input[x+2] >= 0x80 ) && ( (unsigned char)input[x+2] <= 0xBF ) && ( (unsigned char)input[x+3] >= 0x80 ) && ( (unsigned char)input[x+3] <= 0xBF ) ){
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x++];
encoded_html_string[y++]=input[x];
}
/* for simplicity, all other chars represented by their numeric value */