Skip to content

Instantly share code, notes, and snippets.

@edulan
Created November 27, 2014 13:47
Show Gist options
  • Save edulan/bccfe1d922b23c86b7a0 to your computer and use it in GitHub Desktop.
Save edulan/bccfe1d922b23c86b7a0 to your computer and use it in GitHub Desktop.
Logentries bulk update for Tags & Alerts
var APP_ID = window.location.pathname.replace("/app/", "");
function appUrl () {
return "https://logentries.com/rest/" + APP_ID;
}
function tagsUrl () {
return appUrl() + "/api/tags";
}
function updateTagUrl (tagId) {
return tagsUrl() + "/" + tagId;
}
function getTags () {
return $.ajax({
url: tagsUrl(),
type: "GET",
dataType: "json"
});
}
function updateTag (tagId, tagData) {
return $.ajax({
url: updateTagUrl(tagId),
data: JSON.stringify(tagData),
type: "PUT",
dataType: "json",
contentType: "application/json;charset=UTF-8",
processData: false
});
}
function setTagData (tagObject, data) {
tagObject["actions"].forEach(function(action) {
action["min_report_period"] = data["min_report_period"];
});
return tagObject;
}
function updateTags (data) {
getTags()
.done(function(response) {
response.tags.forEach(function(tagObject) {
var tagData = setTagData(tagObject, data);
updateTag(tagObject.id, { tag: tagData })
.done(function() {
console.log("Tag updated!");
}).
fail(function() {
console.log("Error updating tag");
});
});
})
.fail(function() {
console.log("Error retrieving tags");
});
}
updateTags({
"min_report_period": "Day"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment