Welcome 微信登录

首页 / 操作系统 / Linux / 关于Linux中 syslog-ng 如何在转发时修改其facility以及level

国内关于Syslog-ng的内容比较少,就是找到了也都是些许的只言片语,或者都仅仅是一些简简单单的配置facility或则和level以及destination等。这两天碰到一个问题,就是在日志转发时,需要更改收到的日志的facility和level,结果中文文档几乎木有,英文的文档倒是碰到一些,兴奋之余,一打开傻眼了。。。好几个都是问how to change the facility and level的,然后在balabit中看到回复如下: "Simply because we"re not there yet and because I didn"t feel it that important when we implemented the rewrite functionality."。。。原来还木有实现这个功能啊,直接修改看来是行不通了,然后去下载“syslog-ng-v2.0-guide-admin-en.pdf”学习Syslog-ng的这本书可真是指明灯啊。终于找到解决方案:利用Syslog-ng中的template可以完美解决此问题实例如下, 比如当我收到facility为local 6,level为debug的日志时,我需要将其facility改为local0, 同时 level 改为info然后存储到本机,实现如下:
  1. filter f_local6 {facility(local6);};   
  2. filter f_level  {level(debug);};   
  3. destination d_template1 {udp("127.0.0.1" port(514) template("<166>$DATE $HOST $MSGHDR$MSG "));   
  4. };   
  5. log { source(src);filter(f_tag_acs);filter(f_local6);destination( d_template1);};  
同时发往的目的地服务器(此处问本机127.0.0.1) 也要配置接收log,配置如下:
  1. source src          {    
  2.                 file("/proc/kmsg");    
  3.             unix-stream("/dev/log" max-connections(256));    
  4.             internal(); };   
  5.   
  6. source s_remote { udp(ip(0.0.0.0) port(514)); };   
  7.   
  8.   
  9. filter f_facility{ facility (local4 ); };   
  10. filter f_level{ level (info ); };   
  11. filter f_tag {  match("acs")  ; };   
  12. destination dest{ file("/var/log/filter1.log");};   
  13. log {   
  14.     source(src);   
  15.     source(s_remote);   
  16.     filter(f_facility;   
  17.     filter(f_level);   
  18.     filter(f_tag);   
  19.     destination(dest);   
  20.    };  
流程如下:
1. 本机收到属性为local6.debug的日志,
2.发往d_template1 由于其应用规则为:{udp("127.0.0.1" port(514) template("<166>$DATE $HOST $MSG ")); 故将其属性转换为local4.info,同时应用其他规则,
3.将应用新规则的log转发给127.0.0.1,
4.本机的其他过滤器dest进行接收。
此过程完成也就将log的facility和level修改并存储了。
  • 1
  • 2
  • 下一页
Linux中利用logrotate来对log文件进行循环管理Ubuntu 安装 Eclipse C/C++开发环境相关资讯      Linux基础教程 
  • Linux基础教程:对文件打包压缩  (03月08日)
  • 基础教程:Linux 新手应该知道的   (09/06/2015 21:17:20)
  • Linux基础教程:find 与 xargs  (04/05/2015 10:20:11)
  • Linux基础教程:tar 命令使用介绍  (12/03/2015 13:19:47)
  • Linux基础教程(1)操作系统基础   (08/15/2015 20:44:01)
  • Linux基础教程:从源码安装软件  (04/05/2015 10:14:45)
本文评论 查看全部评论 (0)
表情: 姓名: 字数