Skip to content

Commit

Permalink
Update and send logs to webhook endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunoneill-r7 committed Jul 8, 2023
1 parent 406a546 commit 02e966e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
npm-debug.log
npm-debug.log
.env
.github
File renamed without changes.
2 changes: 2 additions & 0 deletions src/apiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export const createCloudflareZoneRecord = async (zoneId, data) => {
};

export const sendWebhookRequest = async (data) => {
if (!WEBHOOK_URL || !WEBHOOK_METHOD) return;

try {
const response = await fetch(WEBHOOK_URL, {
method: WEBHOOK_METHOD,
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getCloudflareZoneRecords,
updateCloudflareZoneRecord,
createCloudflareZoneRecord,
sendWebhookRequest,
} from './apiUtils.js';

const CLOUDFLARE_API_KEY = process.env.CLOUDFLARE_API_KEY;
Expand Down Expand Up @@ -75,6 +76,7 @@ const start = async () => {
});

console.log(`DNS record for ${DNS_URL} has been updated. IP Address: ${updatedDnsRecord.content}, Proxied: ${updatedDnsRecord.proxied}`);
sendWebhookRequest({status: 'success', message: `DNS record for ${DNS_URL} has been updated. IP Address: ${updatedDnsRecord.content}, Proxied: ${updatedDnsRecord.proxied}`});
}
} else {
console.log(`DNS record does not exist for ${DNS_URL}, creating it...`);
Expand All @@ -85,12 +87,14 @@ const start = async () => {
proxied: PROXIED,
});

console.log(`DNS record for ${DNS_URL} has been created. IP Address: ${newRecord.content}`,);
console.log(`DNS record for ${DNS_URL} has been created. IP Address: ${newRecord.content}`);
sendWebhookRequest({status: 'progress', message: `DNS record for ${DNS_URL} has been created. IP Address: ${newRecord.content}`});
}

console.log('Completed, waiting for next scheduled run...\n');
} catch (error) {
console.error('An uncaught error occurred while running. The job will be stopped.', error);
sendWebhookRequest({status: 'error', message: 'An uncaught error occurred while running. The job will be stopped.', error});
job.stop();
}
};
Expand Down

0 comments on commit 02e966e

Please sign in to comment.