|
|
@ -2,19 +2,17 @@ const urlMetadata = require('url-metadata') |
|
|
|
const csv = require('csvtojson') |
|
|
|
const log = console.log |
|
|
|
const { spawnSync } = require( 'child_process' ), |
|
|
|
// uptime = spawnSync( 'uptime', [ '-p' ] )
|
|
|
|
uptime = spawnSync( 'uptime', [ '-s' ] ) |
|
|
|
|
|
|
|
const csvFilePath = 'server-pages.csv' |
|
|
|
// const csvFilePath = 'server-pages-test.csv'
|
|
|
|
|
|
|
|
// consider webpage to be up if stored title matches fetched title
|
|
|
|
const checkIfTitleMatches = obj => { |
|
|
|
return urlMetadata(obj['url']).then(metadata => { // success handler
|
|
|
|
if (metadata.title == obj['siteTitle']) { |
|
|
|
// log(obj['shortUrl'])
|
|
|
|
obj['status'] = 'up' |
|
|
|
} else { |
|
|
|
// console.log(metadata)
|
|
|
|
obj['status'] = 'down' |
|
|
|
} |
|
|
|
return true |
|
|
@ -24,6 +22,7 @@ const checkIfTitleMatches = obj => { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// update all sites' status in JSON
|
|
|
|
const updateSiteStatus = json => { |
|
|
|
const promiseArray = [] |
|
|
|
json.forEach(async function (obj) { |
|
|
@ -37,6 +36,7 @@ const updateSiteStatus = json => { |
|
|
|
} |
|
|
|
|
|
|
|
csv().fromFile(csvFilePath).then(async function (json) { |
|
|
|
// finish updating all sites' status before outputting JSON
|
|
|
|
Promise.all(updateSiteStatus(json)).then(results => { |
|
|
|
const statusJson = { |
|
|
|
"sites": json, |
|
|
|