# Validate file with logstash-file-input plugin

**URL:** <https://discuss.elastic.co/t/validate-file-with-logstash-file-input-plugin/81068>\
**Category:** Logstash\
**Created:** [April 4, 2017, 1:32am UTC](https://discuss.elastic.co/t/validate-file-with-logstash-file-input-plugin/81068 "2017-04-04T01:32:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shabirmean](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@shabirmean](https://discuss.elastic.co/u/shabirmean)\
**Post date:** [April 4, 2017, 1:32am UTC](https://discuss.elastic.co/t/validate-file-with-logstash-file-input-plugin/81068/1 "2017-04-04T01:32:11Z")

</div>

Hi,

I am working on a project that uses Logstash to parse some csv files. For this the Logstash “file-input-plugin” is used where new files are read from a path and the parsing is done.

However, I am trying to implement a validation to this flow: whenever a new file is captured, calculate its SHA DIGEST and call an endpoint and validate that it’s a valid file.

DISCLAIMER: My experience with Ruby is NIL . Mostly accustomed to Java.

Regardless, I was going through the logstash file-input-plugin source ([https://github.com/logstash-plugins/logstash-input-file](https://github.com/logstash-plugins/logstash-input-file)) and I saw that they had used a package named “filewatch/tail”. Searching for it lead me to this repo: [https://github.com/jordansissel/ruby-filewatch](https://github.com/jordansissel/ruby-filewatch)

I found that they call a method “subscribe” of FileWatch::Tail at

> <https://github.com/logstash-plugins/logstash-input-file/blob/master/lib/logstash/inputs/file.rb#L305>

Can I get some guidance as to where exactly can I write into something to have the custom logic – calculate file DIGEST -\> Call endpoint and validate -\> if valid then process file else raise an error – whenever a new file is grabbed?

Your time and guidance will be much appreciated.

Thanks  
Shabir

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [April 5, 2017, 12:50pm UTC](https://discuss.elastic.co/t/validate-file-with-logstash-file-input-plugin/81068/2 "2017-04-05T12:50:14Z")

</div>

@shabirmean  
I wrote those changes to the file input.  
The file input does not have a facility for this - the part you would want to hook into (but can't now) is the file discovery loop which scans for files to the 'to-be-processed' collection.

The only way you can do this is to script something yourself using a staging folder...

1. new files go into a staging folder -\> `staging`
2. a script monitors for new files, does the digest + compare.
3. move file to a valid folder -\> `valid`
4. LS detects the file in the valid folder and begins tailing it.

---

<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:** [May 3, 2017, 12:50pm UTC](https://discuss.elastic.co/t/validate-file-with-logstash-file-input-plugin/81068/3 "2017-05-03T12:50:18Z")

</div>

Closed on May 3, 2017, 12:50pm UTC

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