-
Notifications
You must be signed in to change notification settings - Fork 6
/
delphiDatadog.event.pas
74 lines (60 loc) · 1.89 KB
/
delphiDatadog.event.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
unit delphiDatadog.event;
interface
uses
delphiDatadog.header;
type
TDataDogEvent = class(TObject)
private
FTitle: string;
FText: string;
FMillisSinceEpoch: Int64;
FHostName: string;
FAggregationKey: string;
FPriority: TDataDogEventPriority;
FSourcerTypeName: string;
FAlertType: TDataDogEventAlertType;
public
function ToMap: string;
property Title: string read FTitle write FTitle;
property Text: string read FText write FText;
property MillisSinceEpoch: Int64 read FMillisSinceEpoch write FMillisSinceEpoch;
property HostName: string read FHostName write FHostName;
property AggregationKey: string read FAggregationKey write FAggregationKey;
property Priority: TDataDogEventPriority read FPriority write FPriority;
property SourcerTypeName: string read FSourcerTypeName write FSourcerTypeName;
property AlertType: TDataDogEventAlertType read FAlertType write FAlertType;
end;
implementation
uses
System.SysUtils, delphiDatadog.utils;
{ TDataDogEvent }
function TDataDogEvent.ToMap: string;
var
MapParams: TStringBuilder;
DoubleResult: Double;
PriorityText: string;
AlertText: string;
begin
MapParams := TStringBuilder.Create;
try
if (MillisSinceEpoch <> 0) then
begin
DoubleResult := MillisSinceEpoch / 1000;
MapParams.Append('|d:').Append(DoubleResult);
end;
if not HostName.IsEmpty then
MapParams.Append('|h:').Append(HostName);
if not AggregationKey.IsEmpty then
MapParams.Append('|k:').Append(AggregationKey);
PriorityText := DataTagsEventPriorityToText(Priority);
if not PriorityText.IsEmpty then
MapParams.Append('|p:').Append(PriorityText);
AlertText := DataTagsEventAlertToText(AlertType);
if not AlertText.IsEmpty then
MapParams.Append('|t:').Append(AlertText);
Result := MapParams.ToString;
finally
MapParams.Free;
end;
end;
end.