2016-02-05 18 views
1

我試圖在來自bosun的elasticsearch中插入一個警報,但我不知道如何填充變量$timestamp(看看我的示例)與當前時間。我可以使用bosun.conf中的功能嗎?我想喜歡now()。 有人可以幫我嗎?如何處理復星配置中的時間戳?

這是一個配置示例的摘錄:

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 
} 

回答

0

我們使用.State.Touched.Format這是最近在主分支更名爲.Last.Time.Format。格式字符串是一個go time format,你必須得到它打印彈性所期望的正確格式。

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

謝謝您的回答。這對於模板來說是完美的,但我不能在宏或通知中使用它,對嗎? –