Duplicati and pushgateway

I am working on a solution to monitor our backups, with Duplicati, via Grafana. Duplicate sends a “Post” to a pushgateway after the backup is done. With the script below it works so far. If the pushgateway is not reachable, the script aborts with an “exit status 2”. This will provoke an error message in Duplicati as a warning. The script should also terminate with an “exit status 0” in case of an error.
How can this be realized?
I hope you can help me

package main
import (
func main() {
	var res int
	if strings.EqualFold(os.Getenv("DUPLICATI__PARSED_RESULT"),"Success")  {
	  res = 1
	} else {
	  res = 0
	data := "backup_result " + strconv.Itoa(res) + "\n"
	body := bytes.NewReader([]byte(data))
	req, err := http.NewRequest("POST", "http://pushgateway.tld:9091/metrics/job/"+os.Getenv("DUPLICATI__backup_name"), body)
	req.Header.Set("Content-Type", "application/octet-stream")
	client := &http.Client{}
	resp,err := client.Do(req)
	defer resp.Body.Close()
	if err != nil {
	func() {
    time.Sleep(120 * time.Second)
    data2 := "backup_result "  + "\n"
	body2 := bytes.NewReader([]byte(data2))
	req2,err2 := http.NewRequest("DELETE", "http://pushgateway.tld:9091/metrics/job/"+os.Getenv("DUPLICATI__backup_name"), body2)
        req2.Header.Set("Content-Type", "application/octet-stream")
	client2 := &http.Client{}
	resp2,err2 := client2.Do(req2)
	defer resp2.Body.Close()
	if err2 != nil {

the topic can be deleted, I have solved the problem myself, thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.