55 "fmt"
66 "math/rand/v2"
77 "net/http"
8+ "net/url"
89 "strings"
910
1011 "github.com/prometheus/common/model"
@@ -98,7 +99,7 @@ func createAlerts(probability float64, name string, threshold, upperBound int, t
9899 return alerts , ruleState
99100}
100101
101- func createRule (probability float64 , name , severity string , threshold , upperBound int , bynetobs bool , nsLbl , nodeLbl []string ) AlertingRule {
102+ func createRule (probability float64 , name , severity , extraFilter string , threshold , upperBound int , bynetobs bool , nsLbl , nodeLbl []string ) AlertingRule {
102103 labels := model.LabelSet {
103104 "severity" : model .LabelValue (severity ),
104105 }
@@ -125,12 +126,19 @@ func createRule(probability float64, name, severity string, threshold, upperBoun
125126 }
126127 jsonNodeLbl = fmt .Sprintf (`"nodeLabels":[%s],` , strings .Join (quotedLbl , "," ))
127128 }
129+ searchURL := "https://duckduckgo.com/?q=" + url .PathEscape (name )
130+ var extraFilterJSON string
131+ if extraFilter != "" {
132+ extraFilterJSON = fmt .Sprintf (`,"trafficLinkFilter":"%s"` , extraFilter )
133+ }
128134 annotations ["netobserv_io_network_health" ] = model .LabelValue (fmt .Sprintf (
129- `{%s%s"threshold":"%d","upperBound":"%d","unit":"%%"}` ,
135+ `{%s%s"threshold":"%d","upperBound":"%d","unit":"%%","links":[{"name":"Search the web", "url": "%s"}]%s }` ,
130136 jsonNsLbl ,
131137 jsonNodeLbl ,
132138 threshold ,
133139 upperBound ,
140+ searchURL ,
141+ extraFilterJSON ,
134142 ))
135143 ruleLabels := labels .Clone ()
136144 ruleLabels ["prometheus" ] = "openshift-monitoring/k8s"
@@ -160,13 +168,13 @@ func createRule(probability float64, name, severity string, threshold, upperBoun
160168func GetRules () func (w http.ResponseWriter , r * http.Request ) {
161169 return func (w http.ResponseWriter , _ * http.Request ) {
162170 alertingRules := []AlertingRule {
163- createRule (0.4 , "Packet delivery failed" , "info" , 5 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
164- createRule (0.3 , "You have reached your hourly rate limit" , "info" , 5 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
165- createRule (0.1 , "It's always DNS" , "warning" , 15 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
166- createRule (0.1 , "We're under attack" , "warning" , 20 , 100 , true , []string {}, []string {}),
167- createRule (0.1 , "Sh*t - Famous last words" , "critical" , 5 , 100 , true , []string {}, []string {"SrcK8S_Hostname" , "DstK8S_Hostname" }),
168- createRule (0.3 , "FromIngress" , "info" , 10 , 100 , false , []string {"exported_namespace" }, []string {}),
169- createRule (0.3 , "Degraded latency" , "info" , 100 , 1000 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
171+ createRule (0.4 , "Packet delivery failed" , "info" , "" , 5 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
172+ createRule (0.3 , "You have reached your hourly rate limit" , "info" , "" , 5 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
173+ createRule (0.1 , "It's always DNS" , "warning" , `dns_flag_response_code!=\"\"` , 15 , 100 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
174+ createRule (0.1 , "We're under attack" , "warning" , "" , 20 , 100 , true , []string {}, []string {}),
175+ createRule (0.1 , "Sh*t - Famous last words" , "critical" , "" , 5 , 100 , true , []string {}, []string {"SrcK8S_Hostname" , "DstK8S_Hostname" }),
176+ createRule (0.3 , "FromIngress" , "info" , "" , 10 , 100 , false , []string {"exported_namespace" }, []string {}),
177+ createRule (0.3 , "Degraded latency" , "info" , "" , 100 , 1000 , true , []string {"SrcK8S_Namespace" , "DstK8S_Namespace" }, []string {}),
170178 }
171179 res := map [string ]any {
172180 "status" : "success" ,
0 commit comments