<commit_before>@notification_rules @resque @processor @notifier
Feature: Notification rules on a per contact basis

  Background:
    Given the following users exist:
      | id  | first_name | last_name | email             | sms          | timezone            |
      | c1  | Malak      | Al-Musawi | <EMAIL> | +61400000001 | Asia/Baghdad        |
      | c2  | Imani      | Farooq    | <EMAIL> | +61400000002 | Europe/Moscow       |
      | c3  | Vera       | Дурейко   | <EMAIL>  | +61400000003 | Europe/Paris        |
      | c4  | Lucia      | Moretti   | <EMAIL> | +61400000004 | Europe/Rome         |
      | c5  | <NAME>  | Wong      | <EMAIL>  | +61400000005 | Asia/Shanghai       |
      | c6  | Jive       | Smith     | <EMAIL>  | +61400000006 | America/Los_Angeles |

    And the following entities exist:
      | id  | name           | contacts |
      | 1   | foo            | c1       |
      | 2   | bar            | c1,c2,c3 |
      | 3   | baz            | c1,c3    |
      | 4   | buf            | c1,c2,c3 |
      | 5   | foo-app-01.xyz | c4,c6    |

    And user c1 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c2 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c3 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c4 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c1 has the following notification rules:
      | entities | unknown_media | warning_media | critical_media   | warning_blackhole | critical_blackhole | time_restrictions |
      |          |               | email         | sms,email        | true              | true               |                   |
      | foo      |               | email         | sms,email        |                   |                    | 8-18 weekdays     |
      | bar      | email         |               | sms,email        | true              |                    |                   |
      | baz      |               | email         | sms,email        |                   |                    |                   |

    And user c2 has the following notification rules:
      | entities | tags | warning_media | critical_media   | warning_blackhole | critical_blackhole |
      |          |      | email         | email            |                   |                    |
      |          |      | sms           | sms              |                   |                    |
      | bar      |      | email         | email,sms        |                   |                    |
      | bar      | wags |               |                  | true              | true               |

    And user c3 has the following notification rules:
      | entities | warning_media | critical_media   | warning_blackhole | critical_blackhole |
      |          | email         | email            |                   |                    |
      | baz      | sms           | sms              |                   |                    |
      | buf      | email         | email            |                   |                    |
      | buf      | sms           | sms              |                   |                    |
      | bar      | email         | email            | true              | true               |

    And user c4 has the following notification rules:
      | tags            | warning_media | critical_media   | time_restrictions |
      |                 |               |                  |                   |
      | xyz, disk, util | sms           | sms              |                   |
      | xyz, ping       | sms,email     | sms,email        | 8-18 weekdays     |

    And user c5 has the following notification rules:
      | unknown_media | critical_media |
      | email         | email, sms     |

    And user c6 has the following notification rules:
      | entities       | tags            | warning_media | critical_media   |
      |                |                 |               |                  |
      | foo-app-01.xyz | check_disk      | email         | email            |

  @time_restrictions @time
  Scenario: Alerts only during specified time restrictions
    Given the timezone is Asia/Baghdad
    And   the time is February 1 2013 6:59
    And   the check is check 'ping' on entity 'foo'
    And   the check is in an ok state
    And   a critical event is received
    Then  no email alerts should be queued for <EMAIL>
    And   the time is February 1 2013 7:01
    And   a critical event is received
    Then  no email alerts should be queued for <EMAIL>
    And   the time is February 1 2013 8:01
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  the time is February 1 2013 12:00
    Then  all alert dropping keys for user c1 should have expired
    When  a critical event is received
    Then  2 email alerts should be queued for <EMAIL>
    When  the time is February 1 2013 17:59
    Then  all alert dropping keys for user c1 should have expired
    When  a critical event is received
    Then  3 email alerts should be queued for <EMAIL>
    When  the time is February 1 2013 18:01
    Then  all alert dropping keys for user c1 should have expired
    When  a critical event is received
    Then  3 email alerts should be queued for <EMAIL>

  Scenario: time restrictions continue to work as expected when a contact changes timezone

  @severity @time
  Scenario: Don't alert when media,severity does not match any matching rule's severity's media
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a warning event is received
    And   60 minutes passes
    And   a warning event is received
    Then  no email alerts should be queued for <EMAIL>

  @severity @time
  Scenario: Recoveries are not affected by notification rules
    Given the check is check 'ping' on entity 'baz'
    And   the check is in an ok state
    When  a critical event is received
    And   5 minutes passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  1 minute passes
    And   an ok event is received
    Then  2 email alerts should be queued for <EMAIL>

  @severity @time
  Scenario: Alerts are sent to media of highest severity reached since last ok
    Given the check is check 'ping' on entity 'baz'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  1 email alert should be queued for <EMAIL>
    And   0 sms alerts should be queued for +61400000001
    When  70 minutes passes
    And   a critical event is received
    And   1 minute passes
    And   a critical event is received
    Then  2 email alerts should be queued for <EMAIL>
    And   1 sms alert should be queued for +61400000001
    When  70 minutes passes
    And   a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  3 email alerts should be queued for <EMAIL>
    And   2 sms alerts should be queued for +61400000001
    When  70 minutes passes
    And   an ok event is received
    Then  4 email alerts should be queued for <EMAIL>
    And   3 sms alerts should be queued for +61400000001

  @severity @time
  Scenario: Alerts only when media,severity matches any matching rule's severity's media with ok->warning->critical->ok
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  no email alerts should be queued for <EMAIL>
    When  a critical event is received
    And   5 minutes passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  1 minute passes
    And   an ok event is received
    Then  2 email alert should be queued for <EMAIL>

  @blackhole @time
  Scenario: Drop alerts matching a general blackhole rule
    Given the check is check 'ping' on entity 'buf'
    And   the check is in an ok state
    When  a critical event is received
    And   1 minute passes
    And   a critical event is received
    Then  0 email alerts should be queued for <EMAIL>

  @blackhole @time
  Scenario: Drop alerts matching a blackhole rule by entity
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  0 email alerts should be queued for <EMAIL>
    And   0 email alerts should be queued for <EMAIL>
    When  an ok event is received
    Then  0 email alerts should be queued for <EMAIL>
    And   0 email alerts should be queued for <EMAIL>

  @blackhole @time
  Scenario: Drop alerts matching a blackhole rule by tags
    Given the check is check 'wags the dog' on entity 'bar'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  0 email alerts should be queued for <EMAIL>
    When  an ok event is received
    Then  0 email alerts should be queued for <EMAIL>

  @intervals @time
  Scenario: Alerts according to custom interval
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a critical event is received
    Then  no email alerts should be queued for <EMAIL>
    When  1 minute passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  10 minutes passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  5 minutes passes<commit_msg>simplify the data being tested to aid debugging<commit_after>@notification_rules @resque @processor @notifier
