Repository navigation
Expand file tree
/
Copy pathExceptionSettings.cs
More file actions
158 lines (130 loc) · 5.8 KB
/
Copy pathExceptionSettings.cs
File metadata and controls
158 lines (130 loc) · 5.8 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using Opserver.Data.Exceptions;
using StackExchange.Exceptional;
using System;
using System.Collections.Generic;
namespace Opserver
{
public class ExceptionsSettings : ModuleSettings
{
public override bool Enabled => Stores.Count > 0;
public override string AdminRole => ExceptionsRoles.Admin;
public override string ViewRole => ExceptionsRoles.Viewer;
public int PageSize { get; set; } = 500;
public List<Store> Stores { get; set; } = new List<Store>();
public List<ExceptionsGroup> Groups { get; set; } = new List<ExceptionsGroup>();
public JiraSettings Jira { get; set; } = new JiraSettings();
public List<string> Applications { get; set; } = new List<string>();
public List<StackTraceSourceLinkPattern> StackTraceReplacements { get; set; } = new List<StackTraceSourceLinkPattern>();
private StackTraceSettings _stackTraceSettings;
public StackTraceSettings StackTraceSettings => _stackTraceSettings ??= GetStackTraceSettings();
/// <summary>
/// How many exceptions before the exceptions are highlighted as a warning in the header, null (default) is ignored
/// </summary>
public int? WarningCount { get; set; }
/// <summary>
/// How many exceptions before the exceptions are highlighted as critical in the header, null (default) is ignored
/// </summary>
public int? CriticalCount { get; set; }
/// <summary>
/// How many seconds a error is considered "recent"
/// </summary>
public int RecentSeconds { get; set; } = 600;
/// <summary>
/// How many recent exceptions before the exceptions are highlighted as a warning in the header, null (default) is ignored
/// </summary>
public int? WarningRecentCount { get; set; }
/// <summary>
/// How many recent exceptions before the exceptions are highlighted as critical in the header, null (default) is ignored
/// </summary>
public int? CriticalRecentCount { get; set; }
/// <summary>
/// Default maximum timeout in milliseconds before giving up on an sources
/// </summary>
public bool EnablePreviews { get; set; } = true;
/// <summary>
/// Count to cache in memory per app, defaults to 5000
/// </summary>
public int PerAppCacheCount { get; set; } = 5000;
public class ExceptionsGroup : ISettingsCollectionItem
{
/// <summary>
/// The name that appears for this group, used as a key for applications
/// </summary>
public string Name { get; set; }
public string Description { get; set; }
public List<string> Applications { get; set; } = new List<string>();
}
public class Store : ISettingsCollectionItem
{
/// <summary>
/// The name that appears for this store, used as a key for applications
/// </summary>
public string Name { get; set; }
public string Description { get; set; }
/// <summary>
/// The name of the table exceptions are stored in. "Exceptions" is the default.
/// </summary>
public string TableName { get; set; }
/// <summary>
/// Whether to include this store in the header total
/// </summary>
public bool IncludeInTotal { get; set; } = true;
/// <summary>
/// Store specific groups, if not specified then the top level groups will be used.
/// </summary>
public List<ExceptionsGroup> Groups { get; set; }
/// <summary>
/// Store specific applications, if not specified then the top level applications will be used.
/// </summary>
public List<string> Applications { get; set; }
/// <summary>
/// Maximum timeout in milliseconds before giving up on this store
/// </summary>
public int? QueryTimeoutMs { get; set; }
/// <summary>
/// How often to poll this store
/// </summary>
public int PollIntervalSeconds { get; set; } = 300;
/// <summary>
/// Connection string for this store's database
/// </summary>
public string ConnectionString { get; set; }
}
private StackTraceSettings GetStackTraceSettings()
{
var result = new StackTraceSettings();
foreach (var str in StackTraceReplacements)
{
if (str.Pattern.HasValue())
{
try
{
result.AddReplacement(str.Pattern, str.Replacement);
}
catch (Exception ex)
{
new Exception($"Unable to parse source link pattern for '{str.Name}': '{str.Pattern}'", ex).Log();
}
}
}
return result;
}
public class StackTraceSourceLinkPattern : ISettingsCollectionItem
{
/// <summary>
/// The name of the deep link pattern.
/// </summary>
public string Name { get; set; }
/// <summary>
/// A regular expression for detecting links in stack traces.
/// Used in conjunction with <see cref="Replacement"/>.
/// </summary>
public string Pattern { get; set; }
/// <summary>
/// A replacement pattern for rendering links from a <see cref="Pattern"/> match.
/// matches via <see cref="Regex.Replace(string, string, string)"/>.
/// </summary>
public string Replacement { get; set; }
}
}
}