Skip to content

Commit 24e0af4

Browse files
committed
Thanks, Git
1 parent 003a60c commit 24e0af4

File tree

9 files changed

+80
-17
lines changed

9 files changed

+80
-17
lines changed

prtgshell2.cs

826 Bytes
Binary file not shown.

prtgshell2.dll

0 Bytes
Binary file not shown.

prtgshell2.psd1

0 Bytes
Binary file not shown.

prtgshell2.psm1

2.33 KB
Binary file not shown.

src/cmdlets/Get-PrtgObject.ps1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@ function Get-PrtgObject {
3131

3232
$DeviceType = $Data.prtg.sensortree.nodes.SelectNodes("*[1]").LocalName
3333

34-
return $Data.prtg.sensortree.nodes.SelectNodes("*[1]")
34+
$ObjectXMLData = $Data.prtg.sensortree.nodes.SelectNodes("*[1]")
3535

36-
$ReturnData = @()
36+
37+
####
38+
$TestReturn = "" | select type,data
39+
$TestReturn.type = $DeviceType
40+
$TestReturn.data = $ObjectXMLData
41+
42+
return $TestReturn
43+
####
44+
45+
#$ReturnData = @()
3746

3847
<#
3948
@@ -46,7 +55,7 @@ function Get-PrtgObject {
4655
4756
#>
4857

49-
$PrtgObjectType = switch ($Content) {
58+
$PrtgObjectType = switch ($DeviceType) {
5059
"probes" { "PrtgShell.PrtgProbe" }
5160
"groups" { "PrtgShell.PrtgGroup" }
5261
"devices" { "PrtgShell.PrtgDevice" }
@@ -58,12 +67,18 @@ function Get-PrtgObject {
5867
"history" { "PrtgShell.PrtgHistory" }
5968
}
6069

70+
$ObjectXMLData = $Data.prtg.sensortree.nodes.SelectNodes("*[1]")
6171

72+
$ThisObject = New-Object $PrtgObjectType
73+
74+
foreach ($p in $ObjectXMLData.GetEnumerator()) {
75+
$ThisObject.($p.name) = $p.'#Text'
76+
}
6277

78+
return $ThisObject
6379

64-
foreach ($item in $Data.$Content.item) {
65-
$ThisObject = New-Object $PrtgObjectType
66-
#$ThisRow = "" | Select-Object $SelectedColumns
80+
<#
81+
#$ThisRow = "" | Select-Object $SelectedColumns
6782
foreach ($Prop in $SelectedColumns) {
6883
if ($Content -eq "channels" -and $Prop -eq "lastvalue_raw") {
6984
# fix a bizarre formatting bug
@@ -97,5 +112,8 @@ function Get-PrtgObject {
97112
} else {
98113
return $ReturnData
99114
}
115+
116+
#>
117+
100118
}
101119
}

src/cmdlets/Get-PrtgSensorHistoricData.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ function Get-PrtgSensorHistoricData {
4949
$QueryObject = $PrtgServerObject.HttpQuery($url,$false)
5050

5151
$DataPoints = $QueryObject.RawData | ConvertFrom-Csv | ? { $_.'Date Time' -ne 'Averages' }
52-
53-
#$APropertyName = (($DataPoints | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name) -notmatch "Coverage") -notmatch "Date Time" | Select-Object -First 1
5452
}
5553

5654
END {

src/cmdlets/Get-PrtgSensorUptime.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ function Get-PrtgSensorUptime {
4141
}
4242

4343
PROCESS {
44+
$ObjectInterval = Get-PrtgObject $SensorId | Select-Object -ExpandProperty interval
45+
4446
$HistoricData = Get-PrtgSensorHistoricData $SensorId $RangeStart $RangeEnd 0
4547

4648
$APropertyName = (($HistoricData | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name) -notmatch "Coverage") -notmatch "Date Time" | Select-Object -First 1
@@ -51,14 +53,19 @@ function Get-PrtgSensorUptime {
5153
}
5254

5355
END {
54-
$returnobject = "" | select SensorId,RangeStart,RangeEnd,TotalDatapoints,UpDatapoints,DownDatapoints,UptimePercentage
56+
$returnobject = "" | select SensorId,RangeStart,RangeEnd,TotalDatapoints,UpDatapoints,DownDatapoints,Interval,UptimePercentage
5557
$returnobject.SensorId = $SensorId
5658
$returnobject.RangeStart = $RangeStart
5759
$returnobject.RangeEnd = $RangeEnd
5860
$returnobject.TotalDatapoints = $HistoricData.Count
5961
$returnobject.UpDatapoints = $UpEntries.Count
6062
$returnobject.DownDatapoints = $HistoricData.Count - $UpEntries.Count
61-
$returnobject.UptimePercentage = ($UpEntries.Count / $HistoricData.Count) * 100
63+
$returnobject.Interval = $ObjectInterval
64+
if ($HistoricData.Count) {
65+
$returnobject.UptimePercentage = ($UpEntries.Count / $HistoricData.Count) * 100
66+
} else {
67+
$returnobject.UptimePercentage = 0
68+
}
6269

6370
return $returnobject
6471
}

src/cmdlets/Get-PrtgTableData.ps1

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function Get-PrtgTableData {
4141
Returns the messages log for device 1002.
4242
#>
4343

44+
[CmdletBinding()]
4445
Param (
4546
[Parameter(Mandatory=$True,Position=0)]
4647
[ValidateSet("probes","groups","devices","sensors","todos","messages","values","channels","history")]
@@ -56,8 +57,14 @@ function Get-PrtgTableData {
5657
[string[]]$FilterTags,
5758

5859
[Parameter(Mandatory=$False)]
59-
#[ValidateSet("Unknown","Collecting","Up","Warning","Down","NoProbe","PausedbyUser","PausedbyDependency","PausedbySchedule","Unusual","PausedbyLicense","PausedUntil","DownAcknowledged","DownPartial")]
60+
[ValidateSet("Unknown","Collecting","Up","Warning","Down","NoProbe","PausedbyUser","PausedbyDependency","PausedbySchedule","Unusual","PausedbyLicense","PausedUntil","DownAcknowledged","DownPartial")]
6061
[string[]]$FilterStatus,
62+
63+
[Parameter(Mandatory=$False)]
64+
[string]$FilterTarget,
65+
66+
[Parameter(Mandatory=$False)]
67+
[string]$FilterValue,
6168

6269
[Parameter(Mandatory=$False)]
6370
[int]$Count,
@@ -73,12 +80,12 @@ function Get-PrtgTableData {
7380
sortby = sorts on named column, ascending (or decending with a leading "-")
7481
filter_xyz - fulltext filtering. this is a feature in its own right
7582
83+
84+
7685
#>
7786

7887
BEGIN {
7988
$PRTG = $Global:PrtgServerObject
80-
if ($PRTG.Protocol -eq "https") { $PRTG.OverrideValidation() }
81-
8289

8390
$CountProperty = @{}
8491
$FilterProperty = @{}
@@ -94,10 +101,38 @@ function Get-PrtgTableData {
94101
$FilterProperty += @{ "filter_tags" = $FilterTags }
95102
}
96103

104+
$StatusFilterCodes = @{
105+
"Unknown" = 1
106+
"Collecting" = 2
107+
"Up" = 3
108+
"Warning" = 4
109+
"Down" = 5
110+
"NoProbe" = 6
111+
"PausedbyUser" = 7
112+
"PausedbyDependency" = 8
113+
"PausedbySchedule" = 9
114+
"Unusual" = 10
115+
"PausedbyLicense" = 11
116+
"PausedUntil" = 12
117+
"DownAcknowledged" = 13
118+
"DownPartial" = 14
119+
}
120+
97121
if ($FilterStatus -and (!($Content -eq "sensors"))) {
98122
throw "Get-PrtgTableData: Parameter FilterStatus requires content type sensors"
99123
} elseif ($Content -eq "sensors" -and $FilterStatus) {
100-
$FilterProperty += @{ "filter_status" = $FilterStatus }
124+
# I apparently wrote some code that gracefully
125+
# handles this (multiple properties w/ same name) two years ago.
126+
# good job, past josh
127+
$FilterProperty += @{ "filter_status" = $StatusFilterCodes[$FilterStatus] }
128+
}
129+
130+
if ($FilterTarget) {
131+
if (!$FilterValue) {
132+
throw "Get-PrtgTableData: Parameter FilterTarget requires parameter FilterValue also"
133+
}
134+
$FilterName = "filter_" + $FilterTarget
135+
$FilterProperty += @{ $FilterName = $FilterValue }
101136
}
102137

103138
if (!$Columns) {
@@ -153,11 +188,11 @@ function Get-PrtgTableData {
153188
##### data returned; do!
154189

155190
if ($Raw) {
156-
$QueryObject = HelperHTTPQuery $url
191+
$QueryObject = $PrtgServerObject.HttpQuery($url,$false)
157192
return $QueryObject.Data
158193
}
159194

160-
$QueryObject = HelperHTTPQuery $url -AsXML
195+
$QueryObject = $PrtgServerObject.HttpQuery($url)
161196
$Data = $QueryObject.Data
162197

163198
$ReturnData = @()

src/cs/PrtgServer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public string UrlBuilder(string Action) {
114114
return CompletedString;
115115
}
116116

117+
// i'm not confident that this is actually used anywhere
117118
public string UrlBuilder(string Action, string[] QueryParameters) {
118119

119120
if (Action.StartsWith("/")) Action = Action.Substring(1);
@@ -143,6 +144,10 @@ public string UrlBuilder(string Action, Hashtable QueryParameters) {
143144
Pieces[2] = "?";
144145
Pieces[3] = this.AuthString;
145146

147+
// this little bit of awesome handles query string parameters that
148+
// have multiple entries with the same key name, which obviously
149+
// hashtables do not natively support. this detects values that are
150+
// not singleton strings or ints, and blows up the array.
146151
foreach (DictionaryEntry KeyPair in QueryParameters) {
147152
if (KeyPair.Value.GetType() == typeof(string) || KeyPair.Value.GetType() == typeof(int)) {
148153
Pieces[4] += ("&" + KeyPair.Key + "=" + KeyPair.Value);
@@ -166,7 +171,7 @@ private static bool OnValidateCertificate(object sender, X509Certificate certifi
166171
public void OverrideValidation() {
167172
ServicePointManager.ServerCertificateValidationCallback = OnValidateCertificate;
168173
ServicePointManager.Expect100Continue = true;
169-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
174+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
170175
}
171176

172177
private System.Uri prtguri;

0 commit comments

Comments
 (0)