Feature: Notification rules on a per contact basis

  Background:
    Given the following users exist:
      | id  | first_name | last_name | email             | sms          | timezone            |
      | c1  | Malak      | Al-Musawi | <EMAIL> | +61400000001 | Asia/Baghdad        |
      | c2  | Imani      | Farooq    | <EMAIL> | +61400000002 | Europe/Moscow       |
      | c3  | Vera       | Дурейко   | <EMAIL>  | +61400000003 | Europe/Paris        |
      | c4  | Lucia      | Moretti   | <EMAIL> | +61400000004 | Europe/Rome         |
      | c5  | <NAME>  | Wong      | <EMAIL>  | +61400000005 | Asia/Shanghai       |
      | c6  | Jive       | Smith     | <EMAIL>  | +61400000006 | America/Los_Angeles |

    And the following entities exist:
      | id  | name           | contacts |
      | 1   | foo            | c1       |
      | 2   | bar            | c1,c2,c3 |
      | 3   | baz            | c1,c3    |
      | 4   | buf            | c1,c2,c3 |
      | 5   | foo-app-01.xyz | c4,c6    |
      | 6   | blakes7        | c2       |

    And user c1 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c2 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c3 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c4 has the following notification intervals:
      | email | sms |
      | 15    | 60  |

    And user c1 has the following notification rules:
      | entities | unknown_media | warning_media | critical_media   | warning_blackhole | critical_blackhole | time_restrictions |
      |          |               | email         | sms,email        | true              | true               |                   |
      | foo      |               | email         | sms,email        |                   |                    | 8-18 weekdays     |
      | bar      | email         |               | sms,email        | true              |                    |                   |
      | baz      |               | email         | sms,email        |                   |                    |                   |

    And user c2 has the following notification rules:
      | entities    | tags | warning_media | critical_media   | warning_blackhole | critical_blackhole |
      |             |      | email         | email            |                   |                    |
      |             |      | sms           | sms              |                   |                    |
      | bar,blakes7 |      | email         | email,sms        |                   |                    |
      | bar,blakes7 | wags |               |                  | true              | true               |

    And user c3 has the following notification rules:
      | entities | warning_media | critical_media   | warning_blackhole | critical_blackhole |
      |          | email         | email            |                   |                    |
      | baz      | sms           | sms              |                   |                    |
      | buf      | email         | email            |                   |                    |
      | buf      | sms           | sms              |                   |                    |
      | bar      | email         | email            | true              | true               |

    And user c4 has the following notification rules:
      | tags            | warning_media | critical_media   | time_restrictions |
      |                 |               |                  |                   |
      | xyz, disk, util | sms           | sms              |                   |
      | xyz, ping       | sms,email     | sms,email        | 8-18 weekdays     |

    And user c5 has the following notification rules:
      | unknown_media | critical_media |
      | email         | email, sms     |

    And user c6 has the following notification rules:
      | entities       | tags            | warning_media | critical_media   |
      |                |                 |               |                  |
      | foo-app-01.xyz | check_disk      | email         | email            |

  @time_restrictions @time
  Scenario: Alerts only during specified time restrictions
    Given the timezone is Asia/Baghdad
    And   the time is February 1 2013 6:59
    And   the check is check 'ping' on entity 'foo'
    And   the check is in an ok state
    And   a critical event is received
    Then  no email alerts should be queued for <EMAIL>
    And   the time is February 1 2013 7:01
    And   a critical event is received
    Then  no email alerts should be queued for <EMAIL>
    And   the time is February 1 2013 8:01
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  the time is February 1 2013 12:00
    Then  all alert dropping keys for user c1 should have expired
    When  a critical event is received
    Then  2 email alerts should be queued for <EMAIL>
    When  the time is February 1 2013 17:59
    Then  all alert dropping keys for user c1 should have expired
    When  a critical event is received
    Then  3 email alerts should be queued for <EMAIL>
    When  the time is February 1 2013 18:01
    Then  all alert dropping keys for user c1 should have expired
    When  a critical event is received
    Then  3 email alerts should be queued for <EMAIL>

  Scenario: time restrictions continue to work as expected when a contact changes timezone

  @severity @time
  Scenario: Don't alert when media,severity does not match any matching rule's severity's media
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a warning event is received
    And   60 minutes passes
    And   a warning event is received
    Then  no email alerts should be queued for <EMAIL>

  @severity @time
  Scenario: Recoveries are not affected by notification rules
    Given the check is check 'ping' on entity 'baz'
    And   the check is in an ok state
    When  a critical event is received
    And   5 minutes passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  1 minute passes
    And   an ok event is received
    Then  2 email alerts should be queued for <EMAIL>

  @severity @time
  Scenario: Alerts are sent to media of highest severity reached since last ok
    Given the check is check 'ping' on entity 'baz'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  1 email alert should be queued for <EMAIL>
    And   0 sms alerts should be queued for +61400000001
    When  70 minutes passes
    And   a critical event is received
    And   1 minute passes
    And   a critical event is received
    Then  2 email alerts should be queued for <EMAIL>
    And   1 sms alert should be queued for +61400000001
    When  70 minutes passes
    And   a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  3 email alerts should be queued for <EMAIL>
    And   2 sms alerts should be queued for +61400000001
    When  70 minutes passes
    And   an ok event is received
    Then  4 email alerts should be queued for <EMAIL>
    And   3 sms alerts should be queued for +61400000001

  @severity @time
  Scenario: Alerts only when media,severity matches any matching rule's severity's media with ok->warning->critical->ok
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  no email alerts should be queued for <EMAIL>
    When  a critical event is received
    And   5 minutes passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  1 minute passes
    And   an ok event is received
    Then  2 email alert should be queued for <EMAIL>

  @blackhole @time
  Scenario: Drop alerts matching a general blackhole rule
    Given the check is check 'ping' on entity 'buf'
    And   the check is in an ok state
    When  a critical event is received
    And   1 minute passes
    And   a critical event is received
    Then  0 email alerts should be queued for <EMAIL>

  @blackhole @time
  Scenario: Drop alerts matching a blackhole rule by entity
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    Then  0 email alerts should be queued for <EMAIL>
    And   0 email alerts should be queued for <EMAIL>
    When  an ok event is received
    Then  0 email alerts should be queued for <EMAIL>
    And   0 email alerts should be queued for <EMAIL>

  @blackhole @time
  Scenario: Drop alerts matching a blackhole rule by tags
    Given the check is check 'wags the dog' on entity 'blakes7'
    And   the check is in an ok state
    When  a warning event is received
    And   1 minute passes
    And   a warning event is received
    And show me the lovely log
    Then  0 email alerts should be queued for <EMAIL>
    When  an ok event is received
    Then  0 email alerts should be queued for <EMAIL>

  @intervals @time
  Scenario: Alerts according to custom interval
    Given the check is check 'ping' on entity 'bar'
    And   the check is in an ok state
    When  a critical event is received
    Then  no email alerts should be queued for <EMAIL>
    When  1 minute passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  10 minutes passes
    And   a critical event is received
    Then  1 email alert should be queued for <EMAIL>
    When  5 minutes passes
{'fraction_non_alphanumeric': 0.047007682976142336, 'fraction_numerical': 0.027598059037606145, 'mean_word_length': 1.5893207695327836, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 20, 'word_list_counts': {'cursed_substrings.json': 74, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5899419', 'n_tokens_mistral': 5716, 'n_tokens_neox': 5176, 'n_words': 2359}