# Logstash: Can't generate new event in custom filter using ruby

**URL:** https://discuss.elastic.co/t/logstash-cant-generate-new-event-in-custom-filter-using-ruby/99714
**Category:** Logstash
**Created:** [September 7, 2017, 10:51am UTC](https://discuss.elastic.co/t/logstash-cant-generate-new-event-in-custom-filter-using-ruby/99714 "2017-09-07T10:51:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jay\_Dabhi](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@Jay\_Dabhi](https://discuss.elastic.co/u/Jay_Dabhi)
#### Post date: [September 7, 2017, 10:51am UTC](https://discuss.elastic.co/t/logstash-cant-generate-new-event-in-custom-filter-using-ruby/99714/1 "2017-09-07T10:51:50Z")

</div>

0  
down vote  
favorite  
I am designing the my custom log-stash filter using the ruby.This filter generates the event after certain period.I am generating the new event from the thread.Following is the my code of the thread function which is producing the event.

public  
def timer\_thread()  
while 1  
sleep(2)  
keys = @dict.keys  
keys.each { |key|  
@dict[key][1] = @dict[key][1] - 2  
if @dict[key][1] \< 0  
message = "No repsonse for the UE number: " + key  
@dict.delete(key)  
@logger.info(message)  
e = LogStash::Event.new()  
e.set("Notification",message)  
yield e if block\_given?  
end  
}

```
 end

```

end  
As you can see I am creating the new event and emitting it.But in my output I can only see the log message not my event. What is wrong? Please help me out

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [September 11, 2017, 8:44pm UTC](https://discuss.elastic.co/t/logstash-cant-generate-new-event-in-custom-filter-using-ruby/99714/2 "2017-09-11T20:44:42Z")

</div>

Only filter() can use yield to produce a new message. I don't know OTOH how to inject new events from background threads invoked from filters.

---

<div class="post-metadata">

### Author: ![Jay\_Dabhi](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@Jay\_Dabhi](https://discuss.elastic.co/u/Jay_Dabhi)
#### Post date: [September 12, 2017, 11:02am UTC](https://discuss.elastic.co/t/logstash-cant-generate-new-event-in-custom-filter-using-ruby/99714/3 "2017-09-12T11:02:43Z")

</div>

I am able to solve my problem using flush() method.This method will be called by logstash after every 5 sec.From flush() method we can generate the event.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 10, 2017, 11:02am UTC](https://discuss.elastic.co/t/logstash-cant-generate-new-event-in-custom-filter-using-ruby/99714/4 "2017-10-10T11:02:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
