環境:
*********************<b></b>
Adiscon LogAnalyzer Version 3.4.3
[root@centos100 ~]# cat /etc/issue
CentOS release 5.6 (Final)
*********************
看到标題,可能有些人會不屑,答案無非是建立view,建立DBMappings。我很負責任的告訴你,不是。我這裡是修改PHP源碼的方法,來實作的。費話不多說,直接開搞
最近在搞rsyslog+loganalyzer來實作集中型日志管理,但是在安裝完之後,發現隻顯示了主機名,沒有IP,網上找了一些文章參考,要麼可以隻顯示IP,要麼隻顯示主機名,還有就是兩者同時顯示需要添加view,我在添加view的時候,發現不能搞多個字段。于是乎想到了修改資料庫,修改完資料庫發現還是不對。
添加第一個字段還算正常
<a target="_blank" href="http://blog.51cto.com/attachment/201304/115939641.jpg"></a>
添加第二個字段的時候,我驚訝的發現,FUCK,這泥瑪什麼情況
<a target="_blank" href="http://blog.51cto.com/attachment/201304/120017961.jpg"></a>
第一個字段為啥變成Array了呢?泥瑪,叫雅咩碟也不管用啊。再繼續添加,就一個一個的覆寫,我了個去。搞毛線?
本來是想修正這個BUG的,再怎麼說咱也看了幾天的PHP,以為以老夫的本事,能搞定。結果發現,實在是頭大,學習的時候MVC沒學好,直接修改view.php看來要流産。但也不能這麼就放棄。結果就想修改它本身自帶的view,發現以下
<a target="_blank" href="http://blog.51cto.com/attachment/201304/120315437.jpg"></a>
黑呀,真黑呀。黑的就代表不讓改。妹的,view.php的源碼我看不懂也就不必了,難度這個也會一樣的悲劇麼?于是就找這個在哪裡改,發現頁面還是view.php,發現裡面沒有這些view,它本身又include了一堆的php,泥瑪,看的蛋疼,越是蛋疼的時候越要蛋定。直接在linux下面使用grep找
[root@centos100 log]# grep 'Syslog Fields' ./ -r
./include/functions_config.php: 'DisplayName' =>"Syslog Fields",
找到後編譯它
<a target="_blank" href="http://blog.51cto.com/attachment/201304/121057640.jpg"></a>
添加紅色框裡的内容。
完了之後,發現還是不行,因為點到DBMappings裡面的時候,發現根本就沒這個字段,要以還要改一個檔案來實作關連。
[root@centos100 log]# grep 'MonitorWare' ./ -r
./classes/msgparsers/msgparser.eventlog.class.php: public $_ClassDescription = 'This is a parser for a special format which can be created with Adiscon Eventreporter or MonitorWare Agent.';
./include/constants_logstream.php:$dbmapping['monitorware']['DisplayName'] = "MonitorWare";
./include/functions_config.php: $mysource['ObjRef']->DBTableType = "monitorware"; // Convert to MonitorWare!
./include/constants_general.php:// --- MonitorWare InfoUnit Defines | Messagetypes
./doc/install.html: MonitorWare Line of products.</P>
./doc/install.html:LogAnalyzer supports Adiscon's MonitorWare database schema. The schema
./doc/manual.html:<a href="http://www.mwagent.com">MonitorWare Agent</a>.
./doc/windowsevent.html:<a href="http://www.mwagent.com">MonitorWare Agent</a> software. These Agents are
./doc/basics.html:For the database, tabels in either MonitorWare format or the format used by
./doc/basics.html:you set up something new, be sure the use MonitorWare schema. If you use
./doc/basics.html:that rsyslog uses MonitorWare schema by default, too. So you probably need not to
./doc/basics.html:<a href="http://www.msagent.com/">MonitorWare Agent</a>
./doc/basics.html:<a href="http://kb.monitorware.com">MonitorWare Knowledge Base</a> to aid you
結果就一個一個的看,一個一個的找,html的肯定不是,結果就被我找到了./include/constants_logstream.php
進去就發現,又是一個數組,結果新增一個即可
<a target="_blank" href="http://blog.51cto.com/attachment/201304/121510823.jpg"></a>
添加352行的内容。
<a target="_blank" href="http://blog.51cto.com/attachment/201304/122330882.jpg"></a>
發現IP和主機名都有顯示了。
當然了,做以上操作之前,肯定在要資料庫裡插入這個字段,這樣才能顯示得出來。
mysql> USE Syslog;
mysql> ALTER TABLE SystemEvents ADD FromIP VARCHAR(60) DEFAULT NULL AFTER FromHost;
修改日志的配置檔案
# vi /etc/rsyslog.conf
$template insertpl,"insert into SystemEvents (Message, Facility, FromHost, FromIP,Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%', %syslogfacility%,'%HOSTNAME%', '%fromhost-ip%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')",SQL
改完以上之後,還要添加FromIP到現有的字段裡面
<a href="http://blog.51cto.com/attachment/201304/123211576.png" target="_blank"></a>
完成後不要忘記重新開機rsyslog的服務
說明:
Adiscon LogAnalyzer Version 3.6.3已經修複添加view的時候,不能添加多個字段的BUG,本人新測可用。
3.6.3如果想同時顯示IP和主機名,要把修改的不太一樣。
本文轉自 gm100861 51CTO部落格,原文連結:http://blog.51cto.com/gm100861/1187180