List Users with Bad Notification Rule Settings
List PagerDuty users who have bad Notification Rule settings
by Ryan Hoskin
HTML
<script src="https://eurica.github.io/pdjs/js/pdjs.js"></script>
<div id="users"><strong>Users:</strong><br /></div>
<div id="zero_users"><strong>Users with zero notification rules:</strong><br /></div>
<div id="one_users"><strong>Users with only one notification rule:</strong><br /></div>
<div id="email_users"><strong>Users with only email notification rules:</strong><br /></div>
JavaScript
//List PagerDuty users who have bad Notification Rule settings
PDJS = new PDJSobj({
subdomain: "pdt-ryan",
token: "rSsp2pXK3zijLfcq519v",
})
PDJS.api_all({
res: "users",
data: {
"include[]": "notification_rules"
},
final_success: function(data) {
jQuery.each(data.users, function(index, user) {
console.log(user)
if (user.notification_rules.length == 0) {
$("#zero_users").append(user.name+"<br/>");
}
else if (user.notification_rules.length == 1) {
$("#one_users").append(user.name+"<br/>");
}
else if (user.notification_rules.length >= 1) {
only_email = true;
jQuery.each(user.notification_rules, function(index, notification_rule) {
if (notification_rule.contact_method.type != "email") {
only_email = false;
}
})
if (only_email == true) {
$("#email_users").append(user.name+"<br/>");
}
}
})
},
incremental_success: function(data) {
console.log("Got data");
}
})