@@ -14,13 +14,16 @@ import (
1414 "github.com/Azure/azure-container-networking/network"
1515 "github.com/Azure/azure-container-networking/platform"
1616 "github.com/Azure/azure-container-networking/store"
17+ "github.com/Azure/azure-container-networking/telemetry"
1718)
1819
1920const (
2021 // Service name.
21- name = "azure-cnimonitor"
22- pluginName = "azure-vnet"
23- DEFAULT_TIMEOUT_IN_SECS = "10"
22+ name = "azure-cnimonitor"
23+ pluginName = "azure-vnet"
24+ DEFAULT_TIMEOUT_IN_SECS = "10"
25+ telemetryNumRetries = 5
26+ telemetryWaitTimeInMilliseconds = 200
2427)
2528
2629// Version is populated by make during build.
@@ -113,11 +116,29 @@ func main() {
113116 // Log platform information.
114117 log .Printf ("[monitor] Running on %v" , platform .GetOSInfo ())
115118
119+ reportManager := & telemetry.ReportManager {
120+ ContentType : telemetry .ContentType ,
121+ Report : & telemetry.CNIReport {
122+ Context : "AzureCNINetworkMonitor" ,
123+ Version : version ,
124+ SystemDetails : telemetry.SystemInfo {},
125+ InterfaceDetails : telemetry.InterfaceInfo {},
126+ BridgeDetails : telemetry.BridgeInfo {},
127+ },
128+ }
129+
130+ reportManager .Report .(* telemetry.CNIReport ).GetOSDetails ()
131+
116132 netMonitor := & cnms.NetworkMonitor {
117133 AddRulesToBeValidated : make (map [string ]int ),
118134 DeleteRulesToBeValidated : make (map [string ]int ),
135+ CNIReport : reportManager .Report .(* telemetry.CNIReport ),
119136 }
120137
138+ tb := telemetry .NewTelemetryBuffer ("" )
139+ tb .ConnectToTelemetryService (telemetryNumRetries , telemetryWaitTimeInMilliseconds )
140+ defer tb .Close ()
141+
121142 for true {
122143 config .Store , err = store .NewJsonFileStore (platform .CNIRuntimePath + pluginName + ".json" )
123144 if err != nil {
@@ -141,6 +162,18 @@ func main() {
141162 log .Printf ("[monitor] Failed while calling SetupNetworkUsingState with error %v" , err )
142163 }
143164
165+ if netMonitor .CNIReport .ErrorMessage != "" {
166+ log .Printf ("[monitor] Reporting discrepancy in rules" )
167+ netMonitor .CNIReport .Timestamp = time .Now ().Format ("2006-01-02 15:04:05" )
168+ if err := reportManager .SendReport (tb ); err != nil {
169+ log .Errorf ("[monitor] SendReport failed due to %v" , err )
170+ } else {
171+ log .Printf ("[monitor] Reported successfully" )
172+ }
173+
174+ netMonitor .CNIReport .ErrorMessage = ""
175+ }
176+
144177 log .Printf ("[monitor] Going to sleep for %v seconds" , timeout )
145178 time .Sleep (time .Duration (timeout ) * time .Second )
146179 nm = nil
0 commit comments