码迷,mamicode.com
首页 > 系统相关 > 详细

通过Powershell 来监控华为无线设备

时间:2015-08-30 23:32:31      阅读:435      评论:0      收藏:0      [点我收藏+]

标签:华为   监控   无线   email   

############################################
#Author:Lixiaosong
#Email;lixiaosong8706@gmail.com
#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 noreply@126.com,$password
Send-Mailmessage -from  noreply@qq.com -credential $cred -to user@qq.com -Bodyashtml $EmailbodyHTML -Subject "无线AP负载通知"  -port 587 -UseSsl -smtpserver smtp.exmail.qq.com -Encoding ([System.Text.Encoding]::UTF8)

邮件监控效果:

技术分享

本文出自 “运维人生” 博客,请务必保留此出处http://lixiaosong.blog.51cto.com/705126/1689893

通过Powershell 来监控华为无线设备

标签:华为   监控   无线   email   

原文地址:http://lixiaosong.blog.51cto.com/705126/1689893

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!