/** * Add a PagerDuty notification rule. * * @param name Human-readable name describing the notification rule. * @param every The notification repetition interval. * @param messageTemplate The template used to generate notification. * @param status Status rule the notification rule attempts to match. * @param tagRules List of tag rules the notification rule attempts to match. * @param endpoint The endpoint to use for notification. * @param orgID The ID of the organization that owns this notification rule. * @return Notification rule created */ /// <summary> /// Add a PagerDuty notification rule. /// </summary> /// <param name="name">Human-readable name describing the notification rule.</param> /// <param name="every">The notification repetition interval.</param> /// <param name="messageTemplate">The template used to generate notification.</param> /// <param name="status">Status rule the notification rule attempts to match.</param> /// <param name="tagRules">List of tag rules the notification rule attempts to match.</param> /// <param name="endpoint">The endpoint to use for notification.</param> /// <param name="orgId">The ID of the organization that owns this notification rule</param> /// <returns>Notification rule created</returns> public async Task <PagerDutyNotificationRule> CreatePagerDutyRuleAsync(string name, string every, string messageTemplate, RuleStatusLevel status, List <TagRule> tagRules, PagerDutyNotificationEndpoint endpoint, string orgId) { Arguments.CheckNonEmptyString(name, nameof(name)); Arguments.CheckNonEmptyString(every, nameof(every)); Arguments.CheckNonEmptyString(messageTemplate, nameof(messageTemplate)); Arguments.CheckNotNull(status, nameof(status)); Arguments.CheckNotNull(endpoint, nameof(endpoint)); Arguments.CheckNotNull(tagRules, nameof(tagRules)); Arguments.CheckNonEmptyString(orgId, nameof(orgId)); var rule = new PagerDutyNotificationRule(PagerDutyNotificationRuleBase.TypeEnum.Pagerduty, messageTemplate); return((PagerDutyNotificationRule) await CreateRuleAsync(name, every, status, tagRules, endpoint, orgId, rule)); }
public async Task FindRuleById() { var endpoint = await _notificationEndpointsApi .CreatePagerDutyEndpointAsync(GenerateName("pager-duty"), "https://events.pagerduty.com/v2/enqueue", "secret-key", _orgId); var tagRules = new List <TagRule> { new TagRule(key: "tag_key", value: "tag_value", _operator: TagRule.OperatorEnum.Notequal) }; var name = GenerateName("pagerduty-rule"); var rule = await _notificationRulesApi.CreatePagerDutyRuleAsync( name, "10s", "my-template", RuleStatusLevel.CRIT, tagRules, endpoint, _orgId); PagerDutyNotificationRule found = (PagerDutyNotificationRule)await _notificationRulesApi.FindNotificationRuleByIdAsync(rule.Id); Assert.AreEqual(rule.Id, found.Id); }