Skip to content

Commit

Permalink
Add AnalysisNotScheduledSESTM codeunit and SentinelSetup page
Browse files Browse the repository at this point in the history
This commit adds the AnalysisNotScheduledSESTM codeunit and the SentinelSetup page to the BusinessCentral.Sentinel project. The AnalysisNotScheduledSESTM codeunit is included in the SentinelAdminSESTM permission set, and the SentinelSetup page allows users to configure the Telemetry Logging setting for Sentinel. These changes enhance the functionality and customization options of the application.
  • Loading branch information
StefanMaron committed Jan 31, 2025
1 parent 41f6f64 commit d22f536
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 9 deletions.
3 changes: 2 additions & 1 deletion BusinessCentral.Sentinel/SentinelAdmin.PermissionSet.al
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ permissionset 71180275 SentinelAdminSESTM
codeunit AlertDevScopeExtSESTM = X,
codeunit AlertPteDownloadCodeSESTM = X,
codeunit AlertSESTM = X,
codeunit AnalysisNotScheduledSESTM = X,
codeunit DemoDataExtInProdSESTM = X,
codeunit EvaluationCompanyInProdSESTM = X,
codeunit NonPostNoSeriesGapsSESTM = X,
Expand All @@ -28,5 +29,5 @@ permissionset 71180275 SentinelAdminSESTM
codeunit UserWithSuperSESTM = X,
page AlertListSESTM = X,
page SentinelRuleSetSESTM = X,
codeunit AnalysisNotScheduledSESTM = X;
page SentinelSetup = X;
}
8 changes: 3 additions & 5 deletions BusinessCentral.Sentinel/src/Alert.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ table 71180275 AlertSESTM

Rec.Id := NumberSequence.Next('BCSentinelSESTMAlertId');

Setup.SetLoadFields(Setup.TelemetryLogging);
Setup.ReadIsolation(IsolationLevel::ReadUncommitted);
Setup.SaveGet();
if Setup.TelemetryLogging = Setup.TelemetryLogging::OnRuleLogging then
if Setup.GetTelemetryLoggingSetting(Rec.AlertCode) = Setup.TelemetryLogging::OnRuleLogging then
this.LogUsage();
end;

Expand Down Expand Up @@ -189,7 +186,8 @@ table 71180275 AlertSESTM
CurrSeverity: Enum SeveritySESTM;
begin
SentinelRuleSet.ReadIsolation(IsolationLevel::ReadUncommitted);
if SentinelRuleSet.Get(AlertCodeIn) then

if SentinelRuleSet.Get(AlertCodeIn) and (SentinelRuleSet.Severity <> SentinelRuleSet.Severity::" ") then
CurrSeverity := SentinelRuleSet.Severity
else
CurrSeverity := SeverityIn;
Expand Down
2 changes: 1 addition & 1 deletion BusinessCentral.Sentinel/src/SentinelRuleSet.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ page 71180277 SentinelRuleSetSESTM
{
field(AlertCode; Rec.AlertCode) { }
field(Severity; Rec.Severity) { }
field(TelemetryLogging; Rec.TelemetryLogging) { }
}

}
}
}
5 changes: 5 additions & 0 deletions BusinessCentral.Sentinel/src/SentinelRuleSet.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ table 71180277 SentinelRuleSetSESTM
Caption = 'Severity';
ToolTip = 'The severity level of the alert.';
}
field(4; TelemetryLogging; Enum TelemetryLogging)
{
Caption = 'Telemetry Logging';
ToolTip = 'Specifies how sentinel emits telemetry data.';
}
}

keys
Expand Down
25 changes: 25 additions & 0 deletions BusinessCentral.Sentinel/src/Setup/SentinelSetup.Page.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace STM.BusinessCentral.Sentinel;

page 71180278 SentinelSetup
{
ApplicationArea = All;
Caption = 'Sentinel Setup';
DeleteAllowed = false;
Extensible = false;
PageType = Card;
SourceTable = SentinelSetup;
UsageCategory = Administration;

layout
{
area(Content)
{
group(General)
{
Caption = 'General';

field(TelemetryLogging; Rec.TelemetryLogging) { }
}
}
}
}
22 changes: 21 additions & 1 deletion BusinessCentral.Sentinel/src/Setup/SentinelSetup.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ table 71180278 SentinelSetup
Caption = 'Sentinel Setup';
DataClassification = SystemMetadata;
InherentPermissions = R;
Permissions = tabledata SentinelSetup = RI;
Permissions =
tabledata SentinelRuleSetSESTM = R,
tabledata SentinelSetup = RI;

