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) }
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) }
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) }
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") } }
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) }
func main() { cli := new(ogcli.OpsGenieClient) cli.SetAPIKey(constants.APIKey) hbCli, cliErr := cli.Heartbeat() if cliErr != nil { panic(cliErr) } // create the hb req := hb.AddHeartbeatRequest{Name: samples.RandStringWithPrefix("Test", 4)} response, hbErr := hbCli.Add(req) if hbErr != nil { panic(hbErr) } fmt.Printf("Heartbeat added\n") fmt.Printf("---------------\n") fmt.Printf("name: %s\n", response.Name) fmt.Printf("status: %s\n", response.Status) fmt.Printf("code: %d\n", response.Code) // update the newly created heart beat, change description updateReq := hb.UpdateHeartbeatRequest{Name: response.Name, Description: "new description"} updateResp, updateErr := hbCli.Update(updateReq) if updateErr != nil { panic(updateErr) } fmt.Printf("Heartbeat updated\n") fmt.Printf("-----------------\n") fmt.Printf("name: %s\n", updateResp.Name) fmt.Printf("status: %s\n", updateResp.Status) fmt.Printf("code: %d\n", updateResp.Code) getReq := hb.GetHeartbeatRequest{Name: response.Name} getResp, getErr := hbCli.Get(getReq) if getErr != nil { panic(getErr) } fmt.Printf("Heartbeat details\n") fmt.Printf("-----------------\n") fmt.Printf("Name: %s\n", getResp.Name) fmt.Printf("Description: %s\n", getResp.Description) }
func main() { cli := new(ogcli.OpsGenieClient) cli.SetAPIKey(constants.APIKey) hbCli, cliErr := cli.Heartbeat() if cliErr != nil { panic(cliErr) } // create the hb req := hb.AddHeartbeatRequest{Name: samples.RandStringWithPrefix("Test", 4)} response, hbErr := hbCli.Add(req) if hbErr != nil { panic(hbErr) } fmt.Printf("Heartbeat created\n") fmt.Printf("-----------------\n") fmt.Printf("id: %s\n", response.ID) fmt.Printf("status: %s\n", response.Status) fmt.Printf("code: %d\n", response.Code) // list the HBs listReq := hb.ListHeartbeatsRequest{} listResp, listErr := hbCli.List(listReq) if listErr != nil { panic(listErr) } fmt.Printf("Heartbeats\n") fmt.Printf("-----------------\n") beats := listResp.Heartbeats for _, beat := range beats { fmt.Printf("Id: %s\n", beat.ID) fmt.Printf("Name: %s\n", beat.Name) fmt.Printf("Status %s\n", beat.Status) fmt.Printf("Description: %s\n", beat.Description) fmt.Printf("Enabled?: %t\n", beat.Enabled) fmt.Printf("Last Heartbeat: %d\n", beat.LastHeartbeat) fmt.Printf("Interval: %d\n", beat.Interval) fmt.Printf("Interval Unit: %s\n", beat.IntervalUnit) fmt.Printf("Expired?: %t\n", beat.Expired) fmt.Printf("-----------------\n") } }
func main() { cli := new(ogcli.OpsGenieClient) cli.SetAPIKey(constants.APIKey) hbCli, cliErr := cli.Heartbeat() if cliErr != nil { panic(cliErr) } // create the hb req := hb.AddHeartbeatRequest{Name: samples.RandStringWithPrefix("Test", 4)} response, hbErr := hbCli.Add(req) if hbErr != nil { panic(hbErr) } fmt.Printf("Heartbeat created\n") fmt.Printf("-----------------\n") fmt.Printf("id: %s\n", response.ID) fmt.Printf("status: %s\n", response.Status) fmt.Printf("code: %d\n", response.Code) // enable the hb getReq := hb.GetHeartbeatRequest{ID: response.ID} getResp, getErr := hbCli.Get(getReq) if getErr != nil { panic(getErr) } fmt.Printf("Heartbeat details\n") fmt.Printf("-----------------\n") fmt.Printf("Id: %s\n", getResp.ID) fmt.Printf("Name: %s\n", getResp.Name) fmt.Printf("Status: %s\n", getResp.Status) fmt.Printf("Description: %s\n", getResp.Description) fmt.Printf("Enabled?: %t\n", getResp.Enabled) fmt.Printf("Last Heartbeat: %d\n", getResp.LastHeartbeat) fmt.Printf("Interval: %d\n", getResp.Interval) fmt.Printf("Interval Unit: %s\n", getResp.IntervalUnit) fmt.Printf("Expired?: %t\n", getResp.Expired) }
func main() { cli := new(ogcli.OpsGenieClient) cli.SetAPIKey(constants.APIKey) hbCli, cliErr := cli.Heartbeat() if cliErr != nil { panic(cliErr) } hbName := samples.RandStringWithPrefix("Test", 4) // create the hb req := hb.AddHeartbeatRequest{Name: hbName} response, hbErr := hbCli.Add(req) if hbErr != nil { panic(hbErr) } fmt.Printf("Heartbeat added\n") fmt.Printf("---------------\n") fmt.Printf("id: %s\n", response.ID) fmt.Printf("status: %s\n", response.Status) fmt.Printf("code: %d\n", response.Code) // send heart beat request sendReq := hb.SendHeartbeatRequest{Name: hbName} sendResp, sendErr := hbCli.Send(sendReq) if sendErr != nil { panic(sendErr) } fmt.Printf("Heartbeat request sent\n") fmt.Printf("----------------------\n") fmt.Printf("Heartbeat: %d\n", sendResp.Heartbeat) fmt.Printf("Will expire at: %d\n", sendResp.WillExpireAt) fmt.Printf("Status: %s\n", sendResp.Status) fmt.Printf("Code: %d\n", sendResp.Code) }
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) }
func main() { cli := new(ogcli.OpsGenieClient) cli.SetAPIKey(constants.APIKey) hbCli, cliErr := cli.Heartbeat() if cliErr != nil { panic(cliErr) } // create the hb req := hb.AddHeartbeatRequest{Name: samples.RandStringWithPrefix("Test", 4)} response, hbErr := hbCli.Add(req) if hbErr != nil { panic(hbErr) } fmt.Printf("name: %s\n", response.Name) fmt.Printf("status: %s\n", response.Status) fmt.Printf("code: %d\n", response.Code) }
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) } }
func main() { cli := new(ogcli.OpsGenieClient) cli.SetAPIKey(constants.APIKey) hbCli, cliErr := cli.Heartbeat() if cliErr != nil { panic(cliErr) } // create the hb req := hb.AddHeartbeatRequest{Name: samples.RandStringWithPrefix("Test", 4)} response, hbErr := hbCli.Add(req) if hbErr != nil { panic(hbErr) } fmt.Printf("Heartbeat created\n") fmt.Printf("-----------------\n") fmt.Printf("id: %s\n", response.ID) fmt.Printf("status: %s\n", response.Status) fmt.Printf("code: %d\n", response.Code) // enable the hb disableReq := hb.DisableHeartbeatRequest{ID: response.ID} disableResp, disableErr := hbCli.Disable(disableReq) if disableErr != nil { panic(disableErr) } fmt.Printf("Heartbeat disabled\n") fmt.Printf("-----------------\n") fmt.Printf("Status: %s\n", disableResp.Status) fmt.Printf("Code: %d\n", disableResp.Code) }