当前位置: 首页>>代码示例>>Golang>>正文


Golang OpsGenieClient.Alert方法代码示例

本文整理汇总了Golang中github.com/opsgenie/opsgenie-go-sdk/client.OpsGenieClient.Alert方法的典型用法代码示例。如果您正苦于以下问题:Golang OpsGenieClient.Alert方法的具体用法?Golang OpsGenieClient.Alert怎么用?Golang OpsGenieClient.Alert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/opsgenie/opsgenie-go-sdk/client.OpsGenieClient的用法示例。


在下文中一共展示了OpsGenieClient.Alert方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// list the alerts
	listreq := alerts.ListAlertsRequest{}
	listresp, listErr := alertCli.List(listreq)

	if listErr != nil {
		panic(listErr)
	}

	for _, alert := range listresp.Alerts {
		fmt.Printf("Id: %s\n", alert.ID)
		fmt.Printf("Alias: %s\n", alert.Alias)
		fmt.Printf("Message: %s\n", alert.Message)
		fmt.Printf("Status: %s\n", alert.Status)
		fmt.Printf("IsSeen?: %t\n", alert.IsSeen)
		fmt.Printf("Acknowledged?: %t\n", alert.Acknowledged)
		fmt.Printf("Created at: %d\n", alert.CreatedAt)
		fmt.Printf("Updated at: %d\n", alert.UpdatedAt)
		fmt.Printf("Tiny id: %s\n", alert.TinyID)
		fmt.Printf("Owner: %s\n", alert.Owner)
	}
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:31,代码来源:alert_listalerts.go

示例2: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// create the alert
	req := alerts.CreateAlertRequest{Message: samples.RandStringWithPrefix("Test", 8)}
	response, alertErr := alertCli.Create(req)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("message: %s\n", response.Message)
	fmt.Printf("alert id: %s\n", response.AlertID)
	fmt.Printf("status: %s\n", response.Status)
	fmt.Printf("code: %d\n", response.Code)

	// add team to the alert
	addTeamReq := alerts.AddTeamAlertRequest{ID: response.AlertID, Team: constants.TeamName}
	addTeamResponse, alertErr := alertCli.AddTeam(addTeamReq)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("status: %s\n", addTeamResponse.Status)
	fmt.Printf("code: %d\n", addTeamResponse.Code)
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:34,代码来源:alert_create_addteam.go

示例3: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// create the alert
	req := alerts.CreateAlertRequest{Message: samples.RandStringWithPrefix("Test", 8), Note: "Created for testing purposes"}
	response, alertErr := alertCli.Create(req)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("message: %s\n", response.Message)
	fmt.Printf("alert id: %s\n", response.AlertID)
	fmt.Printf("status: %s\n", response.Status)
	fmt.Printf("code: %d\n", response.Code)

	// list alert recipients
	getRecipientsReq := alerts.ListAlertRecipientsRequest{ID: response.AlertID}
	getRecipientsResponse, alertErr := alertCli.ListRecipients(getRecipientsReq)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("Users:  %v\n", getRecipientsResponse.Users)
	fmt.Printf("Groups:  %v\n", getRecipientsResponse.Groups)
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:34,代码来源:alert_create_listrecipients.go

示例4: Notify

func (opsgenie *OpsGenieNotifier) Notify(messages Messages) bool {

	overallStatus, pass, warn, fail := messages.Summary()

	client := new(ogcli.OpsGenieClient)
	client.SetApiKey(opsgenie.ApiKey)

	alertCli, cliErr := client.Alert()

	if cliErr != nil {
		log.Println("Opsgenie notification trouble with client")
		return false
	}

	for _, message := range messages {
		title := fmt.Sprintf("\n%s:%s:%s is %s.", message.Node, message.Service, message.Check, message.Status)
		content := fmt.Sprintf(header, opsgenie.ClusterName, overallStatus, fail, warn, pass)
		content += fmt.Sprintf("\n%s:%s:%s is %s.", message.Node, message.Service, message.Check, message.Status)
		content += fmt.Sprintf("\n%s", message.Output)

		// create the alert
		response, alertErr := opsgenie.Send(alertCli, title, content)

		if alertErr != nil {
			log.Println("Opsgenie notification trouble.", response.Status)
			return false
		}

	}

	log.Println("Opsgenie notification send.")
	return true
}
开发者ID:ryane,项目名称:consul-alerts,代码行数:33,代码来源:opsgenie-notifier.go

示例5: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// create the alert
	req := alerts.CreateAlertRequest{Message: samples.RandStringWithPrefix("Test", 8)}
	response, alertErr := alertCli.Create(req)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("message: %s\n", response.Message)
	fmt.Printf("alert id: %s\n", response.AlertID)
	fmt.Printf("status: %s\n", response.Status)
	fmt.Printf("code: %d\n", response.Code)

	// delete the alert
	delreq := alerts.DeleteAlertRequest{ID: response.AlertID, Source: constants.Source}
	cloresponse, alertErr := alertCli.Delete(delreq)
	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("status: %s\n", cloresponse.Status)
	fmt.Printf("code: %d\n", cloresponse.Code)
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:33,代码来源:alert_create_delete.go

