# Ruby filter used for reading modified time of file

**URL:** <https://discuss.elastic.co/t/ruby-filter-used-for-reading-modified-time-of-file/94127>\
**Category:** Logstash\
**Created:** [July 21, 2017, 3:04pm UTC](https://discuss.elastic.co/t/ruby-filter-used-for-reading-modified-time-of-file/94127 "2017-07-21T15:04:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CDR](https://avatars.discourse-cdn.com/v4/letter/c/d9b06d/32.png) [@CDR](https://discuss.elastic.co/u/CDR)\
**Post date:** [July 21, 2017, 3:04pm UTC](https://discuss.elastic.co/t/ruby-filter-used-for-reading-modified-time-of-file/94127/1 "2017-07-21T15:04:21Z")

</div>

Hello community,

I am currently trying to use the ruby filter to get the modified time of the file I am reading. I want to store the modified time in mtime. This is my first time using ruby so I am sort of lost. Here is my code:

```
if [type] == "test" {
	ruby {
		code => 'event.set("modified_time", File.mtime("path"))'
	}
}

```

It gives me an error of:

> Ruby exception occurred: No such file or directory - path

In elasticsearch the 'path' is:

> C:/ELK-Stack\_windows/user\_files/data/multiline/file.prn

Unsure as to why it is giving me this error since the file exists in that location.

Thanks!

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [July 24, 2017, 10:38am UTC](https://discuss.elastic.co/t/ruby-filter-used-for-reading-modified-time-of-file/94127/2 "2017-07-24T10:38:10Z")

</div>

The error is because you cannot directly[reference event values](https://www.elastic.co/guide/en/logstash/current/event-api.html) (much like you can't assign a value and you have to use a .set method, as you already do). This should work

```auto
if [type] == "test" {
	ruby {
		code => 'event.set("modified_time", File.mtime(event.get("path")))'
	}
}
```

---

<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:** [August 21, 2017, 10:38am UTC](https://discuss.elastic.co/t/ruby-filter-used-for-reading-modified-time-of-file/94127/3 "2017-08-21T10:38:27Z")

</div>

Closed on August 21, 2017, 10:38am UTC

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