Bosun 嵌入式模板和CSS样式
示例
您可以将另一个模板主体嵌入到模板中,{{template"mysharedtemplate".}}以重复使用共享的组件。这是一个创建标题模板的示例,该模板可以在所有其他模板主体的顶部重复使用。它还使用CSS来对输出进行样式化,以便于阅读。请注意,所有<style>...</style>块都将转换为每个元素上的内联CSS,以便Gmail等电子邮件客户端可以正确呈现输出。
template header {
body = `
<style>
td, th {
padding-right: 10px;
}
a.rightpad{
padding-right: 10px;
}
</style>
<p style="font-weight: bold; text-decoration: underline;">
<a class="rightpad" href="{{.Ack}}">Acknowledge</a>
<a class="rightpad" href="{{.Rule}}">View Alert in Bosun's Rule Editor</a>
{{if .Group.host}}
<a class="rightpad" href="https://opserver/dashboard/node?node={{.Group.host}}">View {{.Group.host}} in Opserver</a>
<a href="http://kibana/app/kibana?#/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-15m,mode:quick,to:now))&_a=(columns:!(_source),index:%5Blogstash-%5DYYYY.MM.DD,interval:auto,query:(query_string:(analyze_wildcard:!t,query:'logsource:{{.Group.host}}')),sort:!('@timestamp',desc))">View {{.Group.host}} in Kibana</a>
{{end}}
</p>
<table>
<tr>
<td><strong>Key: </strong></td>
<td>{{printf "%s%s" .Alert.Name .Group }}</td>
</tr>
<tr>
<td><strong>Incident: </strong></td>
<td><a href="{{.Incident}}">#{{.Last.IncidentId}}</a></td>
</tr>
</table>
<br/>
{{if .Alert.Vars.notes}}
<p><strong>Notes:</strong> {{html .Alert.Vars.notes}}</p>
{{end}}
<p><strong>Tags</strong>
<table>
{{range $k, $v := .Group}}
{{if eq $k "host"}}
<tr><td>{{$k}}</td><td><a href="{{$.HostView $v}}">{{$v}}</a></td></tr>
{{else}}
<tr><td>{{$k}}</td><td>{{$v}}</td></tr>
{{end}}
{{end}}
</table></p>
`
}之后,您可以添加开始使用模板,body=`{{template"header".}}以在顶部获得以下输出: