Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
764 views
in Technique[技术] by (71.8m points)

logstash - can you forward logs to different targets for different log classes?

I know in logstash you can forward logs.

Can you use different targets and protocol for different classes? I want to separate the forwarding target between my json and syslog logs. How do I do that?

question from:https://stackoverflow.com/questions/66051546/can-you-forward-logs-to-different-targets-for-different-log-classes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can separate different flows as per their needs using tags and apply operations to them accordingly. A sample code is mentioned below:

 input {
      beats { port => 2200  tag => apache   }
      tcp { port => 9999  tag => firewall   }
    }
    filter {
       if "apache" in [tags] {  
        <someoperation> { ... }
       } else if "firewall" in [tags] {  
        grok { ... }
       }  
    }
    output {
       if "apache" in [tags] {  
        elasticsearch { ... }
       } else if "firewall" in [tags] {  
        tcp { ... }
       }  
    }

Explanation :

In the input plugin, all the events flowing from port 2200 and 9999 are added with tags apache and firewall respectively. This will be used to apply separate filter operations to each of the event based on the tag added in the input plugin. Now, In the same way these events can be separately sent to different or same endpoint (be it a log file, a console output, an Elasticsearch storage etc.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...