-
Notifications
You must be signed in to change notification settings - Fork 1
/
prtg-sensor-vmware-uag.ps1
129 lines (108 loc) · 4.76 KB
/
prtg-sensor-vmware-uag.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
<#
.SYNOPSIS
Outputs a PRTG XML structure with multiple information about UAG
.DESCRIPTION
Get Status and Session-statistics from UAG
.INSTRUCTIONS
1) Copy the script file into the PRTG Custom EXEXML sensor directory C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML
- prtg-sensor-vmware-uag.ps1 (PowerShell Sensor Script)
3) Create Sensor Custom EXE/ Script Advanced Sensor for each sensor you wish to monitor (refer Scope) and give it a meaniful name
4) Set Parameters for sensor
- (URL) "https://[VMware-UAG]:9443/rest/v1/monitor/stats"
- (Username) and (Password) to gain access
e.g. -url "https://%host:9443/rest/v1/monitor/stats" -username "%windowsuser" -password "%windowspassword"
.NOTES
Authors: [email protected], [email protected]
Website: https://nios.ch/
Version: 1.1
Date: 1.12.2021
.PARAMETER URL
DNS Name or IP Address of the VMWare UAG
.PARAMETER UserName
The name of the account to be used to access the UAG (mostly admin)
.PARAMETER Password
The password of the account
.EXAMPLES
C:\PS>prtg-sensor-vmware-uag.ps1 -URL "https://vmware-uag:9443/rest/v1/monitor/stats" -username admin -password TopSecretPW
#>
param
(
[string]$URL,# = "",
[string]$Username,# = "admin",
[string]$Password # = "",
)
#Import Modules
#Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true -Confirm:$false
Get-ChildItem -Path "C:\Program Files (x86)\WindowsPowerShell\Modules" -Recurse | Unblock-File
Get-ChildItem -Path "C:\Program Files\WindowsPowerShell\Modules" -Recurse | Unblock-File
#Disable Cert Check
Add-Type @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
"@
[ServerCertificateValidationCallback]::Ignore();
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Request = Invoke-RestMethod -Method Get -Uri $URL -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Write-Host "<prtg>"
Write-Host "<result>"
Write-Host "<channel>Authenticated Session Count</channel>"
Write-Host "<value>$($Request.accessPointStatusAndStats.authenticatedSessionCount)</value>"
Write-Host "</result>"
if ($($Request.accessPointStatusAndStats.overAllStatus.status) -eq "RUNNING"){$OverAllStatus = 1}Else{$OverAllStatus = 0}
Write-Host "<result>"
Write-Host "<channel>OverAllStatus</channel>"
Write-Host "<value>$OverAllStatus</value>"
Write-Host "<LimitMinError>0.5</LimitMinError>"
Write-Host "<LimitMode>1</LimitMode>"
Write-Host "</result>"
if ($($Request.accessPointStatusAndStats.authentication.authBrokerStatus.status) -eq "RUNNING"){$BrokerStatus = 1}Else{$BrokerStatus = 0}
Write-Host "<result>"
Write-Host "<channel>Broker Status</channel>"
Write-Host "<value>$BrokerStatus</value>"
Write-Host "<LimitMinError>0.5</LimitMinError>"
Write-Host "<LimitMode>1</LimitMode>"
Write-Host "</result>"
if ($($Request.accessPointStatusAndStats.viewEdgeServiceStats.backendStatus.status) -eq "RUNNING"){$BackendStatus = 1}Else{$BackendStatus = 0}
Write-Host "<result>"
Write-Host "<channel>Backend Status</channel>"
Write-Host "<value>$BackendStatus</value>"
Write-Host "<LimitMinError>0.5</LimitMinError>"
Write-Host "<LimitMode>1</LimitMode>"
Write-Host "</result>"
if ($($Request.accessPointStatusAndStats.viewEdgeServiceStats.edgeServiceStatus.Status) -eq "RUNNING"){$edgeServiceStatus = 1}Else{$edgeServiceStatus = 0}
Write-Host "<result>"
Write-Host "<channel>Edge Service Status</channel>"
Write-Host "<value>$edgeServiceStatus</value>"
Write-Host "<LimitMinError>0.5</LimitMinError>"
Write-Host "<LimitMode>1</LimitMode>"
Write-Host "</result>"
foreach ($item in $($Request.accessPointStatusAndStats.viewEdgeServiceStats.protocol))
{
write-host "<result>"
write-host "<channel>$($item.name)</channel>"
write-host "<value>$($item.sessions)</value>"
write-host "<CustomUnit>Sessions</CustomUnit>"
write-host "</result>"
}
Write-Host "</prtg>"
exit $code