如何根据Kibana Watcher Action的条件成功将电子邮件警报发送给组

发布于 2025-02-06 08:56:07 字数 2109 浏览 1 评论 0 原文

我能够将各种错误分类---

类似----

错误时,即“键” =“响应状态代码不显示成功服务” ----将电子邮件发送到第1组[ [email  proceeded] 保护] email 

[电子邮件 受 错误,即“键” =“响应状态代码不表示成功网关” ----将电子邮件发送到第2组[ [email  preected] ]

a>, [email  procation -

  "actions": {
"send_email": {
  "throttle_period_in_millis": 300000,
  "condition": {
    "script": {
      "source": " def status = false; for(int i=0; i<ctx.payload.failure_request.aggregations.categories.buckets.length;i++) {if(ctx.payload.failure_request.aggregations.categories.buckets[i].key.contains('Response status code does not indicate success')) {status = true}} return status ",
      "lang": "painless"
    }
  },
  "email": {
    "profile": "standard",
    "to": [
      "[email protected]"
    ],
    "subject": "{{ctx.metadata.email_subject}}",
    "body": {
      "html": "Error Found: <ul> {{ctx.payload.aggregations.categories.buckets.length}}"
                   }
                 }
              }
            }

当通过条件通过时,即使键包含该消息时,也将发送给给定的电子邮件。 但是我想一次,根据特定组的消息匹配发送电子邮件。

如果我们有一些无痛的语言来编写逻辑(例如案例语句),那么任何人都可以帮助我。

感谢您的帮助。

I am able to categorize various error like this ---

enter image description here

But i want to send email to groups based on error message.

Something like ---

when error ie "key"= "Response status code does not indicate success Service Unavailable" ---send email to group 1 [[email protected],[email protected],[email protected]]

when error ie "key"= "Response status code does not indicate success Gateway" ---send email to group 2 [[email protected],[email protected],[email protected]]

I have done upto this much ---

  "actions": {
"send_email": {
  "throttle_period_in_millis": 300000,
  "condition": {
    "script": {
      "source": " def status = false; for(int i=0; i<ctx.payload.failure_request.aggregations.categories.buckets.length;i++) {if(ctx.payload.failure_request.aggregations.categories.buckets[i].key.contains('Response status code does not indicate success')) {status = true}} return status ",
      "lang": "painless"
    }
  },
  "email": {
    "profile": "standard",
    "to": [
      "[email protected]"
    ],
    "subject": "{{ctx.metadata.email_subject}}",
    "body": {
      "html": "Error Found: <ul> {{ctx.payload.aggregations.categories.buckets.length}}"
                   }
                 }
              }
            }

Even Email is going to the given email when condition is pass ie when key contains that message.
But I want to send email based on message match for specific group at one go.

can any one help me on this if we have something in painless language to write logic like case statement.

Appreciate your help in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

变身佩奇 2025-02-13 08:56:08

这些是我的建议,希望能为您提供帮助。

解决方案一: 与字符串

"actions": {
    "email_group_one" : {
        "condition": {
            "script": {
                "source": "def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key == 'Response status code does not indicate success Service Unavailable');"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJEC",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    },
    "email_group_two" : {
        "condition": {
            "script": {
                "source": "def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key == 'Response status code does not indicate success Gateway');"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJECT",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    }

}

解决方案两个: 与a,b,c和d(例如

"actions": {
    "email_group_one" : {
        "condition": {
            "script": {
                "source": "def myArray= ['a', 'b', 'c', 'd'];def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key in myArray);"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJEC",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    },
    "email_group_two" : {
        "condition": {
            "script": {
                "source": "def myArray= ['e', 'f', 'g', 'h'];def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key in myArray);"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJECT",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    }

}

该代码尚未测试,您可能有语法错误。

These is my advice, I hope that can help you.

solution one: match with a string

"actions": {
    "email_group_one" : {
        "condition": {
            "script": {
                "source": "def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key == 'Response status code does not indicate success Service Unavailable');"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJEC",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    },
    "email_group_two" : {
        "condition": {
            "script": {
                "source": "def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key == 'Response status code does not indicate success Gateway');"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJECT",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    }

}

solution two: match with multiple values like a,b,c and d

"actions": {
    "email_group_one" : {
        "condition": {
            "script": {
                "source": "def myArray= ['a', 'b', 'c', 'd'];def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key in myArray);"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJEC",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    },
    "email_group_two" : {
        "condition": {
            "script": {
                "source": "def myArray= ['e', 'f', 'g', 'h'];def status = ctx.payload.failure_request.aggregations.categories.buckets; if (status.size() == 0) return false; return hosts.stream().anyMatch(p -> p.key in myArray);"
                "lang": "painless"
            }
        },
        "email" : {
            "to" :  ["[email protected]","[email protected]","[email protected]"],
            "subject" : "YOUR SUBJECT",
            "body" : {
                "html": "YOUR HTML CODE"
            }
        }
    }

}

the code has not been tested, you may have syntax errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文