#a Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.

input {
 	 jdbc {
		type => "zdgx_article"
		jdbc_connection_string => "jdbc:mysql://10.0.0.12:3309/zdgx_cms?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false"
		jdbc_user => "root"
       		jdbc_password => "mysql@teetron.com.cn"
        	jdbc_driver_library => "/usr/local/logstash-7.6.2/config/mysql-connector-java-8.0.23.jar"
        	jdbc_driver_class => "com.mysql.jdbc.Driver"
		jdbc_paging_enabled => "true"
		jdbc_page_size => "1000"
		statement_filepath => "/usr/local/logstash-7.6.2/config/sql/zdgx_article.sql"
        	schedule => "*/5 * * * * *"
		record_last_run => "true"
		use_column_value => "true"
		tracking_column => "last_update_time"
		tracking_column_type => "timestamp"
		last_run_metadata_path => "/usr/local/logstash-7.6.2/config/sql/zdgx_article_update_time"
		clean_run => false
		jdbc_default_timezone => "UTC" 
	}
	jdbc {
                type => "zdgx_book"
                jdbc_connection_string => "jdbc:mysql://10.0.0.12:3309/zdgx_cms?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false"
                jdbc_user => "root"
                jdbc_password => "mysql@teetron.com.cn"
                jdbc_driver_library => "/usr/local/logstash-7.6.2/config/mysql-connector-java-8.0.23.jar"
                jdbc_driver_class => "com.mysql.jdbc.Driver"
                jdbc_paging_enabled => "true"
                jdbc_page_size => "1000"
                statement_filepath => "/usr/local/logstash-7.6.2/config/sql/zdgx_book.sql"
                schedule => "*/5 * * * * *"
                record_last_run => "true"
                use_column_value => "true"
                tracking_column => "last_update_time"
                tracking_column_type => "timestamp"
                last_run_metadata_path => "/usr/local/logstash-7.6.2/config/sql/zdgx_book_update_time"
                clean_run => false
		jdbc_default_timezone => "UTC" 
        }
	jdbc {
                type => "zdgx_scenic"
                jdbc_connection_string => "jdbc:mysql://10.0.0.12:3309/zdgx_cms?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false"
                jdbc_user => "root"
                jdbc_password => "mysql@teetron.com.cn"
                jdbc_driver_library => "/usr/local/logstash-7.6.2/config/mysql-connector-java-8.0.23.jar"
                jdbc_driver_class => "com.mysql.jdbc.Driver"
                jdbc_paging_enabled => "true"
                jdbc_page_size => "1000"
                statement_filepath => "/usr/local/logstash-7.6.2/config/sql/zdgx_scenic.sql"
                schedule => "*/5 * * * * *"
                record_last_run => "true"
                use_column_value => "true"
                tracking_column => "last_update_time"
                tracking_column_type => "timestamp"
                last_run_metadata_path => "/usr/local/logstash-7.6.2/config/sql/zdgx_scenic_update_time"
                clean_run => false
		jdbc_default_timezone => "UTC" 
        }
	jdbc {
                type => "zdgx_spot"
                jdbc_connection_string => "jdbc:mysql://10.0.0.12:3309/zdgx_cms?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false"
                jdbc_user => "root"
                jdbc_password => "mysql@teetron.com.cn"
                jdbc_driver_library => "/usr/local/logstash-7.6.2/config/mysql-connector-java-8.0.23.jar"
                jdbc_driver_class => "com.mysql.jdbc.Driver"
                jdbc_paging_enabled => "true"
                jdbc_page_size => "1000"
                statement_filepath => "/usr/local/logstash-7.6.2/config/sql/zdgx_spot.sql"
                schedule => "*/5 * * * * *"
                record_last_run => "true"
                use_column_value => "true"
                tracking_column => "last_update_time"
                tracking_column_type => "timestamp"
                last_run_metadata_path => "/usr/local/logstash-7.6.2/config/sql/zdgx_spot_update_time"
                clean_run => false
		jdbc_default_timezone => "UTC" 
        }
}


filter {
	json {  
		source => "message"  
        	remove_field => ["message"]  
	}  
	
} 

output {
	if [type] == "zdgx_article" {
		elasticsearch {
    			hosts => ["10.0.0.14:9200"]
    			index => "pub_index_bus_data"
    			document_id => "%{bus_code}"  
			action => "update"
			doc_as_upsert => true
		}
	}
	if [type] == "zdgx_book" {
                elasticsearch {
                        hosts => ["10.0.0.14:9200"]
                        index => "pub_index_bus_data"
                        document_id => "%{bus_code}"
			action => "update"
                        doc_as_upsert => true
                }
        }
	if [type] == "zdgx_scenic" {
                elasticsearch {
                        hosts => ["10.0.0.14:9200"]
                        index => "pub_index_bus_data"
                        document_id => "%{bus_code}"
			action => "update"
                        doc_as_upsert => true
                }
        }
	if [type] == "zdgx_spot" {
                elasticsearch {
                        hosts => ["10.0.0.14:9200"]
                        index => "pub_index_bus_data"
                        document_id => "%{bus_code}"
			action => "update"
                        doc_as_upsert => true
                }
        }

	stdout {
        	codec => json_lines
        }
}
