首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在bosun配置中处理时间戳?

如何在bosun配置中处理时间戳?
EN

Stack Overflow用户
提问于 2016-02-05 21:53:26
回答 1查看 481关注 0票数 1

我正在尝试从bosun在elasticsearch中插入一个警报,但我不知道如何用当前时间填充变量$timestamp (看看我的示例)。我可以在bosun.conf中使用函数吗?我想要像now()这样的东西。有人能帮帮我吗?

以下是示例配置的摘录:

代码语言:javascript
复制
macro m1
{
    $timestamp = **???**
}
notification http_crit
{
    macro = m1
    post =  http://xxxxxxx:9200/alerts/http/
    body = {"@timestamp":$timestamp,"level":"critical","alert_name":"my_alert"}
    next = http_crit
    timeout = 1m
}
alert http
{
    template = elastic
    $testHTTP = lscount("logstash", "", "_type:stat_http,http_response:200", "1m", "5m", "")
    $testAvgHTTP  = avg($testHTTP)
    crit = $testAvgHTTP < 100
    critNotification = http_crit
}
EN

回答 1

Stack Overflow用户

发布于 2016-02-06 01:27:32

我们在主分支中使用最近被重命名为.Last.Time.Format.State.Touched.Format。格式字符串是一个go time format,您必须让它打印出elastic期望的正确格式。

代码语言:javascript
复制
template elastic {
    subject = `Time: {{.State.Touched.Format "15:04:05UTC"}}`
}
//Changed on 2016 Feb 01 to
template elastic {
    subject = `Time: {{.Last.Time.Format "15:04:05UTC"}}`
}

它在渲染时将如下所示:

时间: 01:30:13UTC

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35225911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档