示例6: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// create the alert
	req := alerts.CreateAlertRequest{Message: samples.RandStringWithPrefix("Test", 8)}
	response, alertErr := alertCli.Create(req)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("message: %s\n", response.Message)
	fmt.Printf("alert id: %s\n", response.AlertID)
	fmt.Printf("status: %s\n", response.Status)
	fmt.Printf("code: %d\n", response.Code)

	addnotereq := alerts.AddNoteAlertRequest{}
	// add alert ten notes
	for i := 0; i < 10; i++ {
		addnotereq.ID = response.AlertID
		addnotereq.Note = samples.RandString(45)
		addnoteresp, alertErr := alertCli.AddNote(addnotereq)
		if alertErr != nil {
			panic(alertErr)
		}
		fmt.Printf("[Add note] %s %d\n", addnoteresp.Status, addnoteresp.Code)
	}
	listNotesReq := alerts.ListAlertNotesRequest{IF: response.AlertID}
	listNotesResponse, alertErr := alertCli.ListNotes(listNotesReq)
	if alertErr != nil {
		panic(alertErr)
	}

	alertNotes := listNotesResponse.Notes

	fmt.Printf("Last key: %s\n", listNotesResponse.LastKey)
	fmt.Printf("Notes:\n")
	fmt.Printf("------\n")

	for _, note := range alertNotes {
		fmt.Printf("Note: %s\n", note.Note)
		fmt.Printf("Owner: %s\n", note.Owner)
		fmt.Printf("Created at: %d\n", note.CreatedAt)
		fmt.Printf("-------------------------\n")
	}
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:53,代码来源:alert_create_addnote_listnotes.go

示例7: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// create the alert
	req := alerts.CreateAlertRequest{Message: samples.RandStringWithPrefix("Test", 8), Note: "Created for testing purposes", User: constants.User}
	response, alertErr := alertCli.Create(req)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("message: %s\n", response.Message)
	fmt.Printf("alert id: %s\n", response.AlertID)
	fmt.Printf("status: %s\n", response.Status)
	fmt.Printf("code: %d\n", response.Code)

	// close the alert
	getreq := alerts.GetAlertRequest{ID: response.AlertID}
	getresponse, alertErr := alertCli.Get(getreq)
	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("tags: %v\n", getresponse.Tags)
	fmt.Printf("count: %d\n", getresponse.Count)
	fmt.Printf("teams: %v\n", getresponse.Teams)
	fmt.Printf("recipients: %v\n", getresponse.Recipients)
	fmt.Printf("tiny id: %s\n", getresponse.TinyID)
	fmt.Printf("alias: %s\n", getresponse.Alias)
	fmt.Printf("entity: %s\n", getresponse.Entity)
	fmt.Printf("id: %s\n", getresponse.ID)
	fmt.Printf("updated at: %d\n", getresponse.UpdatedAt)
	fmt.Printf("message: %s\n", getresponse.Message)
	fmt.Printf("details: %v\n", getresponse.Details)
	fmt.Printf("source: %s\n", getresponse.Source)
	fmt.Printf("description: %s\n", getresponse.Description)
	fmt.Printf("created at: %d\n", getresponse.CreatedAt)
	fmt.Printf("is seen?: %t\n", getresponse.IsSeen)
	fmt.Printf("acknowledged?: %t\n", getresponse.Acknowledged)
	fmt.Printf("owner: %s\n", getresponse.Owner)
	fmt.Printf("actions: %s\n", getresponse.Actions)
	fmt.Printf("system data: %v\n", getresponse.SystemData)
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:50,代码来源:alert_create_get.go

示例8: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// create the alert
	req := alerts.CreateAlertRequest{Message: samples.RandStringWithPrefix("Test", 8)}
	response, alertErr := alertCli.Create(req)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("message: %s\n", response.Message)
	fmt.Printf("alert id: %s\n", response.AlertID)
	fmt.Printf("status: %s\n", response.Status)
	fmt.Printf("code: %d\n", response.Code)

	file, err := os.OpenFile(constants.PathToFile, os.O_RDWR, 0666)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	attachFileReq := alerts.AttachFileAlertRequest{ID: response.AlertID, Attachment: file}
	attachFileResp, attachFileErr := alertCli.AttachFile(attachFileReq)

	if attachFileErr != nil {
		panic(attachFileErr)
	}

	fmt.Printf("Status: %s\n", attachFileResp.Status)
	fmt.Printf("Code: %d\n", attachFileResp.Code)
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:39,代码来源:alert_create_attachfile.go

示例9: main

func main() {
	cli := new(ogcli.OpsGenieClient)
	cli.SetAPIKey(constants.APIKey)

	alertCli, cliErr := cli.Alert()

	if cliErr != nil {
		panic(cliErr)
	}

	// create the alert
	req := alerts.CreateAlertRequest{Message: samples.RandStringWithPrefix("Test", 8), Note: "Created for testing purposes", User: constants.User}
	response, alertErr := alertCli.Create(req)

	if alertErr != nil {
		panic(alertErr)
	}

	fmt.Printf("message: %s\n", response.Message)
	fmt.Printf("alert id: %s\n", response.AlertID)
	fmt.Printf("status: %s\n", response.Status)
	fmt.Printf("code: %d\n", response.Code)

	getLogsReq := alerts.ListAlertLogsRequest{ID: response.AlertID}
	getLogsResponse, alertErr := alertCli.ListLogs(getLogsReq)
	if alertErr != nil {
		panic(alertErr)
	}

	logs := getLogsResponse.Logs
	for _, log := range logs {
		fmt.Printf("Owner: %s\n", log.Owner)
		fmt.Printf("Log: %s\n", log.Log)
		fmt.Printf("Log type: %s\n", log.LogType)
		fmt.Printf("Created at: %d\n", log.CreatedAt)
	}
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:37,代码来源:alert_create_listlogs.go


注:本文中的github.com/opsgenie/opsgenie-go-sdk/client.OpsGenieClient.Alert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。