MediantDailyChecklist.ps1
#Requires -version 5.0 <#PSScriptInfo .VERSION 0.3.0 .GUID 4fd8659d-aa9f-49d0-b3ee-928028cc6026 .AUTHOR Shane Hoey .COMPANYNAME .COPYRIGHT 2016-2019 Shane Hoey .TAGS Mediant,daily,audiocodes .LICENSEURI https://github.com/shanehoey/code/blob/master/LICENSE.md .PROJECTURI https://github.com/shanehoey/code/tree/master/mediant/MediantDailyChecklist .ICONURI .EXTERNALMODULEDEPENDENCIES Mediant .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> #Requires -Module Mediant <# .DESCRIPTION Daily Checklist Script for Mediant Devices #> <# Copyright (c) 2016-2019 Shane Hoey 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. #> param ( [ValidateScript( { if (-Not ($_ | Test-Path) ) { throw "File does not exist" } if (-Not ($_ | Test-Path -PathType Leaf) ) { throw "The Path argument must be a file." } if ($_ -notmatch "(\.json)") { throw "The file specified must be a .json file " } return $true })] [parameter(Position = 0, Mandatory = $true)][System.IO.FileInfo]$jsonFile, [ValidateScript( { if (-Not ($_ | Test-Path -PathType Container) ) { throw "The Path argument must be a folder." } return $true })] [parameter(Position = 1, Mandatory = $false)][System.IO.FileInfo]$outputFolder, [ValidateSet("basic", "detailed","debug")] [parameter(Position = 2, Mandatory = $false)][string]$schema = "basic", [parameter(Position = 3, Mandatory = $false)][switch]$backupINI, [parameter(Position = 4, Mandatory = $false)][switch]$backupCLI, [parameter(Position = 5, Mandatory = $false)][switch]$insecure, [parameter(Position = 6, Mandatory = $false)][switch]$nostats ) Write-Verbose -message "'MediantDailyChecklist.ps1' source https://github.com/shanehoey/code/tree/master/mediant/dailychecks please contribute" -verbose #region functions function mediantimport { [CmdletBinding(DefaultParametersetName = "default")] param( [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [string]$jsonfile ) Write-Verbose -message "[function] $($MyInvocation.MyCommand)" foreach ($mediant in (get-content -Path $jsonfile | convertfrom-json) ) { Write-Verbose -Message "Connecting to SBC -> $($mediant.mediant)" $Parameters = @{ } $Parameters.Mediant = $Mediant.mediant $Parameters.Http = $Mediant.http $Parameters.Username = $Mediant.username $Parameters.password = (ConvertTo-SecureString -String $mediant.password) $temp = get-MediantDevice @parameters if ($temp) { [MediantDailyChecklist]::new($temp.Mediant, $temp.Credential, $temp.http) } } } function mediantstats { try { # This is used for usage stats only, only reporting on page views # to disable use -nostats parameter instead Write-Verbose "[function] $($MyInvocation.MyCommand)" Invoke-WebRequest -Uri "https://api.shanehoey.com/stats/MediantDailyChecklist/" -TimeoutSec 2 | out-null } catch { } } function mediantregex { param( $string, $capture ) Write-Verbose "[function] $($MyInvocation.MyCommand)" ((([Regex]::new($capture)).Match($string)).value).trim() } Function mediantbackup { [CmdletBinding(DefaultParametersetName = "default")] param( [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [parameter(Position = 0, ParameterSetName = "filename", Mandatory = $true)] [MediantDailyChecklist]$mediant, [ValidateSet("ini", "cliscript")] [parameter(Position = 1, ParameterSetName = "default", Mandatory = $true)] [parameter(Position = 1, ParameterSetName = "filename", Mandatory = $true)] [string]$type, [parameter(Position = 2, ParameterSetName = "filename", Mandatory = $false)] [switch]$writefile ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential if ($type -eq "ini") { Write-Verbose "Backup INI -> $mediant.filename" if ($writefile) { $Parameters.file = (join-path -path $outputFolder -childpath "$($mediant.filename).ini") } $findChars = '[\"]' $replaceChars = '\"' (Get-MediantDeviceFileIni @Parameters) -replace $findChars, $replaceChars } if ($type -eq "cliscript") { if ($writefile) { $Parameters.file = (join-path -path $path -childpath "$($mediant.filename).cli") } Write-Verbose "Backup cliScript -> $filename" $findChars = '[\"]' $replaceChars = '\"' (Get-MediantDeviceFileCliScript @Parameters) -replace $findChars, $replaceChars } } function mediantSystemVersion { [CmdletBinding(DefaultParametersetName = "default")] param ( [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $mediant.mediant $Parameters.Http = $mediant.http $Parameters.Credential = $mediant.credential $Parameters.script = "show system version" if ( $insecure ) { $Parameters.insecure = $true } [SystemVersion]::new( ( Invoke-MediantCurlRequest @parameters | ConvertFrom-Json | Select-Object -expand output ).replace(". ;", "`n").replace(" ;", "`n").replace(":;", "`n") ) } function mediantPhysicalPort { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show network physical-port" if ( $insecure ) { $Parameters.insecure = $true } [physicalPort]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantEthernetDevice { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show network physical-port" if ( $insecure ) { $Parameters.insecure = $true } [EthernetDevice]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantEthernetGroup { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show network ethernet-group" if ( $insecure ) { $Parameters.insecure = $true } [EthernetGroup]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantNetworkInterface { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show network interface" if ( $insecure ) { $Parameters.insecure = $true } [NetworkInterface]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantNetworkRoute { [CmdletBinding(DefaultParametersetName = "default")] param ( [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show network route" if ( $insecure ) { $Parameters.insecure = $true } [NetworkRoute]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantNetworkStatus { [CmdletBinding(DefaultParametersetName = "default")] param ( [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" [NetworkStatus]::new($mediant) } function mediantNTPStatus { [CmdletBinding(DefaultParametersetName = "default")] param ( [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show system ntp-status" if ( $insecure ) { $Parameters.insecure = $true } [NTPStatus]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantDeviceInfo { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential [DeviceStatus]::new((Get-MediantDeviceStatus @Parameters)) } function mediantHAStatus { param ( [MediantDailyChecklist]$mediant ) #todo: investigate "debug ha" instead Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show high-availability status" if ( $insecure ) { $Parameters.insecure = $true } [HAStatus]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantRunningConfig { param ( [MediantDailyChecklist]$mediant, [ValidateSet("full","network","system","troubleshoot","voip")] [string]$type = "full" ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show running-config $type" if ( $insecure ) { $Parameters.insecure = $true } switch ($type) { "full" { [RunningConfigFull]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } "network" { [RunningConfigNetwork]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } "system" { [RunningConfigSystem]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } "troubleshoot" { [RunningConfigTroubleshoot]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } "voip" { [RunningConfigVoip]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } } } function mediantSyslog { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $Mediant.Mediant $Parameters.Http = $Mediant.http $Parameters.Credential = $Mediant.Credential $Parameters.script = "show running-config troubleshoot" if ( $insecure ) { $Parameters.insecure = $true } [Syslog]::new((Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output)) } function mediantUptime { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $mediant.Mediant $Parameters.Http = $mediant.http $Parameters.Credential = $mediant.Credential $Parameters.script = "show system uptime" if ( $insecure ) { $Parameters.insecure = $true } [uptime]::new(( Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output )) } function mediantAlarms { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" [alarms]::new("NotImplemented") } function mediantPerformanceMonitoring { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" [PerformanceMonitoring]::new("NotImplemented") } # mediantVoipStatus function mediantVoipStatus { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" [VoipStatus]::new($mediant) } function mediantProxySet { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $mediant.Mediant $Parameters.Http = $mediant.http $Parameters.Credential = $mediant.Credential $Parameters.script = "show voip proxy set status" if ( $insecure ) { $Parameters.insecure = $true } [ProxySet]::new(( Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output )) } function mediantRegistration { param ( [MediantDailyChecklist]$mediant ) Write-Verbose "[function] $($MyInvocation.MyCommand)" $Parameters = @{ } $Parameters.Mediant = $mediant.Mediant $Parameters.Http = $mediant.http $Parameters.Credential = $mediant.Credential $Parameters.script = "show voip register account sbc" if ( $insecure ) { $Parameters.insecure = $true } [Registration]::new(( Invoke-MediantCurlRequest @Parameters | ConvertFrom-Json | Select-Object -expand output )) } function format-mediantdailychecklist { [CmdletBinding(DefaultParametersetName = "default")] param( [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [MediantDailyChecklist]$mediant, [ValidateSet("basic", "detailed","debug")] [parameter(Position = 0, ParameterSetName = "default", Mandatory = $true)] [string]$schema ) switch($schema) { "basic" { $result = [ordered]@{} $result.Mediant = $mediant.Mediant $result.Firmware = $mediant.DeviceStatus.VersionID $result.SystemUptime = $mediant.uptime.time $result.OperationalState = $mediant.DeviceStatus.operationalState $result.ProductType = $mediant.DeviceStatus.productType $result.SaveNeeded = $mediant.DeviceStatus.saveNeeded $result.ResetNeeded = $mediant.DeviceStatus.resetNeeded #Bug ProxySet Not Resolved IDs $result.ProxySetOnline = $mediant.VoipStatus.ProxySet.online $result.ProxySetOffline = $mediant.VoipStatus.ProxySet.offline $result.ProxySetNotResolved = $mediant.VoipStatus.ProxySet.NotResolved #Bug Registrations Registrations/Notregistered #Bug Registrations ID $result.Registered = $mediant.VoipStatus.Registration.Registered $result.NotRegisted = $mediant.VoipStatus.Registration.NotRegistered #Bug Active Routes $result.NetworkActiveRoute = $mediant.NetworkStatus.NetworkRoute.ActiveRoute $result.NetworkInvalidRoute = $mediant.NetworkStatus.NetworkRoute.InvalidRoute $result.HAStatus = $mediant.HAStatus.State $result.HAStatus = $mediant.HAStatus.connection $result.HAStatus = $mediant.HAStatus.LastStart #Bug Physicial Ports $result.PhysicalPortUP = $mediant.NetworkStatus.PhysicalPort.up $result.PhysicalPortDown = $mediant.NetworkStatus.PhysicalPort.Down $result.NTPServer1 = $mediant.NTPStatus.Server1 $result.NTPServer2 = $mediant.NTPStatus.Server2 $result.NTPSynchronized = $mediant.NTPStatus.Synchronized $result.NTPReference = $mediant.NTPStatus.Reference $result.NTPLocalTime = $mediant.NTPStatus.LocalTime $result.SyslogIP = $mediant.RunningConfig.Troubleshoot.Syslog.Syslog $result.SyslogStatus = $mediant.RunningConfig.Troubleshoot.Syslog.Status $result } "detailed" { $result = [ordered]@{} $result.Mediant = $mediant.Mediant $result.operationalState = $mediant.DeviceStatus.operationalState $result.productType = $mediant.DeviceStatus.productType $result.VersionID = $mediant.DeviceStatus.VersionID $result.saveNeeded = $mediant.DeviceStatus.saveNeeded $result.resetNeeded = $mediant.DeviceStatus.resetNeeded $result.Uptime = $mediant.uptime.time $result.NTPStatus = $mediant.NTPStatus | Select-Object Server1,Server2,Synchronized,Reference,LocalTime $result.HAStatus = $mediant.HAStatus | Select-object State,connection,LastStart $result.Syslog = $mediant.RunningConfig.Troubleshoot.Syslog | Select-object Syslog,Status $result.ProxySet = $mediant.VoipStatus.ProxySet $result.Registrations = $mediant.VoipStatus.Registration $result } "debug" { $result = [ordered]@{} $result.Mediant = $mediant.Mediant $result.http = $mediant.http $result.filename = $mediant.filename $result.DeviceStatus = $mediant.DeviceStatus $result.SystemVersion = $mediant.SystemVersion.raw $result.Uptime = $mediant.Uptime.raw $result.NTPStatus = $mediant.NTPStatus.raw $result.HAStatus = $mediant.HAStatus.raw $result.RunningConfigFull = $mediant.RunningConfig.full.raw $result.RunningConfigNetwork = $mediant.RunningConfig.network.raw $result.RunningConfigSystem = $mediant.RunningConfig.system.raw $result.RunningConfigTroubleShoot = $mediant.RunningConfig.troubleshoot.raw $result.RunningConfigVoip = $mediant.RunningConfig.voip.raw $result.NetworkStatusPhysicalPort = $mediant.NetworkStatus.PhysicalPort.raw $result.NetworkStatusEthernetDevice = $mediant.NetworkStatus.EthernetDevice.raw $result.NetworkStatusEthernetGroup = $mediant.NetworkStatus.EthernetGroup.raw $result.NetworkStatusNetworkInterface = $mediant.NetworkStatus.NetworkInterface.raw $result.NetworkStatusNetworkRoute = $mediant.NetworkStatus.NetworkRoute.raw #??? $result.Alarms = $mediant.Alarms.raw $result.PerformanceMonitoring = $mediant.PerformanceMonitoring.raw $result.VoipStatus = $mediant.VoipStatus $result.ConfigCLI = $mediant.ConfigCLI $result.ConfigINI = $mediant.ConfigINI $result } } } #endregion #region classes class DeviceStatus { [String]$Mediant [String]$localTimeStamp [String]$ipAddress [String]$subnetMask [String]$defaultGateway [String]$productType [String]$versionID [String]$protocolType [String]$operationalState [String]$highAvailability [String]$serialNumber [String]$macAddress [String]$systemUpTime [String]$saveNeeded [String]$resetNeeded DeviceStatus() { } DeviceStatus([PSCustomObject]$DeviceStatus) { $this.Mediant = $DeviceStatus.Mediant $this.localTimeStamp = $DeviceStatus.localTimeStamp $this.ipAddress = $DeviceStatus.ipAddress $this.subnetMask = $DeviceStatus.subnetMask $this.defaultGateway = $DeviceStatus.defaultGateway $this.productType = $DeviceStatus.productType $this.versionID = $DeviceStatus.versionID $this.protocolType = $DeviceStatus.protocolType $this.operationalState = $DeviceStatus.operationalState $this.highAvailability = $DeviceStatus.highAvailability $this.serialNumber = $DeviceStatus.serialNumber $this.macAddress = $DeviceStatus.macAddress $this.systemUpTime = $DeviceStatus.systemUpTime $this.saveNeeded = $DeviceStatus.saveNeeded $this.resetNeeded = $DeviceStatus.resetNeeded } } class NTPStatus { [string]$Server1 [string]$Server2 [string]$Synchronized [string]$Stratum [string]$Reference [string]$Precision [string]$RootDelay [string]$RootDispersion [string]$ReferenceTime [string]$UTCOffset [string]$LocalTime [string] Hidden $Raw NTPStatus() { } NTPStatus([PSCustomObject]$NTPStatus) { $this.Server1 = mediantregex -string $NTPStatus -Capture "(?<=Configured NTP server #1 is) ([0-9]{1,3}[\.]){3}[0-9]{1,3}" $this.Server2 = mediantregex -string $NTPStatus -Capture "(?<=Configured NTP server #2 is ) ([0-9]{1,3}[\.]){3}[0-9]{1,3}" $this.Synchronized = mediantregex -string $NTPStatus -Capture "NTP is Synchronized" $this.Stratum = mediantregex -string $NTPStatus -Capture "(?<=stratum).*(?=, reference)" $this.Reference = mediantregex -string $NTPStatus -Capture "(?<=reference is) ([0-9]{1,3}[\.]){3}[0-9]{1,3}" $this.Precision = mediantregex -string $NTPStatus -Capture "(?<=Precision).*(?=seconds.\s\*\*\sRoot\sdelay)" $this.RootDelay = mediantregex -string $NTPStatus -Capture "(?<=Root delay).*(?=seconds.\s\*\*\sRoot\sdispersion)" $this.RootDispersion = mediantregex -string $NTPStatus -Capture "(?<=Root\sdispersion).*(?=seconds.\s\*\*\sReference)" $this.ReferenceTime = mediantregex -string $NTPStatus -Capture "(?<=Reference time ).*(?=\.\s\*\*\sUTC)" $this.UTCOffset = mediantregex -string $NTPStatus -Capture "(?<=UTC offset ).*(?=seconds.)" $this.LocalTime = mediantregex -string $NTPStatus -Capture "(?<=Current local time:).*(?=\.)" $this.Raw = mediantregex -string $NTPStatus -Capture ".*" } } class HAStatus { [string]$state [string]$connection [string]$LastStart [string] Hidden $Raw HAStatus() { } HAStatus ([PSCustomObject]$HAStatus) { $this.state = (mediantregex -string $HAStatus -capture "(?<=.*Unit HA state is: )\w+?(?=[.])") $this.connection = (mediantregex -string $HAStatus -capture "(?<=.*HA Connection with other unit State is: )\w+?(?=[.])") $this.LastStart = (mediantregex -string $HAStatus -capture "(?<=.*was: )\w+(.*)").replace(" ", "").replace(".", "") $this.raw = (mediantregex -string $HAStatus -Capture ".*") } } class Syslog { [string]$syslog [string]$status [string]$DebugLevel [string] Hidden $Raw Syslog() { } Syslog ([PSCustomObject]$Syslog) { $this.syslog = mediantregex -string $Syslog -capture "(?<=syslog-ip )([0-9]{1,3}[\.]){3}[0-9]{1,3}" $this.status = mediantregex -string $Syslog -capture "syslog\s(on)" $this.DebugLevel = mediantregex -string $Syslog -capture "(?<=debug-level)\w+?(?=[.])" $this.raw = $Syslog #(mediantregex -string $Syslog -Capture ".*")#.split("\. ",$option) } } #region Running Config class RunningConfigFull { [string] Hidden $Raw RunningConfigFull() { } RunningConfigFull([PSCustomObject]$RunningConfigFull) { $this.raw = $RunningConfigFull } } class RunningConfigNetwork { [string] Hidden $Raw RunningConfigNetwork() { } RunningConfigNetwork([PSCustomObject]$RunningConfigNetwork) { $this.raw = $RunningConfigNetwork } } class RunningConfigSystem { [string] Hidden $Raw RunningConfigSystem() { } RunningConfigSystem([PSCustomObject]$RunningConfigSystem) { $this.raw = $RunningConfigSystem } } class RunningConfigTroubleshoot { [Syslog]$Syslog [string] Hidden $Raw RunningConfigTroubleshoot() { } RunningConfigTroubleshoot([PSCustomObject]$RunningConfigTroubleshoot) { $this.syslog = [syslog]::new($RunningConfigTroubleshoot) $this.raw = $RunningConfigTroubleshoot } } class RunningConfigVoip { [string] Hidden $Raw RunningConfigVoip() { } RunningConfigVoip([PSCustomObject]$RunningConfigVoip) { $this.raw = $RunningConfigVoip } } #Primary Class class RunningConfig { [RunningConfigFull]$Full [RunningConfigNetwork]$Network [RunningConfigSystem]$System [RunningConfigTroubleshoot]$Troubleshoot [RunningConfigVoip]$Voip RunningConfig() { $this.Full = [RunningConfigFull]::new() $this.Network = [RunningConfigNetwork]::new() $this.System = [RunningConfigSystem]::new() $this.Troubleshoot = [RunningConfigTroubleshoot]::new() $this.Voip = [RunningConfigVoip]::new() } RunningConfig([MediantDailyChecklist]$mediant) { $this.Full = [RunningConfigFull]::new((mediantRunningConfig -mediant $mediant -type Full)) $this.Network = [RunningConfigNetwork]::new((mediantRunningConfig -mediant $mediant -type Network)) $this.System = [RunningConfigSystem]::new((mediantRunningConfig -mediant $mediant -type System)) $this.Troubleshoot = [RunningConfigTroubleshoot]::new((mmediantRunningConfig -mediant $mediant -type Troubleshoot)) $this.Voip = [RunningConfigVoip]::new((mediantRunningConfig -mediant $mediant -type Voip)) } } #endregion class PhysicalPort { [string]$Up [string]$Down [string] Hidden $Raw PhysicalPort () { } PhysicalPort ([PSCustomObject]$PhysicalPort) { $this.up = ([regex]::Matches($PhysicalPort, "UP" )).count $this.down = ([regex]::Matches($PhysicalPort, "DOWN" )).count $this.raw = $PhysicalPort } } class EthernetDevice { [string] Hidden $Raw EthernetDevice () { } EthernetDevice ([PSCustomObject]$EthernetDevice) { $this.raw = $EthernetDevice } } class EthernetGroup { [string] Hidden $Raw EthernetGroup () { } EthernetGroup ([PSCustomObject]$EthernetGroup) { $this.raw = $EthernetGroup } } class NetworkInterface { [string] Hidden $Raw NetworkInterface () { } NetworkInterface ([PSCustomObject]$NetworkInterface) { $this.raw = $NetworkInterface } } class NetworkRoute { [string]$ActiveRoute [string]$InactiveRoute [string] Hidden $Raw NetworkRoute () { } NetworkRoute ([PSCustomObject]$NetworkRoute) { $this.ActiveRoute = ([regex]::Matches($NetworkRoute, "ACTIVE" )).count $this.InactiveRoute = ([regex]::Matches($NetworkRoute, "INACTIVE" )).count $this.raw = $NetworkRoute } } class NetworkStatus { [PhysicalPort]$PhysicalPort [EthernetDevice]$EthernetDevice [EthernetGroup]$EthernetGroup [NetworkInterface]$NetworkInterface [NetworkRoute]$NetworkRoute [string] Hidden $Raw NetworkStatus() { $this.PhysicalPort = [PhysicalPort]::new() $this.EthernetDevice = [EthernetDevice]::new() $this.EthernetGroup = [EthernetGroup]::new() $this.NetworkInterface = [NetworkInterface]::new() $this.NetworkRoute = [NetworkRoute]::new() } NetworkStatus ([MediantDailyChecklist]$mediant) { $this.PhysicalPort = mediantPhysicalPort -mediant $mediant $this.EthernetDevice = mediantEthernetDevice -mediant $mediant $this.EthernetGroup = mediantEthernetGroup -mediant $mediant $this.NetworkInterface = mediantNetworkInterface -mediant $mediant $this.NetworkRoute = MediantNetworkRoute -mediant $mediant } } class Alarms { [string] Hidden $Raw Alarms () { } Alarms ([PSCustomObject]$alarms) { $this.raw = $Alarms } } class PerformanceMonitoring { [string] Hidden $Raw PerformanceMonitoring () { } PerformanceMonitoring ([PSCustomObject]$PerformanceMonitoring) { $this.raw = $PerformanceMonitoring } } class ProxySet { [string]$Online [string]$Offline [string]$NotResolved [string] Hidden $Raw ProxySet () { } ProxySet ([PSCustomObject]$ProxySet) { $this.Online = ([regex]::Matches($ProxySet, "ONLINE" )).count $this.Offline = ([regex]::Matches($ProxySet, "OFFLINE" )).count $this.NotResolved = ([regex]::Matches($ProxySet, "NOT RESOLVED" )).count $this.raw = $ProxySet } } class Registration { [String]$Registered [String]$NotRegistered [string] Hidden $Raw Registration () { } Registration ([PSCustomObject]$Registration) { $this.Registered = ([regex]::Matches($Registration, "REGISTERED" )).count $this.NotRegistered = ([regex]::Matches($Registration, "NOT REGISTERED" )).count $this.raw = $Registration } } class VoipStatus { [ProxySet]$ProxySet [Registration]$Registration VoipStatus() { $this.ProxySet = [ProxySet]::new() $this.Registration = [Registration]::new() } VoipStatus ([MediantDailyChecklist]$mediant) { $this.ProxySet = mediantProxySet $mediant $this.Registration = mediantRegistration $mediant } } class SystemVersion { [string] Hidden $Raw SystemVersion () { } SystemVersion ([PSCustomObject]$SystemVersion) { $this.raw = $SystemVersion } } class Uptime { [String]$days [String]$hours [String]$minutes [String]$seconds [String]$time [string] Hidden $Raw uptime() { } uptime ([PSCustomObject]$uptime) { $this.days = mediantregex -string $uptime -Capture "(?<=Uptime: ).*(?= days)" $this.hours = mediantregex -string $uptime -Capture "(?<=days, ).*(?= hours)" $this.minutes = mediantregex -string $uptime -Capture "(?<=hours, ).*(?= minutes)" $this.seconds = mediantregex -string $uptime -Capture "(?<=minutes, ).*(?= seconds)" $this.time = ($uptime).TrimStart('Uptime: ').Replace(",","").Replace(".","") $this.raw = $uptime } } class MediantDailyChecklist { [string]$Mediant [pscredential]$credential [ValidateSet("https", "http")] [string]$http = "HTTPS" [string]$filename [DeviceStatus]$DeviceStatus [SystemVersion]$SystemVersion [Uptime]$Uptime [NTPStatus]$NTPStatus [HAStatus]$HAStatus [RunningConfig]$RunningConfig [NetworkStatus]$NetworkStatus [Alarms]$Alarms [PerformanceMonitoring]$PerformanceMonitoring [VoipStatus]$VoipStatus [string] hidden $ConfigCLI [string] hidden $ConfigINI MediantDailyChecklist () { $this.Http = "HTTPS" $this.DeviceStatus = [DeviceStatus]::new() $this.SystemVersion = [SystemVersion]::new() $this.uptime = [Uptime]::new() $this.NTPStatus = [NTPStatus]::new() $this.HAStatus = [HAStatus]::new() $this.RunningConfig = [RunningConfig]::new() $this.NetworkStatus = [NetworkStatus]::new() $this.Alarms = [Alarms]::new() $this.PerformanceMonitoring = [PerformanceMonitoring]::new() $this.VoipStatus = [VoipStatus]::new() } MediantDailyChecklist ([string]$Mediant, [pscredential]$Credential, [string]$Http) { $this.Mediant = $Mediant $this.Credential = $Credential $this.Http = $Http $this.DeviceStatus = [DeviceStatus]::new() $this.SystemVersion = [SystemVersion]::new() $this.uptime = [Uptime]::new() $this.NTPStatus = [NTPStatus]::new() $this.HAStatus = [HAStatus]::new() $this.RunningConfig = [RunningConfig]::new() $this.NetworkStatus = [NetworkStatus]::new() $this.Alarms = [Alarms]::new() $this.PerformanceMonitoring = [PerformanceMonitoring]::new() $this.VoipStatus = [VoipStatus]::new() } MediantDailyChecklist ([pscustomobject]$Mediant) { $this.Mediant = $Mediant.Mediant $this.Credential = $Mediant.Credential $this.Http = $mediant.Http $this.DeviceStatus = [DeviceStatus]::new() $this.SystemVersion = [SystemVersion]::new() $this.uptime = [Uptime]::new() $this.NTPStatus = [NTPStatus]::new() $this.HAStatus = [HAStatus]::new() $this.RunningConfig = [RunningConfig]::new() $this.NetworkStatus = [NetworkStatus]::new() $this.Alarms = [Alarms]::new() $this.PerformanceMonitoring = [PerformanceMonitoring]::new() $this.VoipStatus = [VoipStatus]::new() } } #endregion Write-verbose -Message "JsonFile : $jsonfile" Write-verbose -Message "OutputFolder : $outputFolder" if ( !$nostats ) { mediantstats } if ( $insecure ) { Set-MediantTrustAllCertPolicy } [array]$MediantDailyChecklist = mediantimport -jsonfile $jsonFile if ($null -eq $MediantDailyChecklist) { write-warning "No Mediant Devices Available... exiting"; break } foreach ($Mediant in $MediantDailyChecklist) { write-Verbose -Message "Data Collection -> $($mediant.mediant)" # filename (Ok) $mediant.filename = "$($mediant.mediant)_$((get-date).tostring('yyMMdd'))" Write-Verbose -Message "Filename -> $mediant.filename" # DeviceStatus (Ok) $mediant.DeviceStatus = mediantDeviceInfo -mediant $mediant # SystemVersion (improve) $mediant.SystemVersion = mediantSystemVersion -mediant $mediant # Uptime (Ok) $mediant.Uptime = mediantUptime -mediant $mediant # NTPStatus (Ok) $mediant.NTPStatus = mediantNTPStatus -mediant $mediant # HAStatus (Ok) $mediant.HAStatus = mediantHAStatus -mediant $mediant # RunningConfig (OK) # Bug Debuglevel not working correctly $mediant.RunningConfig.Full = mediantRunningConfig -mediant $mediant -type full $mediant.RunningConfig.Network = mediantRunningConfig -mediant $mediant -type network $mediant.RunningConfig.System = mediantRunningConfig -mediant $mediant -type system $mediant.RunningConfig.Troubleshoot = mediantRunningConfig -mediant $mediant -type troubleshoot $mediant.RunningConfig.Voip = mediantRunningConfig -mediant $mediant -type voip # NetworkStatus (Needed) $mediant.NetworkStatus = mediantNetworkStatus -mediant $mediant # Alarms (Next) $mediant.Alarms = mediantAlarms -mediant $mediant # PerformanceMonitoring (Next) $mediant.PerformanceMonitoring = mediantPerformanceMonitoring -mediant $mediant # VoipStatus (Needed) $mediant.VoipStatus = mediantVoipStatus -mediant $mediant # ConfigCLI (testing) $mediant.ConfigCLI = mediantbackup -mediant $mediant -type cliscript if ($backupCLI) { mediantbackup -mediant $mediant -type cliscript -writefile } # ConfigINI (testing) $mediant.ConfigINI = mediantbackup -mediant $mediant -type ini if ($backupINI) { mediantbackup -mediant $mediant -type ini -writefile } } foreach ($Mediant in $MediantDailyChecklist) { if ($outputfolder) { format-mediantdailychecklist -mediant $mediant -schema $schema | convertto-json | out-file -FilePath (join-path -path $outputFolder -childpath ("$($Mediant.Filename).json"))} else { format-mediantdailychecklist -mediant $mediant -schema $schema } } # SIG # Begin signature block # MIINHwYJKoZIhvcNAQcCoIINEDCCDQwCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQ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ahY7uI+C6ZSW+R9sXm+CIQQkMYhXs8LFM2kNf # a9GKcX1nPZPVmqxMcK6AJYnOnV4EnENEzAdYBhm1erUoXrx+7++yiK3JFrGZ6WBK # kGJpxrwRh76vl5FG0DcjUOuWCInb9x6x7etmljY0/CxfqO7+u9cLuWuqFUqelEdB # uIA0BHQRkSj3WOse4od38eG16ytfD/Mt//ODY4KOjdC5G0FlrRO1+HGubRqs2YYK # L32N # SIG # End signature block |