# Logstash from 2 different resource in one logstash

**URL:** <https://discuss.elastic.co/t/logstash-from-2-different-resource-in-one-logstash/306185>\
**Category:** Logstash\
**Created:** [June 2, 2022, 5:09am UTC](https://discuss.elastic.co/t/logstash-from-2-different-resource-in-one-logstash/306185 "2022-06-02T05:09:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zerra\_Triani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zerra_triani/32/105901_2.png) [@Zerra\_Triani](https://discuss.elastic.co/u/Zerra_Triani)\
**Post date:** [June 2, 2022, 5:09am UTC](https://discuss.elastic.co/t/logstash-from-2-different-resource-in-one-logstash/306185/1 "2022-06-02T05:09:46Z")

</div>

Hi, i have two differetent resource log and i want to filtered in one server with one logstash. I've created the grok filter as I want it using the grol debugger and it's working and producing the appropriate output. But when I implement using logstash it doesn't work. Can anyone help?

It's the Logstash

```auto
input {
  beats {
    port => 5044
  }
}
filter{
	mutate { 
        rename => ["message", "rawMessage"]
    }
	mutate {
        gsub => ["rawMessage", "[\r\n\t]", ""]
        gsub => ["rawMessage", "\\r", ""]
        gsub => ["rawMessage", "\\n", ""]
        gsub => ["rawMessage", "\\t", ""]
	}
	
	if[data_source] == "global" {
		grok {
                match => { "rawMessage" => "%{TIMESTAMP_ISO8601:datetime}\s\[%{GREEDYDATA:thread}\]\s%{LOGLEVEL:log}\s%{GREEDYDATA:category1}\s\s\-\s%{GREEDYDATA:message}"}
        }
        date {
                match => ["datetime", "yyyy-MM-dd HH:mm:ss,SSS"]
                target => "@timestamp"
        }
	}
	else if[data_source] == "XMLDriver" {
		grok {
			patterns_dir => ["C:\Elasticsearch\ELK\Logstash\date_pattern.txt"]
			match => { "rawMessage" => "%{GREEDYDATA:category1}\s-\s%{GREEDYDATA:category2}\s-\s%{GREEDYDATA:category3}\s-\s%{F_DATETIME_XML:datetime}\s-\s%{GREEDYDATA:category4}\s-\s%{GREEDYDATA:category5}\s-\s%{GREEDYDATA:message}"}
		}
		date {
			match => ["datetime" , "EEE MMM d HH:mm:ss"]
			target => "@timestamp" 
		}
	}
}
output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
  }
}

```

it's the filebeat

```auto
filebeat.inputs:

  - type: log
    enabled: true
    paths:
      - C:\Elasticsearch\Log\ABC\globalserver2.log
      - C:\Elasticsearch\Log\ABC\globalserver3.log
    multiline.pattern: ^(\d{4})-(\d{2})-(\d{2})\s*(\d{2}):(\d{2}):(\d{2}),(\d{3})
    multiline.negate: true
    multiline.match: after
    fields:
      data_source: global
      
  - type: log
    enabled: true
    paths:
      - C:\Elasticsearch\Log\ABC\XMLdriver.log
    multiline.pattern: ^R10\.97389
    multiline.negate: true
    multiline.match: after
    fields:
      data_source: XMLDriver

```

It's the log example  
**ServerGlobal Log**

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/d/5d2e2659d058b5c74a6145c22e234fcd7885f6da.png)

**XMLDriver Log**

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/9/09b1fcd5bf5d3e3421d33f0ecc235607fc9227e5.png)

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [June 2, 2022, 11:22am UTC](https://discuss.elastic.co/t/logstash-from-2-different-resource-in-one-logstash/306185/2 "2022-06-02T11:22:30Z")

</div>

You are missing **fields**

`if [fields][data_source] == "global" { `

`else if [fields][data_source] == "XMLDriver" {`

Use ruby debug when something is not working.

---

<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:** [June 30, 2022, 11:22am UTC](https://discuss.elastic.co/t/logstash-from-2-different-resource-in-one-logstash/306185/3 "2022-06-30T11:22:49Z")

</div>

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