Basic Operations

Basic

Stdin, Stdout

You may create a conf file like:

input {
    stdin {

    }
}

output {
    stdout {
        codec => rubydebug
    }
}

Then run:

/usr/share/logstash/bin/logstash -f test.conf 

Stdin on JSON

We can use codec json:

input {
    stdin {
        codec => json
    }
}

output {
    stdout {
        codec => rubydebug
    }
}

Then run

/usr/share/logstash/bin/logstash -f jsontest.conf

Output to a file

Our config could be:

input {
    stdin {
        codec => json
    }
}

output {
    stdout {
        codec => rubydebug
    }
    file {
        path => "/tmp/out.txt"
    }
}

Then run:

/usr/share/logstash/bin/logstash -f file_out_test.conf

HTTP Input

Conf:

input {
    stdin {
        codec => json
    }
    http {
        host => "127.0.0.1"
        port => 8080
    }
}

output {
    stdout {
        codec => rubydebug
    }
    file {
        path => "/tmp/http_out.txt"
    }
}

Run:

/usr/share/logstash/bin/logstash -f http_input_test.conf

Filtering

Conf:

input {
    stdin {
        codec => json
    }
    http {
        host => "127.0.0.1"
        port => 8080
    }
}

filter {
    mutate {
        convert => { "quantity" => "integer" }
    }
}

output {
    stdout {
        codec => rubydebug
    }
    file {
        path => "/tmp/filter_out.txt"
    }
}

More mutate:

  • add_field

  • remove_field

  • add_tag

  • remove_tag

Last updated