阅读本文,您可以获取 Go SDK 告警管理的接口调用示例,实现快速开发。
说明
本文的调用示例包含接口的部分参数。由于参数间可能存在互斥关系,在调用时,请您参考注释,进行调整。
调用接口前,请先完成 Go SDK 的安装及初始化操作。
本节为您介绍告警管理相关接口的功能和调用示例。
您可以调用 CreateImageMonitorRule 接口新建告警规则。详细的参数说明可参见 CreateImageMonitorRule 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_CreateImageMonitorRule(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.CreateImageMonitorRuleReq{ CreateImageMonitorRuleQuery: &imagex.CreateImageMonitorRuleQuery{}, CreateImageMonitorRuleBody: &imagex.CreateImageMonitorRuleBody{}, } resp, err := instance.CreateImageMonitorRule(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 DeleteImageMonitorRules 接口删除告警规则。详细的参数说明可参见 DeleteImageMonitorRules 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_DeleteImageMonitorRules(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.DeleteImageMonitorRulesReq{ DeleteImageMonitorRulesQuery: &imagex.DeleteImageMonitorRulesQuery{}, DeleteImageMonitorRulesBody: &imagex.DeleteImageMonitorRulesBody{}, } resp, err := instance.DeleteImageMonitorRules(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 DeleteImageMonitorRecords 接口删除告警记录。详细的参数说明可参见 DeleteImageMonitorRecords 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_DeleteImageMonitorRecords(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.DeleteImageMonitorRecordsReq{ DeleteImageMonitorRecordsQuery: &imagex.DeleteImageMonitorRecordsQuery{}, DeleteImageMonitorRecordsBody: &imagex.DeleteImageMonitorRecordsBody{}, } resp, err := instance.DeleteImageMonitorRecords(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 UpdateImageMonitorRule 接口更新告警规则。详细的参数说明可参见 UpdateImageMonitorRule 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_UpdateImageMonitorRule(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.UpdateImageMonitorRuleReq{ UpdateImageMonitorRuleQuery: &imagex.UpdateImageMonitorRuleQuery{}, UpdateImageMonitorRuleBody: &imagex.UpdateImageMonitorRuleBody{}, } resp, err := instance.UpdateImageMonitorRule(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 UpdateImageMonitorRuleStatus 接口更新告警规则状态。详细的参数说明可参见 UpdateImageMonitorRuleStatus 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_UpdateImageMonitorRuleStatus(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.UpdateImageMonitorRuleStatusReq{ UpdateImageMonitorRuleStatusQuery: &imagex.UpdateImageMonitorRuleStatusQuery{}, UpdateImageMonitorRuleStatusBody: &imagex.UpdateImageMonitorRuleStatusBody{}, } resp, err := instance.UpdateImageMonitorRuleStatus(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetImageMonitorRules 接口获取所有告警规则。详细的参数说明可参见 GetImageMonitorRules 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetImageMonitorRules(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetImageMonitorRulesQuery{} resp, err := instance.GetImageMonitorRules(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetImageAlertRecords 接口获取所有告警记录。详细的参数说明可参见 GetImageAlertRecords 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetImageAlertRecords(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetImageAlertRecordsReq{ GetImageAlertRecordsQuery: &imagex.GetImageAlertRecordsQuery{}, GetImageAlertRecordsBody: &imagex.GetImageAlertRecordsBody{}, } resp, err := instance.GetImageAlertRecords(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }