You need to enable JavaScript to run this app.
导航
告警管理
最近更新时间:2024.12.05 16:20:42首次发布时间:2024.12.05 16:20:42

阅读本文,您可以获取 Go SDK 告警管理的接口调用示例,实现快速开发。

说明

本文的调用示例包含接口的部分参数。由于参数间可能存在互斥关系,在调用时,请您参考注释,进行调整。

调用说明

  • 本文提供的接口调用示例均通过 AK 和 SK 初始化实例。
  • 接口的参数说明和错误码等信息可通过接口文档签查看。

前提条件

调用接口前,请先完成 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))
	}
}