From 046fd49b069b8c948e071f70e0fcd52674113443 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 12 Sep 2022 08:55:56 +0200 Subject: [PATCH] chg: [periodic_notification] Generate tag trendings for mitre ATTACK if none are provided --- app/Lib/Tools/TrendingTool.php | 4 ++++ app/Model/User.php | 3 ++- app/View/Users/notification_settings.ctp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Lib/Tools/TrendingTool.php b/app/Lib/Tools/TrendingTool.php index 089308569..9cdf1f240 100644 --- a/app/Lib/Tools/TrendingTool.php +++ b/app/Lib/Tools/TrendingTool.php @@ -2,6 +2,9 @@ class TrendingTool { private $eventModel; + public const defaultTagNamespaceForTrends = [ + 'misp-galaxy:mitre-attack-pattern', + ]; public function __construct($eventModel) { @@ -10,6 +13,7 @@ class TrendingTool public function getTrendsForTags(array $events, int $baseDayRange, int $rollingWindows=3, $tagFilterPrefixes=null): array { + $tagFilterPrefixes = $tagFilterPrefixes ?: self::defaultTagNamespaceForTrends; $clusteredTags = $this->__clusterTagsForRollingWindow($events, $baseDayRange, $rollingWindows, $tagFilterPrefixes); $trendAnalysis = $this->__computeTrendAnalysis($clusteredTags); return [ diff --git a/app/Model/User.php b/app/Model/User.php index 6d86b8b37..8caa1cb85 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -1787,9 +1787,10 @@ class User extends AppModel $rollingWindows = 2; $trendAnalysis = $this->Event->getTrendsForTagsFromEvents($events, $this->__periodToDays($period), $rollingWindows, $periodicSettings['trending_for_tags']); + $tagFilterPrefixes = $periodicSettings['trending_for_tags'] ?: array_keys($trendAnalysis['all_tags']); $trendData = [ 'trendAnalysis' => $trendAnalysis, - 'tagFilterPrefixes' => $periodicSettings['trending_for_tags'], + 'tagFilterPrefixes' => $tagFilterPrefixes, ]; $trending_summary = $this->__renderTrendingSummary($trendData); diff --git a/app/View/Users/notification_settings.ctp b/app/View/Users/notification_settings.ctp index 691cb569c..8c1a62011 100644 --- a/app/View/Users/notification_settings.ctp +++ b/app/View/Users/notification_settings.ctp @@ -59,7 +59,7 @@ echo $this->element('genericElements/Form/genericForm', [ 'type' => 'tagsPicker', 'placeholder' => '["tlp:red"]', ], - sprintf('

%s

', __('Notification filters')), + sprintf('

%s

', __('Report settings')), [ 'field' => 'periodic_settings.trending_for_tags', 'label' => __('Generate trends for tag namespaces'),