Skip to content

Instantly share code, notes, and snippets.

@jonarddoci
Created August 27, 2016 20:12
Show Gist options
  • Save jonarddoci/0586c67eae661daf69dda56976323042 to your computer and use it in GitHub Desktop.
Save jonarddoci/0586c67eae661daf69dda56976323042 to your computer and use it in GitHub Desktop.
create opsgenie alerts using a waterfall model with delay in between
var opsgenie = require("opsgenie-sdk");
opsgenie.configure({
'api_key': '0d3deae3-a362-4c79-b485-dfd1ad56947c',
'host': "http://127.0.0.1:9000"
});
function waterfall(func, timeout, iterations, index){
console.log(index);
if(index == iterations){
process.exit(1);
return;
}
setTimeout(function(){
func();
waterfall(func, timeout, iterations, index+1);
}, timeout);
}
var createAlert = function(){
var create_alert_json = {
"message": "Test alert"+"_"+(new Date()).getTime()
};
console.log("alert will be created ", create_alert_json);
opsgenie.alert.create(create_alert_json, function (error, alert) {
if (error) {
console.log(error);
} else {
console.log("alert created");
}
});
}
waterfall(createAlert, 50, 5000, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment