public void ChangeSeverity( string projectId = "YOUR-PROJECT-ID", string incidentId = "an.opaque.random.id") { // Create client IncidentServiceClient incidentServiceClient = IncidentServiceClient.Create(); // Update the severity. Incident incidentChange = new Incident() { Name = new IncidentName(projectId, incidentId).ToString(), Severity = Severity.Minor, }; // Tell the API which fields to update. FieldMask mask = new FieldMask() { Paths = { "severity" } }; // Call the API to update the incident. var incident = incidentServiceClient.UpdateIncident(incidentChange, mask); Console.WriteLine("Changed severity of {0}.", incident.Name); }
public Signal CreateIncidentWithSignal(string projectId = "YOUR-PROJECT-ID") { // Create client IncidentServiceClient incidentServiceClient = IncidentServiceClient.Create(); // Manually create a signal. Signal newSignal = new Signal() { Title = "Red button pushed.", Content = "Somebody pushed the red button!", ContentType = "text/plain", }; // Call the API to create the signal. string parent = new ProjectName(projectId).ToString(); Signal signal = incidentServiceClient.CreateSignal(parent, newSignal); Console.WriteLine("Created signal {0}.", signal.Name); // Manually create an incident. Incident newIncident = new Incident() { Title = "Somebody pushed the red button!", Synopsis = new Synopsis() { Author = new User() { Email = "*****@*****.**", }, Content = "Nobody should ever push the red button.", ContentType = "text/plain", UpdateTime = DateTime.UtcNow.ToTimestamp() }, Severity = Severity.Major, Stage = Stage.Unspecified }; // Call the API to create the incident. Incident incident = incidentServiceClient.CreateIncident(newIncident, parent); Console.WriteLine("Created incident {0}.", incident.Name); // Call the API to bind the signal to the incident. // TODO: Remove the name hack. signal.Name = signal.Name.Replace("/-/", $"/{projectId}/"); signal.Incident = incident.Name.Replace("/-/", $"/{projectId}/"); signal.Title = "Yellow button pushed!"; FieldMask mask = new FieldMask() { Paths = { "title", "incident" } }; signal = incidentServiceClient.UpdateSignal(signal, mask); return(signal); }
public string CreateSignal(string projectId = "YOUR-PROJECT-ID") { // Create client IncidentServiceClient incidentServiceClient = IncidentServiceClient.Create(); // Describe the signal. Signal signal = new Signal() { Title = "Red button pushed.", Content = "Somebody pushed the red button!", ContentType = "text/plain" }; // Call the API to create the signal. string parent = new ProjectName(projectId).ToString(); Signal response = incidentServiceClient.CreateSignal(parent, signal); Console.WriteLine("Created signal {0}.", response.Name); return(response.Name); }
public void ChangeStageAtomically( string projectId = "YOUR-PROJECT-ID", string incidentId = "an.opaque.random.id") { // Create client IncidentServiceClient incidentServiceClient = IncidentServiceClient.Create(); for (int retry = 0; true; ++retry) { try { // Observe the current state of the incident. Incident incident = incidentServiceClient.GetIncident( new IncidentName(projectId, incidentId).ToString()); Incident incidentChange = new Incident() { // TODO: Remove the name hack. Name = incident.Name.Replace("/-/", $"/{projectId}/"), // Use the ETag to prevent race conditions. Only update the // incident if it hasn't changed since we observed it. Etag = incident.Etag, Stage = Stage.Detected }; // Tell the API which fields to update. FieldMask mask = new FieldMask() { Paths = { "stage" } }; // Call the API to update the incident. incident = incidentServiceClient.UpdateIncident( incidentChange, mask); Console.WriteLine("Changed stage of {0}.", incident.Name); break; } catch (Grpc.Core.RpcException e) when(retry < 3 && e.StatusCode == Grpc.Core.StatusCode.Aborted) { // Somebody else must have updated the incident at the same // time! Try again. } } }
public string AnnotateIncident( string projectId = "YOUR-PROJECT-ID", string incidentId = "an.opaque.random.id") { // Create client IncidentServiceClient incidentServiceClient = IncidentServiceClient.Create(); // Describe the annotation. Annotation newAnnotation = new Annotation() { Content = "The red button was found in a depressed state." }; string parent = new IncidentName(projectId, incidentId).ToString(); // Call the API to create the annotation. Annotation annotation = incidentServiceClient.CreateAnnotation(parent, newAnnotation); Console.WriteLine("Created annotation {0}.", annotation.Name); return(annotation.Name); }