Skip to content

Commit 36abffc

Browse files
authored
Add ability to filter by teams. (#23)
* Add ability to filter by teams. * Update README with team filter.
1 parent f6fb09e commit 36abffc

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ See "[Generating a General Access REST API Key](https://support.pagerduty.com/do
2020
* **Account Subdomain** - (Required) The subdomain for your PagerDuty account. If your account is https://example.pagerduty.com, you would use "example".
2121
* **PagerDuty API Key** - (Optional) An API key for your PagerDuty account. If not provided, an active session on your subdomain is needed. If a read-only key is provided, then the Acknowledge/Resolve buttons will be non-functional.
2222
* **Filter Users** - (Optional) A list of comma-separated user ID's, which will only trigger notifications for incidents assigned to those users.
23+
* **Filter Teams** - (Optional) A list of comma-separated teams ID's, which will only trigger notifications for incidents assigned to escalation policies that belong to those teams.
2324
* **Filter Services** - (Optional) A list of comma-separated service ID's, which will only trigger notifications for incidents that are part of those services.
2425
* **Include Low Urgency Alerts?** - If checked, then you will receive notifications for low urgency alerts.
2526
* **Remove Ack/Resolve Buttons?** - If checked, the Acknowledge/Resolve buttons are removed from the notification. You should use this if you only wish to provide a read-only API key.

pd-notifier/background/pd-notifier.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function PagerDutyNotifier()
1616
self.requireInteraction = false; // Whether the notification will require user interaction to dismiss.
1717
self.filterServices = null; // ServiceID's of services to only show alerts for.
1818
self.filterUsers = null; // UserID's of users to only show alerts for.
19+
self.filterTeams = null; // TeamID's of teams to only show alerts for.
1920
self.pdapi = null; // Helper for API calls.
2021
self.poller = null; // This points to the interval function so we can clear it if needed.
2122
self.showBadgeUpdates = false; // Whether we show updates on the toolbar badge.
@@ -57,6 +58,7 @@ function PagerDutyNotifier()
5758
pdRequireInteraction: false,
5859
pdFilterServices: null,
5960
pdFilterUsers: null,
61+
pdFilterTeams: null,
6062
pdShowBadgeUpdates: false,
6163
pdBadgeLocation: 'triggered',
6264
},
@@ -71,6 +73,7 @@ function PagerDutyNotifier()
7173
self.requireInteraction = items.pdRequireInteraction;
7274
self.filterServices = items.pdFilterServices;
7375
self.filterUsers = items.pdFilterUsers;
76+
self.filterTeams = items.pdFilterTeams;
7477
self.showBadgeUpdates = items.pdShowBadgeUpdates;
7578
self.badgeLocation = items.pdBadgeLocation;
7679
callback(true);
@@ -169,6 +172,15 @@ function PagerDutyNotifier()
169172
});
170173
}
171174

175+
// Add a team filter if we have one.
176+
if (self.filterTeams && self.filterTeams != null && self.filterTeams != "")
177+
{
178+
self.filterTeams.split(',').forEach(function(s)
179+
{
180+
url = url + 'team_ids[]=' + s + '&';
181+
});
182+
}
183+
172184
return url;
173185
}
174186

pd-notifier/options/options.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,22 @@ <h2>Notification Filters</h2>
4040
<span class="info">Only show notifications for incidents currently assigned to these user(s). Should be one or more user IDs (comma separated, no spaces). </span>
4141
</div>
4242

43+
<div class="option">
44+
<label>Filter Teams</label>
45+
<input id="filter-teams" type="text" size="20" placeholder="P123456,PX4MPLE..." />
46+
<span class="info">Only show notifications for incidents in escalation policies that belong to these team(s). Should be one or more team IDs (comma separated, no spaces). </span>
47+
</div>
48+
4349
<div class="option">
4450
<label>Filter Services</label>
4551
<input id="filter-services" type="text" size="20" placeholder="P123456,PX4MPLE..." />
4652
<span class="info">Only show notifications for incidents from these services. Should be one or more service IDs (comma separated, no spaces). </span>
4753
</div>
4854

55+
<div class="notice">
56+
All filters must be satisfied for you to get a notification. So if you filter by both a user and service, the incident must be in that service and belong to that user for you to get the notification.
57+
</div>
58+
4959
<hr/>
5060
<h2>Customizations</h2>
5161

pd-notifier/options/options.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ document.addEventListener('DOMContentLoaded', function ()
2626
pdRequireInteraction: false,
2727
pdFilterServices: '',
2828
pdFilterUsers: '',
29+
pdFilterTeams: '',
2930
pdShowBadgeUpdates: false,
3031
pdBadgeLocation: ''
3132
},
@@ -41,6 +42,7 @@ document.addEventListener('DOMContentLoaded', function ()
4142
getElement('require-interaction').checked = items.pdRequireInteraction;
4243
getElement('filter-services').value = items.pdFilterServices;
4344
getElement('filter-users').value = items.pdFilterUsers;
45+
getElement('filter-teams').value = items.pdFilterTeams;
4446
getElement('show-badge').checked = items.pdShowBadgeUpdates;
4547

4648
// Default to "Triggered" for badgeLocation.
@@ -80,6 +82,7 @@ document.getElementById('save').addEventListener('click', function ()
8082
pdRequireInteraction: getElement('require-interaction').checked,
8183
pdFilterServices: getElement('filter-services').value,
8284
pdFilterUsers: getElement('filter-users').value,
85+
pdFilterTeams: getElement('filter-teams').value,
8386
pdShowBadgeUpdates: getElement('show-badge').checked,
8487
pdBadgeLocation: badgeLocation
8588
},
@@ -146,7 +149,6 @@ function validateConfiguration()
146149
isValid = false;
147150
}
148151

149-
150152
// Filter users shouldn't have any spaces.
151153
e = getElement('filter-users');
152154
e.value = e.value.replace(/\s+/g, '');
@@ -157,5 +159,15 @@ function validateConfiguration()
157159
isValid = false;
158160
}
159161

162+
// Filter teams shouldn't have any spaces.
163+
e = getElement('filter-teams');
164+
e.value = e.value.replace(/\s+/g, '');
165+
if (e.value !== ""
166+
&& e.value.indexOf(" ") > -1)
167+
{
168+
e.className = "bad";
169+
isValid = false;
170+
}
171+
160172
return isValid;
161173
}

0 commit comments

Comments
 (0)