apiVersion: v1
kind: ConfigMap
metadata:
  name: logstash-discrepancy-user-cm-sql
data:
  logstash.conf: |-
    input {
        jdbc {
        type => "di_updt_user_disc"
        jdbc_driver_library => "/opt/logstash/driver/mssql-jdbc-7.4.1.jre8.jar"
        jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
        jdbc_connection_string => "CONN_STRING"
        jdbc_user => "MT_CONPOOL_USER"
        jdbc_password => "MT_CONPOOL_USER"
        jdbc_fetch_size => 1000
        schedule => "*/5 * * * *"
        statement => "select distinct concat(d.disc_id, concat('$', concat(d.disc_line_no, concat('$',d.updt_userid)))) as rid_obj, concat('', d.rowid) as temp_rid, d.updt_userid, d.disc_id, d.disc_line_no, d.part_no, d.PART_CHG, d.security_group from sfqa_disc_item d where (DATEADD(second, datediff(second, getdate(), getutcdate()), d.time_stamp) >= :sql_last_value)"
        clean_run => false
        record_last_run => true
        sql_log_level => debug
        last_run_metadata_path => "/opt/logstash/lastrun/.logstash_jdbc_last_run_disc_updt_user"
        connection_retry_attempts_wait_time => 30
        connection_retry_attempts => 99999999
        }	
      jdbc {
        type => "di_assigned_to_user_disc"
        jdbc_driver_library => "/opt/logstash/driver/mssql-jdbc-7.4.1.jre8.jar"
        jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
        jdbc_connection_string => "CONN_STRING"
        jdbc_user => "MT_CONPOOL_USER"
        jdbc_password => "MT_CONPOOL_USER"
        jdbc_fetch_size => 1000
        schedule => "*/5 * * * *"
        statement => "select distinct concat(d.disc_id, concat('$', concat(d.disc_line_no, concat('$',t.assigned_to_userid)))) as rid_obj, concat('', t.rowid) as temp_rid, t.assigned_to_userid as updt_userid, d.disc_id, d.disc_line_no, d.part_no, d.PART_CHG, d.security_group from sfqa_disc_item d, sffnd_disposition_task dt, sffnd_task t where d.disc_id = dt.disc_id and d.disc_line_no = dt.disc_line_no and dt.task_id = t.task_id and t.auto_complete_task_flag = 'N' and (DATEADD(second, datediff(second, getdate(), getutcdate()), d.time_stamp) >= :sql_last_value OR DATEADD(second, datediff(second, getdate(), getutcdate()), dt.time_stamp) >= :sql_last_value OR DATEADD(second, datediff(second, getdate(), getutcdate()), t.time_stamp) >= :sql_last_value)"
        clean_run => false
        record_last_run => true
        sql_log_level => debug
        last_run_metadata_path => "/opt/logstash/lastrun/.logstash_jdbc_last_run_disc_assigned_to_user"
        connection_retry_attempts_wait_time => 30
        connection_retry_attempts => 99999999
        }	
    }
    filter {
      if[type] == "di_assigned_to_user_disc" {
        mutate {
          replace => { "type" => "assigned_to_user_disc" }
          }
      }
      else if[type] == "di_updt_user_disc" {
        mutate {
          replace => { "type" => "updt_user_disc" }
          }
      }
    }
    output {
        elasticsearch {
          hosts => "https://--es--:443"
          index => "<discrepancyusersearch>" 
          document_id => "%{rid_obj}"
        }
      }

  logstash.yml: |-
    http.host: "0.0.0.0"
    path.config: /usr/share/logstash/pipeline
    xpack.monitoring.enabled: false
