Some end to end flow working

This commit is contained in:
Dillon Shook
2024-10-22 22:56:06 -04:00
parent f6ce2d8c84
commit e88be84fda
4 changed files with 66 additions and 50 deletions

View File

@@ -2,10 +2,18 @@ currentDateTime=$(date +"%Y-%m-%dT%H:%M")
for logFile in /var/log/nginx-shared/*.log; do
# Ensure the log isn't empty
if [ -s $logFile ]; then
rotatedLog="$logFile-$currentDateTime.log"
report="$logFile-$currentDateTime.html"
filename=$(basename "$logFile")
appName=${filename%%--*}
appPath="/var/log/nginx-shared/$appName"
# Make directory for all the reports to live in
mkdir -p $appPath
rotatedLog="$logFile--$currentDateTime.log"
report="$appPath/$filename--$currentDateTime.html"
if [ -f "$report" ]; then
echo "$report already exists, skipping"

View File

@@ -351,20 +351,16 @@ router.get('/goaccess/:appName/files', function (req, res, next) {
return
}
let appDefinition: IAppDef
return Promise.resolve()
.then(function () {
// Ensure a valid appName parameter
return dataStore.getAppsDataStore().getAppDefinition(appName)
})
.then(function (resolvedAppDefinition) {
appDefinition = resolvedAppDefinition
.then(function () {
// Request the autoindex json that has all the generated reports
const url = `http://${CaptainConstants.nginxServiceName}/goaccess/${appName}`
// Request the autoindex file that has all the generated reports
const url = `http://${CaptainConstants.nginxServiceName}/goaccess`
return new Promise<string[]>(function (resolve, reject) {
return new Promise<any[]>(function (resolve, reject) {
request(url, function (error, response, body) {
if (error || !body) {
Logger.e(`Error ${error}`)
@@ -377,45 +373,32 @@ router.get('/goaccess/:appName/files', function (req, res, next) {
return
}
const lines = body.split('\n')
const linkRegex = /\<a href=\"(.*?)\"/g
const data = []
for (const line of lines) {
const match = linkRegex.exec(line)
if (match) {
data.push(match[1])
}
try {
resolve(JSON.parse(body))
} catch (e) {
console.error('what', { url, body })
Logger.e(`Error parsing ${e}`)
reject(
ApiStatusCodes.createError(
ApiStatusCodes.STATUS_ERROR_GENERIC,
'Request to list goaccess files Failed.'
)
)
}
resolve(data)
})
})
})
.then(function (linkData) {
//Filter to just the generated files for the particular app
const customDomains = appDefinition.customDomain.map(
(d) => d.publicDomain
)
console.log('Filtering link data', {
linkData,
appName,
customDomains,
})
return linkData.filter(
(l) =>
(l.startsWith(appName) ||
customDomains.some((d) => l.startsWith(d))) &&
l.endsWith('.html')
)
})
.then(function (linkData) {
const baseApi = new BaseApi(
ApiStatusCodes.STATUS_OK,
'GoAccess info retrieved'
)
baseApi.data = linkData
baseApi.data = linkData.map((d) => ({
...d,
url: `http://${
CaptainConstants.configs.captainSubDomain
}.${dataStore.getRootDomain()}/goaccess/${appName}/${d.name}`,
}))
res.send(baseApi)
})
.catch(ApiStatusCodes.createCatcher(res))

View File

@@ -318,7 +318,10 @@ class LoadBalancerManager {
nginxConfigTemplate
serverWithSubDomain.httpBasicAuth = httpBasicAuth
serverWithSubDomain.logAccessPath = logAccess
? self.getLogPath(serverWithSubDomain.publicDomain)
? self.getLogPath(
appName,
serverWithSubDomain.publicDomain
)
: undefined
if (
@@ -352,7 +355,7 @@ class LoadBalancerManager {
customErrorPagesDirectory: '',
httpBasicAuth: httpBasicAuth,
logAccessPath: logAccess
? self.getLogPath(d.publicDomain)
? self.getLogPath(appName, d.publicDomain)
: undefined,
}
if (
@@ -391,9 +394,8 @@ class LoadBalancerManager {
)
}
getLogPath(domainName: string) {
// The shared volume path plus a filesafe name
return `${CaptainConstants.nginxSharedLogsPath}/${domainName}-access.log`
getLogPath(appName: string, domainName: string) {
return `${CaptainConstants.nginxSharedLogsPath}/${appName}--${domainName}--access.log`
}
getInfo() {

View File

@@ -32,20 +32,21 @@
location /goaccess {
alias <%-captain.logAccessPath%>;
autoindex on;
autoindex_format json;
# This can be improved by adding authentication as well.
# CIDR Range IPs:
allow 172.16.0.0/12;
allow 10.0.0.0/8;
allow 192.168.0.0/16;
# allow 172.16.0.0/12;
# allow 10.0.0.0/8;
# allow 192.168.0.0/16;
deny all;
# deny all;
}
<%
}
%>
location / {
root <%-captain.defaultHtmlDir%>;
index index.html index.htm;
@@ -137,6 +138,28 @@
location /.well-known/captain-identifier {
root <%-captain.staticWebRoot%>;
}
<%
if (captain.logAccessPath) {
%>
location /goaccess {
alias <%-captain.logAccessPath%>;
autoindex on;
autoindex_format json;
# This can be improved by adding authentication as well.
# CIDR Range IPs:
# allow 172.16.0.0/12;
# allow 10.0.0.0/8;
# allow 192.168.0.0/16;
# deny all;
}
<%
}
%>
}