-
Notifications
You must be signed in to change notification settings - Fork 48
/
Program.cs
1963 lines (1602 loc) · 104 KB
/
Program.cs
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using AppDynamics.Dexter.ProcessingSteps;
using CommandLine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;
namespace AppDynamics.Dexter
{
public class Program
{
private static Logger logger = LogManager.GetCurrentClassLogger();
private static Logger loggerConsole = LogManager.GetLogger("AppDynamics.Dexter.Console");
public static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
try
{
logger.Trace("AppDynamics DEXTER Version {0}", Assembly.GetEntryAssembly().GetName().Version);
loggerConsole.Info("AppDynamics DEXTER Version {0}", Assembly.GetEntryAssembly().GetName().Version);
logger.Trace("Starting at local {0:o}/UTC {1:o}, Version={2}, Parameters={3}", DateTime.Now, DateTime.UtcNow, Assembly.GetEntryAssembly().GetName().Version, String.Join(" ", args));
logger.Trace("Timezone {0} {1} {2}", TimeZoneInfo.Local.DisplayName, TimeZoneInfo.Local.StandardName, TimeZoneInfo.Local.BaseUtcOffset);
logger.Trace("Culture {0}({1}), ShortDate={2}, ShortTime={3}, All={4}", CultureInfo.CurrentCulture.DisplayName, CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern, String.Join(";", CultureInfo.CurrentCulture.DateTimeFormat.GetAllDateTimePatterns()));
logger.Trace("Framework {0}", RuntimeInformation.FrameworkDescription);
logger.Trace("OS Architecture {0}", RuntimeInformation.OSArchitecture);
logger.Trace("OS {0}", RuntimeInformation.OSDescription);
logger.Trace("Process Architecture {0}", RuntimeInformation.ProcessArchitecture);
logger.Trace("Number of Processors {0}", Environment.ProcessorCount);
var parserResult = Parser.Default
.ParseArguments<ProgramOptions>(args)
.WithParsed((ProgramOptions programOptions) => { RunProgram(programOptions); })
.WithNotParsed((errs) =>
{
logger.Error("Could not parse command line arguments into ProgramOptions");
//loggerConsole.Error("Could not parse command line arguments into ProgramOptions");
});
}
catch (Exception ex)
{
logger.Error(ex);
loggerConsole.Error(ex);
}
finally
{
stopWatch.Stop();
logger.Info("Application execution took {0:c} ({1} ms)", stopWatch.Elapsed, stopWatch.ElapsedMilliseconds);
loggerConsole.Trace("Application execution took {0:c} ({1} ms)", stopWatch.Elapsed, stopWatch.ElapsedMilliseconds);
// Flush all the logs before shutting down
LogManager.Flush();
}
}
public static void RunProgram(ProgramOptions programOptions)
{
logger.Trace("Executing:\r\n{0}", programOptions);
loggerConsole.Trace("Executing:\r\n{0}", programOptions);
#region Check version and prompt someone
if (programOptions.SkipVersionCheck == false)
{
using (GithubApi githubApi = new GithubApi("https://api.github.com"))
{
loggerConsole.Info("Version check against Github releases");
string listOfReleasesJSON = githubApi.GetReleases();
if (listOfReleasesJSON.Length > 0)
{
JArray releasesListArray = JArray.Parse(listOfReleasesJSON);
if (releasesListArray != null)
{
if (releasesListArray.Count > 0)
{
JObject releaseObject = (JObject)releasesListArray[0];
string latestReleaseVersionString = releaseObject["tag_name"].ToString();
if (latestReleaseVersionString != null && latestReleaseVersionString.Length > 0)
{
try
{
Version latestReleaseVersion = new Version(latestReleaseVersionString);
if (latestReleaseVersion > Assembly.GetEntryAssembly().GetName().Version)
{
// This version is older than what is listed on Github
loggerConsole.Warn("Latest released version is {0}, and yours is {1}. Would you like to upgrade (y/n)?", latestReleaseVersion, Assembly.GetEntryAssembly().GetName().Version);
ConsoleKeyInfo cki = Console.ReadKey();
Console.WriteLine();
if (cki.Key.ToString().ToLower() == "y")
{
loggerConsole.Info("Go to AppDynamics Extensions or to {0} to download new release", releaseObject["html_url"]);
return;
}
}
}
catch (Exception ex)
{
logger.Error(ex);
loggerConsole.Error(ex);
}
}
}
}
}
}
}
#endregion
// Choose type of program to run, ETL or Compare
if (programOptions.InputETLJobFilePath != null && programOptions.InputETLJobFilePath.Length > 0)
{
loggerConsole.Info("Running ETL workload");
RunProgramETL(programOptions);
}
else if (programOptions.RequestIDs != null && programOptions.ReportFolderPath.Length > 0)
{
loggerConsole.Info("Running Individual Snapshots workload");
RunProgramIndividualSnapshots(programOptions);
}
else if (programOptions.InputCompareJobFilePath != null && programOptions.InputCompareJobFilePath.Length > 0)
{
loggerConsole.Info("Running Compare workload");
RunProgramCompare(programOptions);
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Compiler", "CS0168", Justification = "Hiding ArgumentOutOfRangeException and FormatException that may occur when dates are parsed")]
public static void RunProgramETL(ProgramOptions programOptions)
{
#region Validate job file exists and load it
programOptions.InputETLJobFilePath = Path.GetFullPath(programOptions.InputETLJobFilePath);
logger.Info("Checking input ETL job file {0}", programOptions.InputETLJobFilePath);
loggerConsole.Info("Checking input ETL job file {0}", programOptions.InputETLJobFilePath);
if (File.Exists(programOptions.InputETLJobFilePath) == false)
{
logger.Error("ETL job file {0} does not exist", programOptions.InputETLJobFilePath);
loggerConsole.Error("ETL job file {0} does not exist", programOptions.InputETLJobFilePath);
return;
}
// Load job configuration
JobConfiguration jobConfiguration = FileIOHelper.ReadJobConfigurationFromFile(programOptions.InputETLJobFilePath);
if (jobConfiguration == null)
{
logger.Error("Unable to load job input file {0}", programOptions.InputETLJobFilePath);
loggerConsole.Error("Unable to load job input file {0}", programOptions.InputETLJobFilePath);
return;
}
if (jobConfiguration.Input == null)
{
logger.Error("Job File Problem: Input can not be empty");
loggerConsole.Error("Job File Problem: Input can not be empty");
return;
}
if (jobConfiguration.Output == null)
{
logger.Error("Job File Problem: Output can not be empty");
loggerConsole.Error("Job File Problem: Output can not be empty");
return;
}
if (jobConfiguration.Target == null || jobConfiguration.Target.Count == 0)
{
logger.Error("Job File Problem: No targets to work on");
loggerConsole.Error("Job File Problem: No targets to work on");
return;
}
#endregion
#region Validate Input - Time Range
DateTime dateTimeNowOriginal = DateTime.Now;
DateTime dateTimeNowOriginalUtc = dateTimeNowOriginal.ToUniversalTime();
// Validate input time range selection
if (jobConfiguration.Input.TimeFrame != null)
{
#region Validate new style TimeFrame
// Using Timespan https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-timespan-format-strings?view=netcore-3.1#the-constant-c-format-specifier
//"TimeFrame": {
// "MarkDate": "2020-03-20",
// "MarkTime": "10:00:00",
// "Duration": "1:00:00"
//}
// Or using ISO 8601 time interval https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
// Going Forward in time from mark:
//"TimeFrame": {
// "MarkDate": "2020-03-20",
// "MarkTime": "10:00:00",
// "Duration": "PT1H"
//}
// Going Backward in time from mark:
//"TimeFrame": {
// "MarkDate": "2020-03-20",
// "MarkTime": "10:00:00",
// "Duration": "-PT1H"
//}
// The newer type of relative time range specifier in newer job files
if (jobConfiguration.Input.TimeFrame.MarkDate == null || jobConfiguration.Input.TimeFrame.MarkDate.Length == 0)
{
logger.Error("Job File Problem: Input.TimeFrame.MarkDate can not be empty");
loggerConsole.Error("Job File Problem: Input.TimeFrame.MarkDate can not be empty");
return;
}
if (jobConfiguration.Input.TimeFrame.MarkTime == null || jobConfiguration.Input.TimeFrame.MarkTime.Length == 0)
{
logger.Error("Job File Problem: Input.TimeFrame.MarkTime can not be empty");
loggerConsole.Error("Job File Problem: Input.TimeFrame.MarkTime can not be empty");
return;
}
if (jobConfiguration.Input.TimeFrame.Duration == null || jobConfiguration.Input.TimeFrame.Duration.Length == 0)
{
logger.Error("Job File Problem: Input.TimeFrame.Duration can not be empty");
loggerConsole.Error("Job File Problem: Input.TimeFrame.Duration can not be empty");
return;
}
// Parse out date of the point from which we're counting
DateTime markDate = DateTime.MinValue;
if (DateTime.TryParse(jobConfiguration.Input.TimeFrame.MarkDate, null, DateTimeStyles.AssumeLocal, out markDate) == true)
{
//markDate = markDate.ToUniversalTime();
}
else
{
logger.Warn("Job File Problem: Input.TimeFrame.MarkDate={0} is not a valid Date", jobConfiguration.Input.TimeFrame.MarkDate);
DateTimeKind kind = dateTimeNowOriginal.Kind;
string token = jobConfiguration.Input.TimeFrame.MarkDate.ToUpper();
if (jobConfiguration.Input.TimeFrame.MarkDate.ToUpper().EndsWith("_Z") == true)
{
kind = DateTimeKind.Utc;
token = token.Substring(0, token.Length - 2);
}
// Let's try one of the tokens
switch (token)
{
#region Day offsets
case "TODAY":
markDate = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
break;
case "YESTERDAY":
markDate = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind).AddDays(-1);
break;
case "DAY_BEFORE_YESTERDAY":
markDate = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind).AddDays(-2);
break;
case "SAME_DAY_LAST_WEEK":
markDate = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind).AddDays(-7);
break;
#endregion
#region Weekdays
case "MONDAY":
DateTime dateTime_Token_Monday = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
while (dateTime_Token_Monday.DayOfWeek != DayOfWeek.Monday)
{
dateTime_Token_Monday = dateTime_Token_Monday.AddDays(-1);
}
markDate = dateTime_Token_Monday;
break;
case "TUESDAY":
DateTime dateTime_Token_Tuesday = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
while (dateTime_Token_Tuesday.DayOfWeek != DayOfWeek.Tuesday)
{
dateTime_Token_Tuesday = dateTime_Token_Tuesday.AddDays(-1);
}
markDate = dateTime_Token_Tuesday;
break;
case "WEDNESDAY":
DateTime dateTime_Token_Wednesday = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
while (dateTime_Token_Wednesday.DayOfWeek != DayOfWeek.Wednesday)
{
dateTime_Token_Wednesday = dateTime_Token_Wednesday.AddDays(-1);
}
markDate = dateTime_Token_Wednesday;
break;
case "THURSDAY":
DateTime dateTime_Token_Thursday = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
while (dateTime_Token_Thursday.DayOfWeek != DayOfWeek.Thursday)
{
dateTime_Token_Thursday = dateTime_Token_Thursday.AddDays(-1);
}
markDate = dateTime_Token_Thursday;
break;
case "FRIDAY":
DateTime dateTime_Token_Friday = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
while (dateTime_Token_Friday.DayOfWeek != DayOfWeek.Friday)
{
dateTime_Token_Friday = dateTime_Token_Friday.AddDays(-1);
}
markDate = dateTime_Token_Friday;
break;
case "SATURDAY":
DateTime dateTime_Token_Saturday = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
while (dateTime_Token_Saturday.DayOfWeek != DayOfWeek.Saturday)
{
dateTime_Token_Saturday = dateTime_Token_Saturday.AddDays(-1);
}
markDate = dateTime_Token_Saturday;
break;
case "SUNDAY":
DateTime dateTime_Token_Sunday = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
while (dateTime_Token_Sunday.DayOfWeek != DayOfWeek.Sunday)
{
dateTime_Token_Sunday = dateTime_Token_Sunday.AddDays(-1);
}
markDate = dateTime_Token_Sunday;
break;
#endregion
default:
// Day of Month?
if (token.StartsWith("DAY_OF_MONTH") == true)
{
string tokenWithoutZ = token.Replace("_Z", "");
string dayOfMonthToken = tokenWithoutZ.Substring("DAY_OF_MONTH_".Length);
int dayOfMonth = -1;
if (Int32.TryParse(dayOfMonthToken, out dayOfMonth) == false)
{
logger.Error("Job File Problem: Input.TimeFrame.MarkDate={0} is not a valid day of month token", jobConfiguration.Input.TimeFrame.MarkDate);
}
else
{
if (dayOfMonth < 1 || dayOfMonth > 31)
{
logger.Error("Job File Problem: Input.TimeFrame.MarkDate={0} is not a valid day of month token", jobConfiguration.Input.TimeFrame.MarkDate);
}
else
{
// Got a day of the month in range of 1..31
// The months are all different in size. Let's find that day. If we're in the month with 30 days and we are on day 31, we'll go to 30
DateTime dateTime_Token_Today = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
0, 0, 0,
kind);
DateTime dateTime_Token_ThisDay_ThisMonth = DateTime.MinValue;
bool parsedDayThisMonth = false;
while (parsedDayThisMonth == false)
{
try
{
dateTime_Token_ThisDay_ThisMonth = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dayOfMonth,
0, 0, 0,
kind);
parsedDayThisMonth = true;
}
catch (ArgumentOutOfRangeException ex)
{
// Date out of range
dayOfMonth--;
}
}
if (dateTime_Token_ThisDay_ThisMonth > dateTime_Token_Today)
{
// This day is in the future. Must go back
markDate = dateTime_Token_ThisDay_ThisMonth.AddMonths(-1);
}
else
{
// This day of month is today or in the past. Take it
markDate = dateTime_Token_ThisDay_ThisMonth;
}
}
}
}
else
{
logger.Error("Job File Problem: Input.TimeFrame.MarkDate={0} is not a valid token", jobConfiguration.Input.TimeFrame.MarkDate);
}
break;
}
}
if (markDate == DateTime.MinValue)
{
loggerConsole.Error("Job File Problem: Input.TimeFrame.MarkDate={0} is not a valid Date or recognized token", jobConfiguration.Input.TimeFrame.MarkDate);
return;
}
// Parse out time of the point from which we're counting
DateTime markTime = DateTime.MinValue;
if (DateTime.TryParse(jobConfiguration.Input.TimeFrame.MarkTime, null, DateTimeStyles.AssumeLocal, out markTime) == true)
{
//markTime = markTime.ToUniversalTime();
}
else
{
logger.Warn("Job File Problem: Input.TimeFrame.MarkTime={0} is not a valid Time", jobConfiguration.Input.TimeFrame.MarkTime);
// Let's try one of the tokens
switch (jobConfiguration.Input.TimeFrame.MarkTime.ToUpper())
{
case "NOW":
// Round the time out to the beginning of the minute
markTime = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
dateTimeNowOriginal.Hour,
dateTimeNowOriginal.Minute,
0,
dateTimeNowOriginal.Kind);
break;
case "NOW_Z":
// Round the time out to the beginning of the minute
markTime = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
dateTimeNowOriginal.ToUniversalTime().Hour,
dateTimeNowOriginal.ToUniversalTime().Minute,
0,
DateTimeKind.Utc);
break;
case "CURRENT_HOUR":
// Round the time out to the beginning of hour
markTime = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
dateTimeNowOriginal.Hour,
0,
0,
dateTimeNowOriginal.Kind);
break;
case "CURRENT_HOUR_Z":
// Round the time out to the beginning of hour
markTime = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
dateTimeNowOriginal.ToUniversalTime().Minute,
0,
0,
DateTimeKind.Utc);
break;
case "PREVIOUS_HOUR":
// Round the time out to the beginning of past
markTime = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
dateTimeNowOriginal.Hour,
0,
0,
dateTimeNowOriginal.Kind).AddHours(-1);
break;
case "PREVIOUS_HOUR_Z":
// Round the time out to the beginning of past
markTime = new DateTime(
dateTimeNowOriginal.Year,
dateTimeNowOriginal.Month,
dateTimeNowOriginal.Day,
dateTimeNowOriginal.ToUniversalTime().Hour,
0,
0,
DateTimeKind.Utc).AddHours(-1);
break;
default:
logger.Warn("Job File Problem: Input.TimeFrame.MarkTime={0} is not a valid token", jobConfiguration.Input.TimeFrame.MarkTime);
break;
}
}
if (markTime == DateTime.MinValue)
{
loggerConsole.Error("Job File Problem: Input.TimeFrame.MarkTime={0} is not a valid Time or recognized token", jobConfiguration.Input.TimeFrame.MarkTime);
return;
}
// Parse out duration, first the .NET
TimeSpan duration = new TimeSpan(0, 0, 0);
if (TimeSpan.TryParse(jobConfiguration.Input.TimeFrame.Duration, out duration) == false)
{
// Not a Timespan
logger.Warn("Job File Problem: Input.TimeFrame.Duration={0} is not a valid TimeSpan", jobConfiguration.Input.TimeFrame.Duration);
loggerConsole.Warn("Job File Problem: Input.TimeFrame.Duration={0} is not a valid TimeSpan", jobConfiguration.Input.TimeFrame.Duration);
// Try the ISO 8601 time interval
try
{
duration = XmlConvert.ToTimeSpan(jobConfiguration.Input.TimeFrame.Duration);
}
catch (FormatException ex)
{
logger.Error("Job File Problem: Input.TimeFrame.Duration={0} is not a valid ISO 8601 Time interval", jobConfiguration.Input.TimeFrame.Duration);
loggerConsole.Error("Job File Problem: Input.TimeFrame.Duration={0} is not a valid ISO 8601 Time interval", jobConfiguration.Input.TimeFrame.Duration);
return;
}
}
if (Math.Abs(duration.TotalSeconds) < 60)
{
logger.Error("Job File Problem: Input.TimeFrame.Duration={0} is shorter than 60 seconds", jobConfiguration.Input.TimeFrame.Duration);
loggerConsole.Error("Job File Problem: Input.TimeFrame.Duration={0} is is shorter than 60 seconds", jobConfiguration.Input.TimeFrame.Duration);
return;
}
// If we got here, we successfully parsed the date, time and duration (possibly negative)
logger.Info("Parsed MarkDate '{0}' as '{1:o}', local '{2:o}'", jobConfiguration.Input.TimeFrame.MarkDate, markDate.ToUniversalTime(), markDate.ToLocalTime());
logger.Info("Parsed MarkTime '{0}' as '{1:o}', local '{2:o}'", jobConfiguration.Input.TimeFrame.MarkTime, markTime.ToUniversalTime(), markTime.ToLocalTime());
logger.Info("Parsed Duration '{0}' as '{1:c}'", jobConfiguration.Input.TimeFrame.Duration, duration);
loggerConsole.Info("Parsed MarkDate '{0}' as '{1:o}', local '{2:o}'", jobConfiguration.Input.TimeFrame.MarkDate, markDate.ToUniversalTime(), markDate.ToLocalTime());
loggerConsole.Info("Parsed MarkTime '{0}' as '{1:o}', local '{2:o}'", jobConfiguration.Input.TimeFrame.MarkTime, markTime.ToUniversalTime(), markTime.ToLocalTime());
loggerConsole.Info("Parsed Duration '{0}' as '{1:c}'", jobConfiguration.Input.TimeFrame.Duration, duration);
DateTime dateTimeMark = DateTime.MinValue;
if ((markDate.Kind == DateTimeKind.Local && markTime.Kind == DateTimeKind.Local) || (markDate.Kind == DateTimeKind.Utc && markTime.Kind == DateTimeKind.Utc))
{
dateTimeMark = new DateTime(
markDate.Year,
markDate.Month,
markDate.Day,
markTime.Hour,
markTime.Minute,
markTime.Second,
markDate.Kind);
}
else if (markDate.Kind == DateTimeKind.Local && markTime.Kind == DateTimeKind.Utc)
{
dateTimeMark = new DateTime(
markDate.Year,
markDate.Month,
markDate.Day,
markTime.ToLocalTime().Hour,
markTime.ToLocalTime().Minute,
markTime.ToLocalTime().Second,
markDate.Kind);
}
else if (markDate.Kind == DateTimeKind.Utc && markTime.Kind == DateTimeKind.Local)
{
dateTimeMark = new DateTime(
markDate.Year,
markDate.Month,
markDate.Day,
markTime.ToUniversalTime().Hour,
markTime.ToUniversalTime().Minute,
markTime.ToUniversalTime().Second,
markDate.Kind);
}
DateTime dateTimeMarkPlusDuration = dateTimeMark.Add(duration);
logger.Info("DateTimeMark '{0:o}', local '{1:o}'", dateTimeMark.ToUniversalTime(), dateTimeMark.ToLocalTime());
logger.Info("DateTimeMarkPlusDuration '{0:o}', local '{1:o}'", dateTimeMarkPlusDuration.ToUniversalTime(), dateTimeMarkPlusDuration.ToLocalTime());
loggerConsole.Info("DateTimeMark '{0:o}', local '{1:o}'", dateTimeMark.ToUniversalTime(), dateTimeMark.ToLocalTime());
loggerConsole.Info("DateTimeMarkPlusDuration '{0:o}', local '{1:o}'", dateTimeMarkPlusDuration.ToUniversalTime(), dateTimeMarkPlusDuration.ToLocalTime());
jobConfiguration.Input.TimeRange = new JobTimeRange();
if (dateTimeMark <= dateTimeMarkPlusDuration)
{
jobConfiguration.Input.TimeRange.From = dateTimeMark;
jobConfiguration.Input.TimeRange.To = dateTimeMarkPlusDuration;
}
else
{
jobConfiguration.Input.TimeRange.From = dateTimeMarkPlusDuration;
jobConfiguration.Input.TimeRange.To = dateTimeMark;
}
#endregion
}
else if (jobConfiguration.Input.TimeRange != null)
{
#region Validate old style TimeRange
//"TimeRange": {
// "From": "2020-04-22T23:00:00",
// "To": "2020-04-23T00:00:00"
//}
// Or
//"TimeRange": {
// "From": "2020-04-22T23:00:00Z",
// "To": "2020-04-23T00:00:00Z"
//}
// The older type of explicit time range specifier in older job files
if (jobConfiguration.Input.TimeRange.From == null || jobConfiguration.Input.TimeRange.From == DateTime.MinValue)
{
logger.Error("Job File Problem: Input.TimeRange.From can not be empty");
loggerConsole.Error("Job File Problem: Input.TimeRange.From can not be empty");
return;
}
else if (jobConfiguration.Input.TimeRange.To == null || jobConfiguration.Input.TimeRange.To == DateTime.MinValue)
{
logger.Error("Job File Problem: Input.TimeRange.To can not be empty");
loggerConsole.Error("Job File Problem: Input.TimeRange.To can not be empty");
return;
}
#endregion
}
else
{
// Either TimeFrame or TimeRange must be specified. TimeRange is older style for explicit saying, TimeFrame is for the newer one
logger.Error("Job File Problem: Input.TimeRange and Input.TimeFrame can not both be empty");
loggerConsole.Error("Job File Problem: Input.TimeRange and Input.TimeFrame can not both be empty");
return;
}
// Switch all times in TimeRange to UTC
jobConfiguration.Input.TimeRange.From = jobConfiguration.Input.TimeRange.From.ToUniversalTime();
jobConfiguration.Input.TimeRange.To = jobConfiguration.Input.TimeRange.To.ToUniversalTime();
// Now measure the durations, make sure that From is before To
if (jobConfiguration.Input.TimeRange.From > jobConfiguration.Input.TimeRange.To)
{
logger.Error("Job File Problem: Input.TimeRange.From='{0:o}' can not be > Input.TimeRange.To='{1:o}'", jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
loggerConsole.Error("Job File Problem: Input.TimeRange.From='{0:o}' can not be > Input.TimeRange.To='{1:o}'", jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
return;
}
// Make sure we are not past the Now for the From
if (jobConfiguration.Input.TimeRange.From > dateTimeNowOriginalUtc)
{
logger.Error("Job File Problem: Input.TimeRange.From='{0:o}' can not be in the future", jobConfiguration.Input.TimeRange.From);
loggerConsole.Error("Job File Problem: Input.TimeRange.From='{0:o}' can not be in the future", jobConfiguration.Input.TimeRange.From);
return;
}
// Make sure we are not past the Now for the To, if yes, set it to Now
if (jobConfiguration.Input.TimeRange.To > dateTimeNowOriginalUtc)
{
logger.Warn("Job File Problem: Input.TimeRange.To='{0:o}' can not be in the future", jobConfiguration.Input.TimeRange.To);
loggerConsole.Warn("Job File Problem: Input.TimeRange.To='{0:o}' can not be in the future, setting to Now", jobConfiguration.Input.TimeRange.To);
jobConfiguration.Input.TimeRange.To = dateTimeNowOriginalUtc;
}
logger.Info("UTC Input.TimeRange.From='{0:o}' to Input.TimeRange.To='{1:o}'", jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
loggerConsole.Info("UTC Input.TimeRange.From='{0:o}' to Input.TimeRange.To='{1:o}'", jobConfiguration.Input.TimeRange.From, jobConfiguration.Input.TimeRange.To);
logger.Info("Local Input.TimeRange.From='{0:o}' to Input.TimeRange.To='{1:o}'", jobConfiguration.Input.TimeRange.From.ToLocalTime(), jobConfiguration.Input.TimeRange.To.ToLocalTime());
loggerConsole.Info("Local Input.TimeRange.From='{0:o}' to Input.TimeRange.To='{1:o}'", jobConfiguration.Input.TimeRange.From.ToLocalTime(), jobConfiguration.Input.TimeRange.To.ToLocalTime());
#endregion
#region Validate Input Everything else
// Validate Metrics selection criteria
if (jobConfiguration.Input.MetricsSelectionCriteria == null)
{
jobConfiguration.Input.MetricsSelectionCriteria = new JobMetricSelectionCriteria();
jobConfiguration.Input.MetricsSelectionCriteria.MetricSets = new string[0];
}
// Validate Events selection criteria
if (jobConfiguration.Input.EventsSelectionCriteria == null)
{
jobConfiguration.Input.EventsSelectionCriteria = new string[0];
}
// Validate Snapshot selection criteria
if (jobConfiguration.Input.SnapshotSelectionCriteria == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria = new JobSnapshotSelectionCriteria();
}
if (jobConfiguration.Input.SnapshotSelectionCriteria.Tiers == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria.Tiers = new string[0];
}
if (jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactions == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactions = new string[0];
}
if (jobConfiguration.Input.SnapshotSelectionCriteria.TierTypes == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria.TierTypes = new string[1];
jobConfiguration.Input.SnapshotSelectionCriteria.TierTypes[0] = "All";
}
if (jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactionTypes == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactionTypes = new string[1];
jobConfiguration.Input.SnapshotSelectionCriteria.BusinessTransactionTypes[0] = "All";
}
if (jobConfiguration.Input.SnapshotSelectionCriteria.RequestIDs == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria.RequestIDs = new string[0];
}
if (jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience = new JobUserExperience();
jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Normal = true;
jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Slow = true;
jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.VerySlow = true;
jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Stall = true;
jobConfiguration.Input.SnapshotSelectionCriteria.UserExperience.Error = true;
}
if (jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType == null)
{
jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType = new JobSnapshotType();
jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType.Full = true;
jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType.Partial = true;
jobConfiguration.Input.SnapshotSelectionCriteria.SnapshotType.None = true;
}
// Validate Entity Dashboard Screenshot selection criteria
if (jobConfiguration.Input.EntityDashboardSelectionCriteria == null)
{
jobConfiguration.Input.EntityDashboardSelectionCriteria = new JobEntityDashboardSelectionCriteria();
}
if (jobConfiguration.Input.EntityDashboardSelectionCriteria.Tiers == null)
{
jobConfiguration.Input.EntityDashboardSelectionCriteria.Tiers = new string[0];
}
if (jobConfiguration.Input.EntityDashboardSelectionCriteria.BusinessTransactions == null)
{
jobConfiguration.Input.EntityDashboardSelectionCriteria.BusinessTransactions = new string[0];
}
if (jobConfiguration.Input.EntityDashboardSelectionCriteria.TierTypes == null)
{
jobConfiguration.Input.EntityDashboardSelectionCriteria.TierTypes = new string[1];
jobConfiguration.Input.EntityDashboardSelectionCriteria.TierTypes[0] = "All";
}
if (jobConfiguration.Input.EntityDashboardSelectionCriteria.NodeTypes == null)
{
jobConfiguration.Input.EntityDashboardSelectionCriteria.NodeTypes = new string[1];
jobConfiguration.Input.EntityDashboardSelectionCriteria.NodeTypes[0] = "All";
}
if (jobConfiguration.Input.EntityDashboardSelectionCriteria.BusinessTransactionTypes == null)
{
jobConfiguration.Input.EntityDashboardSelectionCriteria.BusinessTransactionTypes = new string[1];
jobConfiguration.Input.EntityDashboardSelectionCriteria.BusinessTransactionTypes[0] = "All";
}
if (jobConfiguration.Input.EntityDashboardSelectionCriteria.BackendTypes == null)
{
jobConfiguration.Input.EntityDashboardSelectionCriteria.BackendTypes = new string[1];
jobConfiguration.Input.EntityDashboardSelectionCriteria.BackendTypes[0] = "All";
}
// Validate Configuration Comparison selection
if (jobConfiguration.Input.ConfigurationComparisonReferenceAPM == null ||
jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Controller == null || jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Controller.Length == 0 ||
jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Application == null || jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Application.Length == 0)
{
jobConfiguration.Input.ConfigurationComparisonReferenceAPM = new JobTarget();
jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Controller = JobStepBase.BLANK_APPLICATION_CONTROLLER;
jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Application = JobStepBase.BLANK_APPLICATION_APM;
jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Type = JobStepBase.APPLICATION_TYPE_APM;
}
else
{
jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Controller = jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Controller;
jobConfiguration.Input.ConfigurationComparisonReferenceAPM.Type = JobStepBase.APPLICATION_TYPE_APM;
}
if (jobConfiguration.Input.ConfigurationComparisonReferenceWEB == null ||
jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller == null || jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller.Length == 0 ||
jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Application == null || jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Application.Length == 0)
{
jobConfiguration.Input.ConfigurationComparisonReferenceWEB = new JobTarget();
jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller = JobStepBase.BLANK_APPLICATION_CONTROLLER;
jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Application = JobStepBase.BLANK_APPLICATION_WEB;
jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Type = JobStepBase.APPLICATION_TYPE_WEB;
}
else
{
jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller = jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Controller;
jobConfiguration.Input.ConfigurationComparisonReferenceWEB.Type = JobStepBase.APPLICATION_TYPE_WEB;
}
if (jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE == null ||
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller == null || jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller.Length == 0 ||
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application == null || jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application.Length == 0)
{
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE = new JobTarget();
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller = JobStepBase.BLANK_APPLICATION_CONTROLLER;
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Application = JobStepBase.BLANK_APPLICATION_MOBILE;
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Type = JobStepBase.APPLICATION_TYPE_MOBILE;
}
else
{
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller = jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Controller;
jobConfiguration.Input.ConfigurationComparisonReferenceMOBILE.Type = JobStepBase.APPLICATION_TYPE_MOBILE;
}
if (jobConfiguration.Input.ConfigurationComparisonReferenceDB == null ||
jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller == null || jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller.Length == 0 ||
jobConfiguration.Input.ConfigurationComparisonReferenceDB.Application == null || jobConfiguration.Input.ConfigurationComparisonReferenceDB.Application.Length == 0)
{
jobConfiguration.Input.ConfigurationComparisonReferenceDB = new JobTarget();
jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller = JobStepBase.BLANK_APPLICATION_CONTROLLER;
jobConfiguration.Input.ConfigurationComparisonReferenceDB.Application = JobStepBase.BLANK_APPLICATION_DB;
jobConfiguration.Input.ConfigurationComparisonReferenceDB.Type = JobStepBase.APPLICATION_TYPE_DB;
}
else
{
jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller = jobConfiguration.Input.ConfigurationComparisonReferenceDB.Controller;
jobConfiguration.Input.ConfigurationComparisonReferenceDB.Type = JobStepBase.APPLICATION_TYPE_DB;
}
#endregion
#region Expand time ranges into hourly chunks
// Prepare list of time ranges that goes from the Hour:00 of the From to the Hour:59 of the To
jobConfiguration.Input.HourlyTimeRanges = new List<JobTimeRange>();
DateTime intervalStartTime = jobConfiguration.Input.TimeRange.From;
DateTime intervalEndTime = new DateTime(
intervalStartTime.Year,
intervalStartTime.Month,
intervalStartTime.Day,
intervalStartTime.Hour,
0,
0,
DateTimeKind.Utc).AddHours(1);
do
{
TimeSpan timeSpan = intervalEndTime - jobConfiguration.Input.TimeRange.To;
if (timeSpan.TotalMinutes >= 0)
{
jobConfiguration.Input.HourlyTimeRanges.Add(new JobTimeRange { From = intervalStartTime, To = jobConfiguration.Input.TimeRange.To });
break;
}
else
{
jobConfiguration.Input.HourlyTimeRanges.Add(new JobTimeRange { From = intervalStartTime, To = intervalEndTime });
}
intervalStartTime = intervalEndTime;
intervalEndTime = intervalStartTime.AddHours(1);
}
while (true);
#endregion
#region Get job file name