-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQualysAgent.Tests.ps1
56 lines (46 loc) · 1.72 KB
/
QualysAgent.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
$be_computer = hostname
$Remote_computer = 'bc-moqgw-101'
Describe "Local QualysAgent Services" {
Context "Check QualysAgent Local Port" {
$Local_ports = @('135')
foreach ($port in $Local_ports) {
it "Server is listening on port $port" {
$port_state = Invoke-Command -computer $be_computer `
-ScriptBlock {param($port)(Get-NetTCPConnection -LocalPort $port `
-ErrorAction SilentlyContinue).State} `
-ArgumentList $port
$port_state.Value -contains "Listen" | should be $true
}
}
}
context 'Service QualysAgent Availability' {
$Services = @('QualysAgent')
foreach ($ServX in $Services){
it "$ServX is running?" {
$svc = Get-Service -Name $ServX
$svc.Status | Should be running
}
}
}
Context "Check Remote Qualys Port" {
$Local_ports = @('8080')
foreach ($port in $Local_ports) {
$socket = New-Object Net.Sockets.TcpClient
it "Remote Server is listening on port $port" {
Try{
$socket.Connect($Remote_computer, $port)
$Result = 'Success'
}
Catch{
Write-Host $_
$Result = 'Failed'
}
Finally{
$socket.Close()
$socket.Dispose()
}
$Result -contains 'Success' | should be $true
}
}
}
}