-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated at 2024-09-16T08:47:22-04:00
- Loading branch information
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
Submodule core
updated
63 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {AuditEvent, AuditEventName} from 'app/common/AuditEvent'; | ||
import {IAuditLogger} from 'app/server/lib/AuditLogger'; | ||
import {HTTPAuditLogger} from 'app/server/lib/HTTPAuditLogger'; | ||
import moment from 'moment-timezone'; | ||
|
||
export class HECAuditLogger extends HTTPAuditLogger implements IAuditLogger { | ||
protected toJSON<Name extends AuditEventName>({event, timestamp}: AuditEvent<Name>): string { | ||
return JSON.stringify({ | ||
event, | ||
time: toUnixTimestamp(timestamp), | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Converts an ISO 8601 timestamp to a Unix timestamp. | ||
* | ||
* The format of the timestamp is `[seconds].[milliseconds]` (e.g. `"1725459194.123"`), as | ||
* documented [here](https://docs.splunk.com/Documentation/SplunkCloud/latest/Data/FormateventsforHTTPEventCollector#Event_metadata). | ||
*/ | ||
function toUnixTimestamp(timestamp: string): string { | ||
const unixMs = moment(timestamp).format('x'); | ||
return `${unixMs.slice(0, -3)}.${unixMs.slice(-3)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {appSettings} from 'app/server/lib/AppSettings'; | ||
import {HECAuditLogger} from 'app/server/lib/HECAuditLogger'; | ||
|
||
export function configureHECAuditLogger() { | ||
const options = checkHECAuditLogger(); | ||
if (!options) { return undefined; } | ||
|
||
return new HECAuditLogger(options); | ||
} | ||
|
||
export function checkHECAuditLogger() { | ||
const settings = appSettings.section('auditLogger').section('http'); | ||
const endpoint = settings.flag('endpoint').readString({ | ||
envVar: 'GRIST_AUDIT_HTTP_ENDPOINT', | ||
}); | ||
if (!endpoint) { return undefined; } | ||
|
||
const payloadFormat = settings.flag('payloadFormat').readString({ | ||
envVar: 'GRIST_AUDIT_HTTP_PAYLOAD_FORMAT', | ||
}); | ||
if (payloadFormat !== 'hec') { return undefined; } | ||
|
||
const authorizationHeader = settings.flag('authorizationHeader').readString({ | ||
envVar: 'GRIST_AUDIT_HTTP_AUTHORIZATION_HEADER', | ||
censor: true, | ||
}); | ||
|
||
return {endpoint, authorizationHeader}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters