package cbssl import ( "strconv" "strings" "time" "rocketgit.ru/rsmon/worker/app/models" "rocketgit.ru/rsmon/worker/internal/checkresult" ) // Result is a result of a browser-based SSL certificate check type Result struct { checkresult.CheckResult // Chrome-specific results ChromeValid bool `json:"chrome_valid"` ChromeError string `json:"chrome_error,omitempty"` ChromeChain []CertInfo `json:"chrome_chain,omitempty"` // Firefox-specific results FirefoxValid bool `json:"firefox_valid"` FirefoxError string `json:"firefox_error,omitempty"` FirefoxChain []CertInfo `json:"firefox_chain,omitempty"` // Certificate details Expires *time.Time `json:"expires,omitempty"` Subject string `json:"subject,omitempty"` Issuer string `json:"issuer,omitempty"` DNSNames []string `json:"dns_names,omitempty"` } // CertInfo represents information about a certificate in the chain type CertInfo struct { Subject string `json:"subject"` Issuer string `json:"issuer"` NotBefore time.Time `json:"not_before"` NotAfter time.Time `json:"not_after"` IsCA bool `json:"is_ca"` PublicKey string `json:"public_key_algorithm"` Signature string `json:"signature_algorithm"` } // InfluxFields returns the fields for InfluxDB metrics func (r *Result) InfluxFields() map[string]interface{} { ret := make(map[string]interface{}, 0) ret["took"] = int64(r.Duration / time.Millisecond) ret["chrome_valid"] = r.ChromeValid ret["firefox_valid"] = r.FirefoxValid if r.Expires != nil { ret["expires_at"] = r.Expires.Unix() ret["days_until_expiry"] = int64(time.Until(*r.Expires).Hours() / 24) } return ret } // InfluxTags returns the tags for InfluxDB metrics func (r *Result) InfluxTags(c models.Check) map[string]string { //nolint:gocritic // hugeParam: accepted for interface compatibility ret := make(map[string]string, 0) ret["check"] = strconv.FormatInt(c.ID, 10) ret["state"] = r.State ret["subject"] = r.Subject ret["issuer"] = r.Issuer if r.Error != nil { ret["error"] = r.Error.Error() } if r.ChromeError != "" { ret["chrome_error"] = r.ChromeError } if r.FirefoxError != "" { ret["firefox_error"] = r.FirefoxError } ret["warnings"] = strings.Join(r.Warnings, ",") ret["dns_names"] = strings.Join(r.DNSNames, ",") return ret }