Skip to content

Instantly share code, notes, and snippets.

@LeZuse
Created November 8, 2019 16:24
Show Gist options
  • Save LeZuse/c2c6989b418d15576911a0c151042dc6 to your computer and use it in GitHub Desktop.
Save LeZuse/c2c6989b418d15576911a0c151042dc6 to your computer and use it in GitHub Desktop.
Parse out details of enqueued jobs from recovered ElastiCache backup
#!/usr/bin/env node
const fs = require('fs')
const FILE = './bulk.csv';
const data = fs.readFileSync(FILE, 'utf8');
console.log('bytes', data.length)
const lines = data.split('\n');
console.log('lines', lines.length);
// {"class":"IntegrationConversationPersistJob","args":["integrations:zendesk:699bd401-ac9b-4122-b836-51e4fa0a56bd"]}
const reg = /^{.*"class":"([^"]+)".*}$/i;
const hash = {};
const topics = {};
const intercomIntegrations = {};
const spaces = {};
// const m = lines[0].match(reg)
// console.log(m[1])
// {"remora":{},
// "class":"IntercomWebhookParseJob",
// "args":["3577","{\"type\":\"notification_event\",\"app_id\":\"hqausqan\",\"data\":{\"type\":\"notification_event_data\",\"item\":{\"type\":\"conversation\",\"id\":\"24451309861\",\"created_at\":1573166495,\"updated_at\":1573167943,\"user\":{\"type\":\"user\",\"id\":\"5a29b2eb339f24a12ec3ef1d\",\"user_id\":\"1860867\",\"name\":\"Sean\",\"email\":\"sean@launchpadagency.com\",\"do_not_track\":null},\"assignee\":{\"type\":\"admin\",\"id\":\"3263955\",\"name\":\"Mariana Oliveira\",\"email\":\"mariana.oliveira@pipedrive.com\"},\"conversation_message\":{\"type\":\"conversation_message\",\"id\":\"443972426\",\"url\":\"https://thelaunchpadagency.pipedrive.com/pipeline/6/user/everyone\",\"subject\":\"\",\"body\":\"<p>Hi</p>\",\"author\":{\"type\":\"user\",\"id\":\"5a29b2eb339f24a12ec3ef1d\"},\"attachments\":[]},\"conversation_parts\":{\"type\":\"conversation_part.list\",\"conversation_parts\":[{\"type\":\"conversation_part\",\"id\":\"4081523517\",\"part_type\":\"comment\",\"body\":\"<p>for us to confirm if is a browser issue or not</p>\",\"created_at\":1573167943,\"updated_at\":1573167943,\"notified_at\":1573167943,\"assigned_to\":null,\"author\":{\"type\":\"admin\",\"id\":\"3263955\",\"name\":\"Mariana Oliveira\"},\"attachments\":[],\"external_id\":null}],\"total_count\":1},\"conversation_rating\":{},\"open\":true,\"state\":\"open\",\"snoozed_until\":null,\"read\":false,\"metadata\":{},\"tags\":{\"type\":\"tag.list\",\"tags\":[]},\"tags_added\":{\"type\":\"tag.list\",\"tags\":[]},\"links\":{\"conversation_web\":\"https://app.intercom.io/a/apps/hqausqan/conversations/24451309861\"}}},\"links\":{},\"id\":\"notif_e998fd31-2814-413f-998c-be348a2440b8\",\"topic\":\"conversation.admin.replied\",\"delivery_status\":\"pending\",\"delivery_attempts\":1,\"delivered_at\":0,\"first_sent_at\":1573167945,\"created_at\":1573167944,\"self\":null}",47799]}
// \"topic\":\"conversation.admin.noted\"
const reg2 = /^.*"args":\["(\d+)".*\\"topic\\":\\"([^\\"]+)\\".*,(\d+)]}$/i;
function parseIntercomTopic(line) {
const m = line.match(reg2)
if (m && m[1]) {
const intId = m[1];
intercomIntegrations[intId] = (intercomIntegrations[intId] || 0) + 1;
}
if (m && m[2]) {
const topic = m[2];
topics[topic] = (topics[topic] || 0) + 1;
}
if (m && m[3]) {
const spaceId = m[3];
spaces[spaceId] = (spaces[spaceId] || 0) + 1;
}
}
lines.forEach(line => {
const m = line.match(reg);
if (m && m[1]) {
const job = m[1];
hash[job] = (hash[job] || 0) + 1;
// if (job === 'IntercomWebhookParseJob') {
// parseIntercomTopic(line);
// }
}
});
console.log(hash)
// console.log(topics);
// console.log(intercomIntegrations);
// console.log(spaces);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment