Skip to content

Commit

Permalink
Merge pull request #205 from HiltonGiesenow/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
HiltonGiesenow authored Jul 16, 2018
2 parents 275122e + 23035b8 commit e99d690
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 18 deletions.
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"version": "0.4.0",
"configurations": [
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch Current File",
"script": "${file}",
"args": [],
"cwd": "${file}"
},
{
"name": "PowerShell",
"type": "PowerShell",
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ Of course there are loads of monitoring systems and tools out there, both paid a
---

## Release Notes
1.1.1
* Various bug fixes in Web tests
* Renamed html ad hoc report function
* Various bug fixes in html ad hoc report function

1.1.0
* Added ability to create ad-hoc html report
* For Drive Space Test, Add Volume Name to Output
* For Drive Space test, added Volume Name to output
* Added html formatting to Exception emails

1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Function Write-ReportToFile {
Function Write-PoShMonHtmlReport {
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[System.Collections.ArrayList]$PoShMonOutputValues,
[hashtable]$PoShMonConfiguration = $null,
[TimeSpan]$TotalElapsedTime = (New-TimeSpan),
[string]$OutputFilePath,
[boolean]$OverwriteFileIfExists = $false
[switch]$OverwriteFileIfExists = $false
)

if ($PoShMonConfiguration -eq $null)
Expand All @@ -15,7 +14,7 @@ Function Write-ReportToFile {
$PoShMonConfiguration = $Global:PoShMonConfiguration
}

if ($TotalElapsedTime.Ticks -eq 0)
if ($TotalElapsedTime -eq $null -or $TotalElapsedTime.Ticks -eq 0)
{
Write-Verbose "No TotalElapsedTime supplied, using Global one created previously"
$TotalElapsedTime = $Global:TotalElapsedPoShMonTime
Expand Down
8 changes: 6 additions & 2 deletions src/Functions/PoShMon.Monitoring.Web/Test-WebSites.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ Function Test-WebSites

$mainOutput = Get-InitialOutputWithTimer -SectionHeader "Web Test - $siteUrl" -OutputHeaders ([ordered]@{ 'ServerName' = 'Server'; 'StatusCode' = 'Status Code'; 'Outcome' = 'Outcome' })

For ($i = -1; $i -lt $PoShMonConfiguration.General.ServerNames.Count; $i++) {
$allServersExceptLocal = $PoShMonConfiguration.General.ServerNames | Where-Object { $_ -ne $env:COMPUTERNAME }

if ($allServersExceptLocal -ne $null -and $allServersExceptLocal.GetType().Name -eq "String") { $allServersExceptLocal = ,$allServersExceptLocal } #convert to proper array

For ($i = -1; $i -lt $allServersExceptLocal.Count; $i++) {

$serverName = '(Direct)'
$highlight = @()
Expand All @@ -26,7 +30,7 @@ Function Test-WebSites

$webRequest = Invoke-WebRequest $siteUrl -UseDefaultCredentials -UseBasicParsing
} else {
$serverName = $PoShMonConfiguration.General.ServerNames[$i]
$serverName = $allServersExceptLocal[$i]

if ($serverName -ne $env:COMPUTERNAME)
{
Expand Down
12 changes: 7 additions & 5 deletions src/Generate Module Manifest.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$version = "1.1.0"
$version = "1.1.1"
$manifestPath = Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) -ChildPath "\PoShMon.psd1"

Remove-Item -Path $manifestPath -ErrorAction SilentlyContinue
Expand All @@ -19,9 +19,14 @@ Some of the key features / benefits of PoShMon are:
For more information, documentation etc. visit https://github.com/HiltonGiesenow/PoShMon as well as the Samples folder within the module itself."

$releaseNotes = "
1.1.1
* Various bug fixes in Web tests
* Renamed html ad hoc report function
* Various bug fixes in html ad hoc report function
1.1.0
* Added ability to create ad-hoc html report
* For Drive Space Test, Add Volume Name to Output
* For Drive Space test, added Volume Name to output
* Added html formatting to Exception emails
1.0.0
Expand Down Expand Up @@ -80,9 +85,6 @@ $releaseNotes = "
* Add a check for any invalid TestsToSkip
* Fixed bug in Update-PoShMon
0.9.2
* Fixed bug in email output
* Fixed bug with not terminating Remote sessions correctly
"

New-ModuleManifest -Path $manifestPath -ModuleVersion $version -RootModule "PoShMon.psm1" -Guid '6e6cb274-1bed-4540-b288-95bc638bf679' -Author "Hilton Giesenow" -CompanyName "Experts Inside" -FunctionsToExport '*' -Copyright "2016 Hilton Giesenow, All Rights Reserved" -ProjectUri "https://github.com/HiltonGiesenow/PoShMon" -LicenseUri "https://github.com/HiltonGiesenow/PoShMon/blob/master/LICENSE" -Description $description -Tags 'Monitoring','Server','Farm','SharePoint' -ReleaseNotes $releaseNotes -Verbose
Expand Down
Binary file modified src/PoShMon.psd1
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $rootPath = Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Path) -ChildPa
Remove-Module PoShMon -ErrorAction SilentlyContinue
Import-Module (Join-Path $rootPath -ChildPath "PoShMon.psd1")

Describe "Write-ReportToFile" {
Describe "Write-PoShMonHtmlReport" {

InModuleScope PoShMon {

Expand All @@ -19,7 +19,7 @@ Describe "Write-ReportToFile" {
$PoShMonConfigurationGlobal = New-PoShMonConfiguration { General -EnvironmentName "Global Test" }

$testMonitoringOutput = @()
$testMonitoringOutput | Write-ReportToFile -OutputFilePath "C:\Temp\PoShMonReport.html"
Write-PoShMonHtmlReport -PoShMonOutputValues $testMonitoringOutput -OutputFilePath "C:\Temp\PoShMonReport.html"

Assert-MockCalled -CommandName New-HtmlBody -ParameterFilter { $PoShMonConfiguration.General.EnvironmentName -eq "Global Test" }
Assert-MockCalled -CommandName Out-File
Expand All @@ -31,7 +31,7 @@ Describe "Write-ReportToFile" {
$Global:TotalElapsedPoShMonTime = New-TimeSpan -Minutes 1 -Seconds 2

$testMonitoringOutput = @()
$testMonitoringOutput | Write-ReportToFile -OutputFilePath "C:\Temp\PoShMonReport.html"
Write-PoShMonHtmlReport -PoShMonOutputValues $testMonitoringOutput -OutputFilePath "C:\Temp\PoShMonReport.html"

Assert-MockCalled -CommandName New-HtmlBody -ParameterFilter { $TotalElapsedTime.TotalMilliseconds -eq 62000 }
Assert-MockCalled -CommandName Out-File
Expand All @@ -43,7 +43,7 @@ Describe "Write-ReportToFile" {
$PoShMonConfigurationGlobal = New-PoShMonConfiguration { General -EnvironmentName "Global Test" }

$testMonitoringOutput = @()
$testMonitoringOutput | Write-ReportToFile -OutputFilePath "C:\Temp\PoShMonReport.html" -PoShMonConfiguration $PoShMonConfigurationTest
Write-PoShMonHtmlReport -PoShMonOutputValues $testMonitoringOutput -OutputFilePath "C:\Temp\PoShMonReport.html" -PoShMonConfiguration $PoShMonConfigurationTest

Assert-MockCalled -CommandName New-HtmlBody -ParameterFilter { $PoShMonConfiguration.General.EnvironmentName -eq "Instance Test" }
Assert-MockCalled -CommandName Out-File
Expand All @@ -56,10 +56,95 @@ Describe "Write-ReportToFile" {
$TestTimeSpan = New-TimeSpan -Minutes 2 -Seconds 3

$testMonitoringOutput = @()
$testMonitoringOutput | Write-ReportToFile -OutputFilePath "C:\Temp\PoShMonReport.html" -TotalElapsedTime $TestTimeSpan
Write-PoShMonHtmlReport -PoShMonOutputValues $testMonitoringOutput -OutputFilePath "C:\Temp\PoShMonReport.html" -TotalElapsedTime $TestTimeSpan

Assert-MockCalled -CommandName New-HtmlBody -ParameterFilter { $TotalElapsedTime.TotalMilliseconds -eq 123000 }
Assert-MockCalled -CommandName Out-File
}

It "Passes in NoClobber correctly" {

$PoShMonConfigurationGlobal = New-PoShMonConfiguration { General -EnvironmentName "Global Test" }
$Global:TotalElapsedPoShMonTime = New-TimeSpan -Minutes 1 -Seconds 2
$TestTimeSpan = New-TimeSpan -Minutes 2 -Seconds 3

$testMonitoringOutput = @()
Write-PoShMonHtmlReport -PoShMonOutputValues $testMonitoringOutput -OutputFilePath "C:\Temp\PoShMonReport.html" -TotalElapsedTime $TestTimeSpan

Assert-MockCalled -CommandName Out-File -ParameterFilter { $NoClobber -eq $true }

}

It "Passes in NoClobber correctly for FALSE" {

$PoShMonConfigurationGlobal = New-PoShMonConfiguration { General -EnvironmentName "Global Test" }
$Global:TotalElapsedPoShMonTime = New-TimeSpan -Minutes 1 -Seconds 2
$TestTimeSpan = New-TimeSpan -Minutes 2 -Seconds 3

$testMonitoringOutput = @()
Write-PoShMonHtmlReport -PoShMonOutputValues $testMonitoringOutput -OutputFilePath "C:\Temp\PoShMonReport.html" -TotalElapsedTime $TestTimeSpan -OverwriteFileIfExists:$true

Assert-MockCalled -CommandName Out-File -ParameterFilter { $NoClobber -eq $false }
}

It "Writes All Output in One Go" {

$PoShMonConfigurationGlobal = New-PoShMonConfiguration { General -EnvironmentName "Global Test" }
$Global:TotalElapsedPoShMonTime = New-TimeSpan -Minutes 1 -Seconds 2
$TestTimeSpan = New-TimeSpan -Minutes 2 -Seconds 3

$testMonitoringOutput = @(
@{
"SectionHeader" = "Grouped Test"
"OutputHeaders" = @{ 'EventID' = 'Event ID'; 'Message' ='Message' }
"NoIssuesFound" = $true
"ElapsedTime" = (Get-Date).Subtract((Get-Date).AddMinutes(-1))
"OutputValues" = @(
@{
"GroupName" = "Server 1"
"GroupOutputValues" = @(
@{
"EventID" = 123
"Message" = "Message 1"
},
@{
"EventID" = 456
"Message" = "Message 2"
}
)
},
@{
"GroupName" = "Server 2"
"GroupOutputValues" = @(
@{
"EventID" = 789
"Message" = "Message 3"
}
)
}
)
}
@{
"SectionHeader" = "Ungrouped Test"
"OutputHeaders" = @{ 'ComponentName' = 'Component'; 'State' = 'State' }
"NoIssuesFound" = $false
"ElapsedTime" = (Get-Date).Subtract((Get-Date).AddMinutes(-1))
"OutputValues" = @(
@{
"ComponentName" = 123
"State" = "State 1"
},
@{
"ComponentName" = 456
"State" = "State 2"
}
)
}
)

Write-PoShMonHtmlReport -PoShMonOutputValues $testMonitoringOutput -OutputFilePath "C:\Temp\PoShMonReport.html" -TotalElapsedTime $TestTimeSpan -OverwriteFileIfExists:$true

Assert-MockCalled -CommandName Out-File -ParameterFilter { $NoClobber -eq $false }
}
}
}
119 changes: 118 additions & 1 deletion src/Tests/CI/Unit/PoShMon.Monitoring.Web/Test-WebSite.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,123 @@ Describe "Test-Website-NewScope" {

Assert-MockCalled -CommandName Invoke-WebRequest -Times 1 -Exactly
Assert-MockCalled -CommandName Invoke-RemoteWebRequest -Times 2 -Exactly
}
}
}
}
Describe "Test-Website-NewScope2" {
InModuleScope PoShMon {

class WebRequestMock {
[int]$StatusCode
[string]$StatusDescription
[string]$Content

WebRequestMock ([int]$NewStatusCode, [String]$NewStatusDescription, [String]$NewContent) {
$this.StatusCode = $NewStatusCode;
$this.StatusDescription = $NewStatusDescription;
$this.Content = $NewContent;
}
}

class RemoteWebRequestMock {
[int]$StatusCode
[string]$StatusDescription
[string]$Content
[string]$ServerName

RemoteWebRequestMock ([int]$NewStatusCode, [String]$NewStatusDescription, [String]$NewContent, [String]$NewServerName) {
$this.StatusCode = $NewStatusCode;
$this.StatusDescription = $NewStatusDescription;
$this.Content = $NewContent;
$this.ServerName = $NewServerName;
}
}

Mock -CommandName Invoke-WebRequest -MockWith {
return [WebRequestMock]::new(200, "OK", "Some Text")
}
Mock -CommandName Invoke-RemoteWebRequest -ModuleName PoShMon -MockWith {
return [RemoteWebRequestMock]::new(200, "OK", "Some Text", $serverName)
}

It "Should test Direct on local server and stop if no other servers" {

$poShMonConfiguration = New-PoShMonConfiguration {
General `
-ServerNames $env:COMPUTERNAME
WebSite `
-WebsiteDetails @{
"http://my.website.com" = "Some Text"
}
}

$actual = Test-WebSites $poShMonConfiguration

$actual.NoIssuesFound | Should Be $true
$actual.OutputValues.Count | Should Be 1
$actual.OutputValues[0].ServerName | Should Be '(Direct)'

Assert-MockCalled -CommandName Invoke-WebRequest -Times 1 -Exactly
Assert-MockCalled -CommandName Invoke-RemoteWebRequest -Times 0 -Exactly
}
}
}
Describe "Test-Website-NewScope3" {
InModuleScope PoShMon {

class WebRequestMock {
[int]$StatusCode
[string]$StatusDescription
[string]$Content

WebRequestMock ([int]$NewStatusCode, [String]$NewStatusDescription, [String]$NewContent) {
$this.StatusCode = $NewStatusCode;
$this.StatusDescription = $NewStatusDescription;
$this.Content = $NewContent;
}
}

class RemoteWebRequestMock {
[int]$StatusCode
[string]$StatusDescription
[string]$Content
[string]$ServerName

RemoteWebRequestMock ([int]$NewStatusCode, [String]$NewStatusDescription, [String]$NewContent, [String]$NewServerName) {
$this.StatusCode = $NewStatusCode;
$this.StatusDescription = $NewStatusDescription;
$this.Content = $NewContent;
$this.ServerName = $NewServerName;
}
}

Mock -CommandName Invoke-WebRequest -MockWith {
return [WebRequestMock]::new(200, "OK", "Some Text")
}
Mock -CommandName Invoke-RemoteWebRequest -ModuleName PoShMon -MockWith {
return [RemoteWebRequestMock]::new(200, "OK", "Some Text", $serverName)
}

It "Should test Direct on local server correctly for just one more server" {

$poShMonConfiguration = New-PoShMonConfiguration {
General `
-ServerNames $env:COMPUTERNAME,'Server2'
WebSite `
-WebsiteDetails @{
"http://my.website.com" = "Some Text"
}
}

$actual = Test-WebSites $poShMonConfiguration

$actual.NoIssuesFound | Should Be $true
$actual.OutputValues.Count | Should Be 2
$actual.OutputValues[0].ServerName | Should Be '(Direct)'
$actual.OutputValues[1].ServerName | Should Be 'Server2'

Assert-MockCalled -CommandName Invoke-WebRequest -Times 1 -Exactly
Assert-MockCalled -CommandName Invoke-RemoteWebRequest -ParameterFilter { $ServerName -eq 'Server2' } -Times 1 -Exactly
}
}
}

0 comments on commit e99d690

Please sign in to comment.