MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / sendPing

Function sendPing

cmd/root.go:128–263  ·  view source on GitHub ↗
(endpoint string, uniqueIdentifier string, message string, series string, timestamp float64, duration *float64, exitCode *int, metrics map[string]int, schedule string, group *sync.WaitGroup)

Source from the content-addressed store, hash-verified

126}
127
128func sendPing(endpoint string, uniqueIdentifier string, message string, series string, timestamp float64, duration *float64, exitCode *int, metrics map[string]int, schedule string, group *sync.WaitGroup) {
129 if group != nil {
130 defer group.Done()
131 }
132
133 Client := &http.Client{
134 Timeout: time.Second * 10,
135 }
136
137 hostname := effectiveHostname()
138 pingApiAuthKey := viper.GetString(varPingApiKey)
139 apiKey := viper.GetString(varApiKey)
140 env := viper.GetString(varEnv)
141 pingApiHost := ""
142 authenticationKey := ""
143 formattedStamp := ""
144 formattedDuration := ""
145 formattedStatusCode := ""
146 formattedMetrics := ""
147 formattedSchedule := ""
148
149 if timestamp > 0 {
150 formattedStamp = fmt.Sprintf("&stamp=%s", formatStamp(timestamp))
151 }
152
153 if len(message) > 0 {
154 message = fmt.Sprintf("&msg=%s", url.QueryEscape(truncateString(message, 1000)))
155 }
156
157 if len(hostname) > 0 {
158 hostname = fmt.Sprintf("&host=%s", url.QueryEscape(truncateString(hostname, 50)))
159 }
160
161 if len(env) > 0 {
162 env = fmt.Sprintf("&env=%s", url.QueryEscape(truncateString(env, 50)))
163 }
164
165 // By passing duration up, we save the computation on the server side
166 if duration != nil {
167 formattedDuration = fmt.Sprintf("&duration=%s", formatStamp(*duration))
168 }
169
170 if schedule != "" {
171 formattedSchedule = fmt.Sprintf("&schedule=%s", schedule)
172 }
173
174 // We aren't using exit code at time of writing, but we have the field available for healthcheck monitors.
175 if exitCode != nil {
176 formattedStatusCode = fmt.Sprintf("&status_code=%d", *exitCode)
177 }
178
179 // The `series` data is used to match run events with complete or fail. Useful if multiple instances of a job are running.
180 if len(series) > 0 {
181 series = fmt.Sprintf("&series=%s", series)
182 }
183
184 if metrics != nil && len(metrics) > 0 {
185 values := url.Values{}

Callers 3

ping.goFile · 0.85
RunCommandFunction · 0.85
handleRunJobFunction · 0.85

Calls 6

effectiveHostnameFunction · 0.85
formatStampFunction · 0.85
truncateStringFunction · 0.85
logFunction · 0.85
ErrorMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected