############################################
#Author:Lixiaosong
#Email;[email protected]
#For:监控无线AP运行状态
#Version:1.0 2015年6月1日
############################################
$aps=0,1,2,3,4,5,6,7,12,13,14,15
$aplist = @()
foreach($ap in $aps){
$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("admin", $secpasswd)
New-SSHSession -ComputerName 192.168.0.1 -Credential $creds -AcceptKey
$SSHStream = New-SSHShellStream -Index 0
Start-Sleep 2
$SSHStream.Write("sys`n")
$SSHStream.Write("wlan`n")
$SSHStream.Write("display ap-performance-statistic id $ap `n")
Start-Sleep 2
$apclient=$SSHStream.Read()
$cpu=(($apclient |findstr.exe "CPU")[0]).replace("  CPU use rate: ","")
$memory=(($apclient |findstr.exe "Memory")[0]).replace("  Memory use rate: ","")
$temperature=(($apclient |findstr.exe "Temperature").replace("  Temperature: ","")).replace(" ??","")+"℃"
$users=($apclient |findstr.exe "Online").replace("  Online user number: ","" )
$portrate=(($apclient |findstr.exe "rate")[4]).replace("  Up port rate: ","" )
Remove-SSHSession -Index 0
echo $ap $apclient
$apobject=New-object psobject
$apobject | Add-Member -membertype noteproperty -Name APID          -value $ap
$apobject | Add-Member -membertype noteproperty -Name 用户数        -Value $users
$apobject | Add-Member -membertype noteproperty -Name CPU使用率     -value $cpu
$apobject | Add-Member -membertype noteproperty -Name 内存使用率    -Value $memory
$apobject | Add-Member -membertype noteproperty -Name 运行温度      -value $temperature
$apobject | Add-Member -membertype noteproperty -Name 端口速率      -Value $portrate
$aplist+=$apobject
}
$EmailbodyHTML=$aplist|
sort-object 用户数 |
ConvertTo-Html |
Out-String
$password = convertto-securestring "password" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist [email protected],$password
Send-Mailmessage -from  [email protected] -credential $cred -to [email protected] -Bodyashtml $EmailbodyHTML -Subject "无线AP负载通知"  -port 587 -UseSsl -smtpserver smtp.exmail.qq.com -Encoding ([System.Text.Encoding]::UTF8)

邮件监控效果:

通过Powershell 来监控华为无线设备_第1张图片