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


Golang OpsGenieClient.SetAPIKey方法代码示例

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


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

示例1: 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

示例2: 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

示例3: main

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

	escCli, cliErr := cli.Escalation()

	if cliErr != nil {
		panic(cliErr)
	}

	req := esc.GetEscalationRequest{Name: ""}
	response, escErr := escCli.Get(req)

	if escErr != nil {
		panic(escErr)
	}

	fmt.Printf("Id: %s\n", response.Id)
	fmt.Printf("Name: %s\n", response.Name)
	fmt.Printf("Team: %s\n", response.Team)
	fmt.Printf("Rules:\n")
	for _, rule := range response.Rules {
		fmt.Printf("Delay: %d\n", rule.Delay)
		fmt.Printf("Notify: %s\n", rule.Notify)
		fmt.Printf("NotifyType: %s\n", rule.NotifyType)
		fmt.Printf("NotifyCondition: %s\n", rule.NotifyCondition)
		fmt.Printf("\n")
	}

}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:30,代码来源:escalation_get.go

示例4: main

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

	teamCli, cliErr := cli.Team()

	if cliErr != nil {
		panic(cliErr)
	}

	req := team.ListTeamLogsRequest{Name: ""}
	response, teamErr := teamCli.ListLogs(req)

	if teamErr != nil {
		panic(teamErr)
	}

	fmt.Printf("Last Key: %s\n", response.LastKey)
	for _, log := range response.Logs {
		fmt.Printf("Log: %s\n", log.Log)
		fmt.Printf("Owner: %s\n", log.Owner)
		fmt.Printf("CreatedAt: %d\n", log.CreatedAt)
		fmt.Printf("\n")
	}
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:25,代码来源:team_list_team_logs.go

示例5: main

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

	integrationCli, cliErr := cli.Integration()

	if cliErr != nil {
		panic(cliErr)
	}
	//disable integration
	disableReq := itg.DisableIntegrationRequest{Name: constants.IntegrationName}
	_, itgError := integrationCli.Disable(disableReq)

	if itgError != nil {
		panic(itgError)
	}
	fmt.Printf("Integration disabled successfuly\n")

	//enable integration
	enableReq := itg.EnableIntegrationRequest{Name: constants.IntegrationName}
	_, itgError = integrationCli.Enable(enableReq)

	if itgError != nil {
		panic(itgError)
	}
	fmt.Printf("Integration enabled successfuly\n")
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:27,代码来源:enable_disable_integration.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), 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

示例7: 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:rdio,项目名称:consul-alerts,代码行数:33,代码来源:opsgenie-notifier.go

示例8: main

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

	teamCli, cliErr := cli.Team()

	if cliErr != nil {
		panic(cliErr)
	}

	req := team.GetTeamRequest{Name: ""}
	response, teamErr := teamCli.Get(req)

	if teamErr != nil {
		panic(teamErr)
	}

	fmt.Printf("Id: %s\n", response.Id)
	fmt.Printf("Name: %s\n", response.Name)
	fmt.Printf("Members:\n")

	for _, member := range response.Members {
		fmt.Printf("User: %s\n", member.User)
		fmt.Printf("Role: %s\n", member.Role)
		fmt.Printf("\n")
	}
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:27,代码来源:team_get.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)}
	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

示例10: main

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

	userCli, cliErr := cli.User()

	if cliErr != nil {
		panic(cliErr)
	}

	req := user.GetUserRequest{Username: ""}
	response, userErr := userCli.Get(req)

	if userErr != nil {
		panic(userErr)
	}

	fmt.Printf("Id: %s\n", response.Id)
	fmt.Printf("Username: %s\n", response.Username)
	fmt.Printf("Fullname: %s\n", response.Fullname)
	fmt.Printf("Timezone: %s\n", response.Timezone)
	fmt.Printf("Locale: %s\n", response.Locale)
	fmt.Printf("State: %s\n", response.State)
	fmt.Printf("Escalations: %v\n", response.Escalations)
	fmt.Printf("Schedules: %v\n", response.Schedules)
	fmt.Printf("Role: %v\n", response.Role)
	fmt.Printf("Groups: %v\n", response.Groups)
	fmt.Printf("Contacts: %v\n", response.Contacts)
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:29,代码来源:user_get.go

示例11: main

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

	schCli, cliErr := cli.Schedule()

	if cliErr != nil {
		panic(cliErr)
	}

	restrictions := []sch.Restriction{}
	restriction := sch.Restriction{StartDay: "", StartTime: "", EndDay: "", EndTime: ""}
	restrictions = append(restrictions, restriction)

	rotations := []sch.Rotation{}
	rotation := sch.Rotation{Name: "", StartDate: "", EndDate: "", Participants: []string{""}, RotationType: ""}
	rotations = append(rotations, rotation)

	enabled := true

	req := sch.UpdateScheduleRequest{Id: "", Name: "", Timezone: "", Enabled: &enabled, Rotations: rotations}
	response, userErr := schCli.Update(req)

	if userErr != nil {
		panic(userErr)
	}

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

示例12: main

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

	userCli, cliErr := cli.User()

	if cliErr != nil {
		panic(cliErr)
	}

	req := user.ListUsersRequest{}
	response, userErr := userCli.List(req)

	if userErr != nil {
		panic(userErr)
	}

	for _, user := range response.Users {
		fmt.Printf("Id: %s\n", user.Id)
		fmt.Printf("Username: %s\n", user.Username)
		fmt.Printf("Fullname: %s\n", user.Fullname)
		fmt.Printf("Timezone: %s\n", user.Timezone)
		fmt.Printf("Locale: %s\n", user.Locale)
		fmt.Printf("State: %s\n", user.State)
		fmt.Printf("Escalations: %v\n", user.Escalations)
		fmt.Printf("Schedules: %v\n", user.Schedules)
		fmt.Printf("Role: %v\n", user.Role)
		fmt.Printf("Groups: %v\n", user.Groups)
		fmt.Printf("Contacts: %v\n", user.Contacts)
		fmt.Printf("\n")
	}
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:32,代码来源:user_list.go

示例13: main

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

	policyCli, cliErr := cli.Policy()

	if cliErr != nil {
		panic(cliErr)
	}
	//disable policy
	disableReq := policy.DisablePolicyRequest{Name: constants.PolicyName}
	_, itgError := policyCli.Disable(disableReq)

	if itgError != nil {
		panic(itgError)
	}
	fmt.Printf("Policy disabled successfuly\n")

	//enable policy
	enableReq := policy.EnablePolicyRequest{Name: constants.PolicyName}
	_, itgError = policyCli.Enable(enableReq)

	if itgError != nil {
		panic(itgError)
	}
	fmt.Printf("Policy enabled successfuly\n")
}
开发者ID:tablexi,项目名称:opsgenie-go-sdk,代码行数:27,代码来源:enable_disable_policy.go

示例14: main

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

	teamCli, cliErr := cli.Team()

	if cliErr != nil {
		panic(cliErr)
	}

	members := []team.Member{}
	member := team.Member{User: "", Role: ""}
	members = append(members, member)

	req := team.CreateTeamRequest{Name: "", Members: members}
	response, teamErr := teamCli.Create(req)

	if teamErr != nil {
		panic(teamErr)
	}

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

示例15: 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


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