Skip to content

Instantly share code, notes, and snippets.

@rylnd
Created December 16, 2022 20:41
Show Gist options
  • Select an option

  • Save rylnd/64229f8615ad45f389e3a60da57bf9b1 to your computer and use it in GitHub Desktop.

Select an option

Save rylnd/64229f8615ad45f389e3a60da57bf9b1 to your computer and use it in GitHub Desktop.
Scoring Pseudocode
const RiskReasonLocation = '.alerts*' // configurable in future
const IdentifierMapping = [
{sourceField: 'host.name', entityField: 'host.name'},
{sourceField: 'user.name', entityField: 'user.name'},
]; // configurable in future
for (Identifier of IdentifierMapping) {
GET(`${RiskReasonLocation}/_search`, {
'event.type': 'risk_reason',
[Identifier.sourceField]: '*',
group_by: Identifier.sourceField
}).map((group) => {
const value = group.bucket;
const reimanWeightingFn = generateWeightingFn(group.items);
const score = group.items.reduce((sum, score) => {
// decay factor based on age
// sort by modified score
// apply riemann zeta fn to obtain a weight
// apply riemann weight to score_after_decay
// sum weighted score_after_decays
normalizedScore = score * decay_factor;
normalizedScore *= riemanWeightingFn(score);
sum += normalizedScore;
})
return {
id_field: Identifier.entityField,
id_value: value,
score,
'@timestamp': Date.now(),
'risk.reasons': group.items.map(_id)
}
}).map(RiskScoreClient.write)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment