|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "flag" |
| 7 | + "fmt" |
| 8 | + "os" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/checkly/checkly-go-sdk" |
| 12 | + ctrl "sigs.k8s.io/controller-runtime" |
| 13 | +) |
| 14 | + |
| 15 | +// The script returns the data for a specific checkly check from the checklyhq API, |
| 16 | +// it's meant to be used as a debug tool for issues with checks created. |
| 17 | + |
| 18 | +func main() { |
| 19 | + |
| 20 | + setupLog := ctrl.Log.WithName("setup") |
| 21 | + |
| 22 | + var checklyID string |
| 23 | + |
| 24 | + flag.StringVar(&checklyID, "c", "", "Specify the checkly check ID") |
| 25 | + flag.Parse() |
| 26 | + |
| 27 | + if checklyID == "" { |
| 28 | + setupLog.Error(errors.New("ChecklyID is empty"), "exiting due to missing information") |
| 29 | + os.Exit(1) |
| 30 | + } |
| 31 | + |
| 32 | + baseUrl := "https://api.checklyhq.com" |
| 33 | + apiKey := os.Getenv("CHECKLY_API_KEY") |
| 34 | + if apiKey == "" { |
| 35 | + setupLog.Error(errors.New("checklyhq.com API key environment variable is undefined"), "checklyhq.com credentials missing") |
| 36 | + os.Exit(1) |
| 37 | + } |
| 38 | + |
| 39 | + accountId := os.Getenv("CHECKLY_ACCOUNT_ID") |
| 40 | + if accountId == "" { |
| 41 | + setupLog.Error(errors.New("checklyhq.com Account ID environment variable is undefined"), "checklyhq.com credentials missing") |
| 42 | + os.Exit(1) |
| 43 | + } |
| 44 | + |
| 45 | + client := checkly.NewClient( |
| 46 | + baseUrl, |
| 47 | + apiKey, |
| 48 | + nil, //custom http client, defaults to http.DefaultClient |
| 49 | + nil, //io.Writer to output debug messages |
| 50 | + ) |
| 51 | + |
| 52 | + client.SetAccountId(accountId) |
| 53 | + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) |
| 54 | + defer cancel() |
| 55 | + |
| 56 | + returnedCheck, err := client.Get(ctx, checklyID) |
| 57 | + if err != nil { |
| 58 | + setupLog.Error(err, "failed to get check") |
| 59 | + os.Exit(1) |
| 60 | + } |
| 61 | + |
| 62 | + fmt.Printf("%+v", returnedCheck) |
| 63 | + |
| 64 | +} |
0 commit comments