fields
{
Expand All @@ -18,6 +20,9 @@ table 71180278 SentinelSetup
field(2; TelemetryLogging; Enum TelemetryLogging)
{
Caption = 'Telemetry Logging';
InitValue = Daily;
ToolTip = 'Specifies how sentinel emits telemetry data.';
ValuesAllowed = Daily, OnRuleLogging, Off;
}
}

Expand All @@ -37,4 +42,19 @@ table 71180278 SentinelSetup
end;
end;

internal procedure GetTelemetryLoggingSetting(AlertCode: Enum AlertCodeSESTM): Enum TelemetryLogging
var
SentinelRuleSet: Record SentinelRuleSetSESTM;
begin
SentinelRuleSet.ReadIsolation(IsolationLevel::ReadCommitted);
SentinelRuleSet.SetLoadFields(TelemetryLogging);
if SentinelRuleSet.Get(AlertCode) and (SentinelRuleSet.TelemetryLogging <> SentinelRuleSet.TelemetryLogging::" ") then
exit(SentinelRuleSet.TelemetryLogging);

Rec.SetLoadFields(TelemetryLogging);
Rec.ReadIsolation(IsolationLevel::ReadCommitted);
Rec.SaveGet();
exit(Rec.TelemetryLogging);
end;

}
9 changes: 8 additions & 1 deletion BusinessCentral.Sentinel/src/Setup/TelemetryLogging.Enum.al
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ enum 71180279 TelemetryLogging
Access = Internal;
Extensible = true;


value(0; " ")
{
Caption = ' ', Locked = true;
}
value(1; Daily)
{
Caption = 'Daily';
Expand All @@ -14,4 +17,8 @@ enum 71180279 TelemetryLogging
{
Caption = 'On Rule Logging';
}
value(3; Off)
{
Caption = 'Off';
}
}
4 changes: 4 additions & 0 deletions BusinessCentral.Sentinel/src/Severity.Enum.al
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ enum 71180276 SeveritySESTM
Access = Internal;
Extensible = false;

value(0; " ")
{
Caption = ' ', Locked = true;
}
value(1; Info)
{
Caption = 'Info';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
namespace STM.BusinessCentral.Sentinel;

using STM.BusinessCentral.Sentinel;
using System.Telemetry;

codeunit 71180285 "SentinelTelemetryLoggerSESTM" implements "Telemetry Logger"
{
Access = Internal;
Permissions =
tabledata AlertSESTM = R;

procedure LogMessage(EventId: Text; Message: Text; Verbosity: Verbosity; DataClassification: DataClassification; TelemetryScope: TelemetryScope; CustomDimensions: Dictionary of [Text, Text])
begin
Expand All @@ -19,4 +22,17 @@ codeunit 71180285 "SentinelTelemetryLoggerSESTM" implements "Telemetry Logger"
begin
Sender.Register(SentinelTelemetryLogger);
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Telemetry Management", OnSendDailyTelemetry, '', false, false)]
local procedure LogSentinelTelemetry_OnSendDailyTelemetry()
var
Alert: Record AlertSESTM;
Setup: Record SentinelSetup;
begin
if Alert.FindSet() then
repeat
if Setup.GetTelemetryLoggingSetting(Alert.AlertCode) = Setup.TelemetryLogging::Daily then
Alert.LogUsage();
until Alert.Next() = 0;
end;
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[Full Changelog](https://github.com/StefanMaron/BusinessCentral.Sentinel/compare/1.6.26...HEAD)

- Improve telemetry logging for rules, change logging to daily, give option to disable logging, log to "All" instead of "ExtensionPublisher"
- Ability to completely turn off telemetry
- Ability to control telemetry via ruleset per Alert individually
- Improve Interface documentation

## [1.6.26](https://github.com/StefanMaron/BusinessCentral.Sentinel/tree/1.6.26)
Expand Down

0 comments on commit d22f536

Please # to comment.