Skip to content

Commit

Permalink
Reorganize Diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
fvanroie committed Oct 4, 2018
1 parent a349c3b commit fd63bcc
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 93 deletions.
36 changes: 36 additions & 0 deletions Public/Diagnostics/Clear-OPNsenseARP.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<# MIT License
Copyright (c) 2018 fvanroie, NetwiZe.be
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function Clear-OPNsenseARP {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param (
)
if ($pscmdlet.ShouldProcess($MyInvocation.MyCommand.Module.PrivateData['OPNsenseApi'])) {
$result = Invoke-OPNsenseCommand diagnostics interface flusharp -Form flusharp
return $result.Split("`n") | Where-Object { $_ -ne '' }
}
}
42 changes: 42 additions & 0 deletions Public/Diagnostics/Format-SystemHealthData.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<# MIT License
Copyright (c) 2018 fvanroie, NetwiZe.be
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function Format-SystemHealthData {
Param (
[ValidateNotNullOrEmpty()]
$data
)
$rawdata = $data | Select-Object -ExpandProperty d3 | Select-Object -ExpandProperty data
$table = @()
$rows = $rawdata[0].values.Count
for ($i = 0; $i -lt $rows; $i++) {
$unixdt = Convert-UnixSecondstoLocal ($rawdata.values[$i][0] / 1000)
$row = New-Object PSObject -Property @{ timestamp = $Unixdt }
foreach ($column in $rawdata) {
$row | Add-Member -NotePropertyName $column.key -NotePropertyValue $column.values[$i][1]
}
$table += $row
}

return $table
}
31 changes: 31 additions & 0 deletions Public/Diagnostics/Get-OPNsenseARP.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<# MIT License
Copyright (c) 2018 fvanroie, NetwiZe.be
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function Get-OPNsenseARP {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
param (
)
$result = Invoke-OPNsenseCommand diagnostics interface getarp
return $result | Add-ObjectDetail -TypeName 'OPNsense.Diagnostics.Interface.Arp' | Sort-Object -Property Interface, { [System.Version]$_.IP }
}
31 changes: 31 additions & 0 deletions Public/Diagnostics/Get-OPNsenseInterface.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<# MIT License
Copyright (c) 2018 fvanroie, NetwiZe.be
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function Get-OPNsenseInterface {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
Param()
$result = $(Invoke-OPNsenseCommand diagnostics systemhealth getRRDlist).data.traffic |
Select-Object -Property @{"N" = "Interface"; "E" = {$_}}
return $result
}
31 changes: 31 additions & 0 deletions Public/Diagnostics/Get-OPNsenseResource.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<# MIT License
Copyright (c) 2018 fvanroie, NetwiZe.be
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function Get-OPNsenseResource {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
Param()
$result = $(Invoke-OPNsenseCommand diagnostics systemhealth getRRDlist).data.system |
Select-Object -Property @{"N" = "Resource"; "E" = {$_}}
return $result
}
31 changes: 31 additions & 0 deletions Public/Diagnostics/Get-OPNsenseRoute.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<# MIT License
Copyright (c) 2018 fvanroie, NetwiZe.be
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function Get-OPNsenseRoute {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
param (
)
$result = Invoke-OPNsenseCommand diagnostics interface getroutes
return $result
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function Format-SystemHealthData {
Param (
[ValidateNotNullOrEmpty()]
$data
)
$rawdata = $data | Select-Object -ExpandProperty d3 | Select-Object -ExpandProperty data
$table = @()
$rows = $rawdata[0].values.Count
for ($i = 0; $i -lt $rows; $i++) {
$unixdt = Convert-UnixSecondstoLocal ($rawdata.values[$i][0] / 1000)
$row = New-Object PSObject -Property @{ timestamp = $Unixdt }
foreach ($column in $rawdata) {
$row | Add-Member -NotePropertyName $column.key -NotePropertyValue $column.values[$i][1]
}
$table += $row
}

return $table
}

Function ValidateSystemHealthOptions {
Param (
[ValidateSet("packets", "system", "traffic")]
[String]$type,
[String]$data,
[String]$collection
)

$result = Invoke-OPNsenseCommand diagnostics systemhealth getRRDlist
switch ($type) {
'packets' { $options = $result.data.packets }
'system' { $options = $result.data.system }
'traffic' { $options = $result.data.traffic }
default { Throw "Invalid SystemHealthOptions type: $type" }
}
if ($options -NotContains $data) {
$choices = $options | ConvertTo-Json -compress
Throw """$data"" is not a valid $type $collection option. ""$data"" needs to be in $choices"
}
}

Function Get-OPNsenseSystemHealth {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
Expand Down Expand Up @@ -155,54 +113,4 @@ Function Get-OPNsenseSystemHealth {
}

return Format-SystemHealthData $result
}

Function Get-OPNsenseInterface {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
Param()
$result = $(Invoke-OPNsenseCommand diagnostics systemhealth getRRDlist).data.traffic |
Select-Object -Property @{"N" = "Interface"; "E" = {$_}}
return $result
}

Function Get-OPNsenseResource {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
Param()
$result = $(Invoke-OPNsenseCommand diagnostics systemhealth getRRDlist).data.system |
Select-Object -Property @{"N" = "Resource"; "E" = {$_}}
return $result
}

Function Get-OPNsenseRoute {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
param (
)
$result = Invoke-OPNsenseCommand diagnostics interface getroutes
return $result
}

Function Get-OPNsenseARP {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding()]
param (
)
$result = Invoke-OPNsenseCommand diagnostics interface getarp
return $result | Add-ObjectDetail -TypeName 'OPNsense.Diagnostics.Interface.Arp' | Sort-Object -Property Interface, { [System.Version]$_.IP }
}

Function Clear-OPNsenseARP {
# .EXTERNALHELP ../PS_OPNsense.psd1-Help.xml
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param (
)
if ($pscmdlet.ShouldProcess($MyInvocation.MyCommand.Module.PrivateData['OPNsenseApi'])) {
$result = Invoke-OPNsenseCommand diagnostics interface flusharp -Form flusharp
return $result.Split("`n") | Where-Object { $_ -ne '' }
}
}
}
43 changes: 43 additions & 0 deletions Public/Diagnostics/ValidateSystemHealthOptions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<# MIT License
Copyright (c) 2018 fvanroie, NetwiZe.be
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>

Function ValidateSystemHealthOptions {
Param (
[ValidateSet("packets", "system", "traffic")]
[String]$type,
[String]$data,
[String]$collection
)

$result = Invoke-OPNsenseCommand diagnostics systemhealth getRRDlist
switch ($type) {
'packets' { $options = $result.data.packets }
'system' { $options = $result.data.system }
'traffic' { $options = $result.data.traffic }
default { Throw "Invalid SystemHealthOptions type: $type" }
}
if ($options -NotContains $data) {
$choices = $options | ConvertTo-Json -compress
Throw """$data"" is not a valid $type $collection option. ""$data"" needs to be in $choices"
}
}

0 comments on commit fd63bcc

Please sign in to comment.