2

特定のメール アドレスにメール通知を送信できますが、ログのパターンに基づいて別のメール アドレスにメールを送信したいと考えています。

たとえば、メールアドレスを持つ 3 人のユーザーがいるとします。

  1. userOne@something.com が [userOneModule] を含むメール ID ログを受信
  2. userTwo@something.com が [userTwoModule] を含むメール ID ログを受信
  3. userThree@something.com が [userThreeModule] を含むメール ID ログを受信

使用されている Logstash のバージョンは 1.3.3 です。logstash でこれが可能である場合のヘルプ、またはこのようなことを達成するための回避策。

これは私の設定ですが、'Security' と 'Portal' の両方が一致しますが、メールは 1 つにしか送信されません。

セキュリティ ログまたはポータル ログと言う 1 種類のログのみを保持する場合は機能しますが、両方のログを保持すると、いずれか 1 つにのみ電子メールが送信されます。

output { 

if [module] == "Security"{
    email { 
   to => "userOne@somemail.com" 
   from => "dummy2161@somemail.com"
    match =>["%{message}","severity,ERROR"]
   subject => "Error Occured" 
   body => "%{message}" 
   via => "smtp" 
   options => { 
     starttls => "true" 
     smtpIporHost => "smtp.gmail.com" 
     port => "587" 
     userName => "dummy2161@somemail.com" 
    password => "*******"  
     authenticationType => "plain" 
   } 
 }
 }
 if [module] == "Portal"{
    email { 
   to => "userTwo@somemail.com" 
   from => "dummy2161@gmail.com"
    match =>["%{message}","severity,ERROR"]
   subject => "Error Occured" 
   body => "%{message}" 
   via => "smtp" 
   options => { 
     starttls => "true" 
     smtpIporHost => "smtp.gmail.com" 
     port => "587" 
     userName => "dummy2161@somemail 
    password => "*****"  
     authenticationType => "plain" 
   } 
 }
 }

}

ありがとう

4

1 に答える 1

0

受信者の電子メール アドレスをフィールドに保存し (条件または grok フィルターを使用して値を割り当てる)、電子メール出力のtoパラメーターでそのフィールドを参照するか、複数の電子メール出力を条件でラップすることができます。

アドレスを格納するためのフィールドの使用:

filter {
  # If the module name is the same as the recipient address's local part
  mutate {
    add_field => { "recipient" => "%{modulename}@example.com" }
  }

  # Otherwise you might have to use conditionals.
  if [modulename] == "something" {
    mutate {
      add_field => { "recipient" => "someuser@example.com" }
    }
  } else {
    mutate {
      add_field => { "recipient" => "otheruser@example.com" }
    }
  }
}

output {
  email {
    to => "%{recipient}"
    ...
  }
}

条件付きで出力をラップする:

output {
  if [modulename] == "something" {
    email {
      to => "someuser@example.com"
      ...
    }
  } else {
    email {
      to => "otheruser@example.com"
      ...
    }
  }
}
于 2015-06-03T10:12:31.063 に答える