# Logstash JDBC Input Complete Action

**URL:** https://discuss.elastic.co/t/logstash-jdbc-input-complete-action/108620
**Category:** Logstash
**Created:** [November 21, 2017, 10:15pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-complete-action/108620 "2017-11-21T22:15:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jeff\_Bursik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeff_bursik/32/23626_2.png) [@Jeff\_Bursik](https://discuss.elastic.co/u/Jeff_Bursik)
#### Post date: [November 21, 2017, 10:15pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-complete-action/108620/1 "2017-11-21T22:15:39Z")

</div>

This has been asked in other threads however a resolution or a solution doesn't appear to have ever been posted so I'd like to ask agin:

Is it possible to have a post action once Logstash has completed the stream/output of the data? For example, I have a JDBC input and ES output that runs every 5 minutes. Upon the completion of the 5 minute task, I'd like to call an API to post data.

If Logstash doesn't contain this function, is there another recommend way? I have considered having logstash running on both the Logstash file (looking for the print out of the SQL statement) and JDBC but that doesn't seem very efficient.

Any help would be great!

---

<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: [November 22, 2017, 6:31am UTC](https://discuss.elastic.co/t/logstash-jdbc-input-complete-action/108620/2 "2017-11-22T06:31:05Z")

</div>

> Is it possible to have a post action once Logstash has completed the stream/output of the data?

No. There's nothing built-in for this and I can't come up with a workaround that's clearly better than what you're suggesting (reading the log).

> <https://github.com/logstash-plugins/logstash-input-jdbc/issues/188>
>
> Currently I am using aggregate filter to group nested tables. The aggregate filt…er works fine except it is using timeout to determine the end of input stream. But timeout is not a reliable choice, it is better that the JDBC input provide someway in the EVENT to tell the query has ended, for example provide with "EOF" as a TAG for the last record. 
> Plug, timeout does not work when paging is enabled, because now the query is broken into multiple individual queries with multiple timeout possibilities.
> Any existing way to detect the EOF of the query? Or should this be implemented as enhancement? Should not be too difficult to add a tag to the last record.
> Thanks

---

<div class="post-metadata">

### Author: ![Jeff\_Bursik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeff_bursik/32/23626_2.png) [@Jeff\_Bursik](https://discuss.elastic.co/u/Jeff_Bursik)
#### Post date: [November 22, 2017, 3:29pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-complete-action/108620/3 "2017-11-22T15:29:51Z")

</div>

Thanks @magnusbaeck.

After some trial and error, it dawned on me that I can modify the sql statement to add a final row. A Union and ensure the final row is always at the bottom of the result set. Appears to be working perfectly for me, incase anyone comes across this.

```
input {
 jdbc {
   statement => 
          "SELECT
                'RUNNING' as logstashstatus
              FROM TABLE
           union
              SELECT
                 'ZCOMPLETE' as logstashstatus
              FROM DUAL
           order by logstashstatus"
 }
}

filter {
 .... 
}

output {

  stdout {}

  if [logstashstatus] != "ZCOMPLETE" {
     .... output
  }
  
  # For JDBC Input Streaming
  if [logstashstatus] == "ZCOMPLETE" {
    # Delete the Status file before writing to it so
    exec {
      command => "echo DONE!!!!!!!!!!! "
    }
  }
}
```

---

<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: [December 20, 2017, 3:30pm UTC](https://discuss.elastic.co/t/logstash-jdbc-input-complete-action/108620/4 "2017-12-20T15:30:03Z")

</div>

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