How to automatically kill a logstash agent when te

2019-05-10 16:08发布

问题:

I have a logstash agent that monitors our automatic tests' log dumps -

at the beginning of each bulk of tests, an agent is started, listens to a specific folder, and at the end it should stop.

The problem is at the end - i need to somehow signal the logstash agent that the tests are done and kill itself..

How can I do that? What is the way to configure the agent so that when it sees a certain log message from the tests it kills himself?

My config file:

input {

  file {
    type => "cloudify-logs"
    path => "<path_to_test_class_folder>/*"
    tags => [ "<suite_name>" , "<test_name>" , "<build_number>" , "<version>" ]
  }
}

output {
  stdout { debug => true debug_format => "json"}
  redis { host => "<host>" data_type => "list" key => "logstash" }
}

回答1:

One option would be to put a line at the end of your log such as:

END TEST

You can then create a LogStash "kill" script which is executed by LogStash when it hits that line.

For example:

filter
{
    if [message] =~ "^END TEST"
    {
        mutate
        {
            add_tag => ["end"]
        }
    }
}

output
{
    if "end" in [tags]
    {
        exec
        {
            command => "kill_logstash.sh"
        }
    }
}


标签: logstash