Skip to content

Instantly share code, notes, and snippets.

@eurica
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eurica/e4027372b301f0b4e17d to your computer and use it in GitHub Desktop.
Save eurica/e4027372b301f0b4e17d to your computer and use it in GitHub Desktop.
// Some basic interactivity
wind.on('click', 'down', function() {
textfield.text("Paused, up to resume")
count = -1
clearInterval(interval);
});
wind.on('click', 'up', function() {
textfield.text("Contacting PagerDuty")
PDupdate()
clearInterval(interval);
interval = window.setInterval(PDupdate,polling_interval)
});
var user_id = "P304FC8";
var subdomain = "webdemo";
var token = "sVVWs84QqzkXqbvVsetM";
// 2000ms = 2 seconds: about as high as you can get without rate limiting kicking in
var polling_interval = 2000;
updateScreen = function (data) {
new_count = data.total || 0
console.log("Found " + new_count + " incidents from " + count);
if(new_count != count) {
str = ""
if(new_count>count && new_count > 0) {
Vibe.vibrate('short');
str = "Oh dear"
} else if(new_count<count){
Vibe.vibrate('long');
str = "Yay!"
}
count = new_count
textfield.text(count + " incidents\n" + str)
}
}
PDupdate = function(e) {
ajax(
{
url: 'http://'+subdomain+'.pagerduty.com/api/v1/incidents/count?'+
'status=triggered,acknowledged&assigned_to_user='+user_id,
type: 'json',
headers: {
Authorization: 'Token token='+token,
contentType: 'application/json; charset=utf-8'
}
},
updateScreen, // <-- on success run this function
function (error) {
console.log("Error:");
console.log(error); // <-- super high fidelity error logging
}
);
}
// Load a basic screen
wind = new UI.Window();
textfield = new UI.Text({
position: new Vector2(0, 50),
size: new Vector2(144, 30),
font: 'gothic-24-bold',
text: "Contacting PagerDuty",
textAlign: 'center'
});
wind.add(textfield);
wind.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment