forked from MattHodge/Graphite-PowerShell-Functions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Graphite-Powershell.Tests.ps1
147 lines (136 loc) · 7.56 KB
/
Graphite-Powershell.Tests.ps1
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
Import-Module .\Graphite-Powershell.psd1
InModuleScope Graphite-PowerShell {
Describe "ConvertTo-GraphiteMetric" {
Context "Metric Transformation - Base Function" {
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec"
It "Should Return Something" {
$TestMetric | Should Not BeNullOrEmpty
}
It "Should Provide myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec as Output" {
$TestMetric | Should MatchExactly "myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec"
}
It "Should Not Contain Left Parentheses" {
$TestMetric | Should Not Match "\("
}
It "Should Not Contain Right Parentheses" {
$TestMetric | Should Not Match "\)"
}
It "Should Not Contain Forward Slash" {
$TestMetric | Should Not Match "\/"
}
It "Should Not Contain Back Slash" {
$TestMetric | Should Not Match "\\"
}
It "Should Contain a Period" {
$TestMetric | Should Match "\."
}
}
Context "Metric Transformation - Using MetricReplacementHash" {
$MockHashTable = [ordered]@{
"^\\\\" = "";
"\\\\" = "";
"\/" = "-";
":" = ".";
"\\" = ".";
"\(" = ".";
"\)" = "";
"\]" = "";
"\[" = "";
"\%" = "";
"\s+" = "";
"\.\." = ".";
"_" = ""
}
It "Should Return Something" {
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not BeNullOrEmpty
}
It "Should Provide myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec as Output" {
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should MatchExactly "myServer.networkinterface.realtekpciegbefamilycontroller.bytesreceived-sec"
}
It "Should Not Contain Left Parentheses" {
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\("
}
It "Should Not Contain Right Parentheses" {
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\)"
}
It "Should Not Contain Forward Slash" {
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\/"
}
It "Should Not Contain Back Slash" {
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Not Match "\\"
}
It "Should Contain a Period" {
ConvertTo-GraphiteMetric -MetricToClean "\\myServer\network interface(realtek pcie gbe family controller)\bytes received/sec" -MetricReplacementHash $MockHashTable | Should Match "\."
}
}
Context "Metric Transformation - Remove Underscores" {
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\myServer\Processor(_Total)\% Processor Time" -RemoveUnderscores
It "Should Return Something" {
$TestMetric | Should Not BeNullOrEmpty
}
It "Should Return myServer.production.net.Processor.Total.ProcessorTime as Output" {
$TestMetric | Should MatchExactly "myServer.Processor.Total.ProcessorTime"
}
It "Should Not Contain Underscores" {
$TestMetric | Should Not Match "_"
}
}
Context "Metric Transformation - Provide Nice Output for Physical Disks" {
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\myServer\physicaldisk(1 e:)\avg. disk write queue length" -RemoveUnderscores -NicePhysicalDisks
It "Should Return Something" {
$TestMetric | Should Not BeNullOrEmpty
}
It "Should Return myServer.physicaldisk.e-drive.diskwritequeuelength as Output" {
$TestMetric | Should MatchExactly "myServer.physicaldisk.e-drive.diskwritequeuelength"
}
}
Context "Metric Transformation - Replace HostName" {
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\$($env:COMPUTERNAME)\physicaldisk(1 e:)\avg. disk write queue length" -RemoveUnderscores -NicePhysicalDisks -HostName "my.new.hostname"
It "Should Return Something" {
$TestMetric | Should Not BeNullOrEmpty
}
It "Should Return my.new.hostname.physicaldisk.e-drive.diskwritequeuelength as Output" {
$TestMetric | Should MatchExactly "my.new.hostname.physicaldisk.e-drive.diskwritequeuelength"
}
$TestMetric = ConvertTo-GraphiteMetric -MetricToClean "\\$($env:COMPUTERNAME)\physicaldisk(1 e:)\avg. disk write queue length" -RemoveUnderscores -NicePhysicalDisks -HostName "host_with_underscores"
It "Should Return host_with_underscores.physicaldisk.e-drive.diskwritequeuelength as Output when RemoveUnderscores is enabled and host has underscores" {
$TestMetric | Should MatchExactly "host_with_underscores.physicaldisk.e-drive.diskwritequeuelength"
}
}
}
Describe "Import-XMLConfig" {
Context "Loading a Configuration File" {
$_config = Import-XMLConfig -ConfigPath "./StatsToGraphiteConfig.xml"
It "Loaded Configuration File Should Not Be Empty" {
$_config | Should Not BeNullOrEmpty
}
It "Should Have 16 Properties" {
$_config.Count | Should Be 17
}
It "SendUsingUDP should be Boolean" {
$_config.SendUsingUDP -is [Boolean] | Should Be $true
}
It "MSSQLMetricSendIntervalSeconds should be Int32" {
$_config.MSSQLMetricSendIntervalSeconds -is [Int32] | Should Be $true
}
It "MSSQLConnectTimeout should be Int32" {
$_config.MSSQLConnectTimeout -is [Int32] | Should Be $true
}
It "MSSQLQueryTimeout should be Int32" {
$_config.MSSQLQueryTimeout -is [Int32] | Should Be $true
}
It "MetricSendIntervalSeconds should be Int32" {
$_config.MetricSendIntervalSeconds -is [Int32] | Should Be $true
}
It "MetricTimeSpan should be TimeSpan" {
$_config.MetricTimeSpan -is [TimeSpan] | Should Be $true
}
It "MSSQLMetricTimeSpan should be TimeSpan" {
$_config.MSSQLMetricTimeSpan -is [TimeSpan] | Should Be $true
}
It "MetricReplace should be HashTable" {
$_config.MetricReplace -is [System.Collections.Specialized.OrderedDictionary] | Should Be $true
}
}
}
}