Skip to content

Commit

Permalink
Version 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chn-lee-yumi committed Aug 26, 2018
1 parent f2af36c commit 51c1d42
Show file tree
Hide file tree
Showing 18 changed files with 1,236 additions and 1,765 deletions.
27 changes: 11 additions & 16 deletions Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,31 @@
WEB_PASSWORD = '12345' # 网页登录的密码
WEB_PORT = 80 # http端口

# =============Ping模块参数=============
# =============扫描参数=============
TCPING_TIMEOUT = 2 # tcping超时时间,秒
SCAN_THREADS = 65
SCAN_PROCESS = 4

# =============监控参数=============
# DEAFULT_PING_INTERVAL = 30 # 扫描间隔,秒,默认30
# DEAFULT_CPU_INTERVAL = 1 # CPU扫描间隔,分钟,默认1
# SWITCH_DOWN_ALERT_TIMES = 6 # 接入交换机连续多少轮扫描都offline才报警,默认6
# THREE_TIER_SWITCH_DOWN_ALERT_TIMES = 3 # 汇聚交换机连续多少轮扫描都offline才报警,默认3
# SWITCH_OVERLOAD_ALERT_TIMES = 3 # 接入交换机连续多少轮扫描都overload才报警,默认3
# SWITCH_UP_AND_DOWN_ALERT_TIMES = 5 # 接入交换机连续挂了又复活多少次才报警,默认5
# DELAY_STAT_TIME = 30 # 延迟发统计信息的时间,秒,默认30
HELPDESK_TIME = 5 # 微信通知/发送工单的延迟,分钟
HELPDESK_TIME = 5 # 微信通知的延迟,分钟
WEIXIN_STAT_TIME_H = 18 # 发送微信统计的时
WEIXIN_STAT_TIME_M = 0 # 发送微信统计的分
SW_REBOOT_TIME_H = 4 # 自动重启交换机的时
SW_REBOOT_TIME_M = 0 # 自动重启交换机的分
CPU_THRESHOLD = 80 # CPU过载阈值
MEM_THRESHOLD = 80 # 内存过高阈值
TEMP_THRESHOLD = 60 # 温度过高阈值
DATA_RECORD_INTERVAL = 5 # 历史记录保存间隔,单位分钟
DATA_RECORD_INTERVAL = 1 # 历史记录保存间隔,单位分钟
DATA_RECORD_SAVED_DAYS = 2 # 历史记录保留天数

# =============SNMP参数=============
SNMP_READ_COMMUNITY = "123456"
SNMP_WRITE_COMMUNITY = "654321"
SNMP_READ_COMMUNITY = "public"
SNMP_WRITE_COMMUNITY = "private"

# =============交换机密码=============
SWITCH_PASSWORD = "3.141592653589793238"
SWITCH_PASSWORD = "123456"

# =============微信接入参数=============
corpid = "wxsakgheity3w9t"
corpsecret = ['', '', 'DFery43g45fW45tgg4th64hdsghiwhil, '', '', '',
'URD45VB7jkg89gu8YNIUG78i87b89n8B8n890bUg']
corpid = "wx09d7623hjg734"
corpsecret = ['', '', 'WsXbVPLqxcNMUY_Okfjrell723ERG2uREnCvZQ5IgwAOS8', '', '', '',
'jKFitXrTpzWpxRdfsghkj34hGR3YTXiWjUzZOs1JpM']
699 changes: 306 additions & 393 deletions Controller.py

Large diffs are not rendered by default.

71 changes: 39 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
# 广东工业大学交换机监控

- 2016年“数字校园”学生科技项目。(已结题,但仍在持续更新)
- 由于权限问题,目前只监控大学城校区学生宿舍的交换机和生活区核心交换机。未对教学区和其它校区的交换机进行适配。
- 最新版本为5.1.0。
- 最新版本为5.2.0。
- 使用GPLv3开源协议。

# 部署说明

## 设备

- 推荐配置:
- CPU:4核
- 内存:1GB
- CPU:4核
- 内存:1GB
- 可运行在树莓派2B上。

## 系统环境
- Windows和Linux均可

- 操作系统:Linux
- 环境:Python3
- 依赖包:requests、flask
- 依赖包:flask、python3-netsnmp

## Debian系统部署

```shell
apt-get install python3 snmp
pip3 install requests
pip3 install flask
# 需要root权限
apt-get install python3 python3-pip
pip3 install flask python3-netsnmp
python3 SwitchMonitor.py # 运行
```
## Windows系统部署
- 从python.org下载安装python3
- 在cmd输入下面命令
```shell
pip install requests
pip install flask
python SwitchMonitor.py # 运行
```

## 参数说明

- 必须要修改的参数:(Config.py)
- web_username:网页用户名
- web_password:网页登录密码
- switch_password:交换机密码
- corpid:微信开放平台corpid
- corpsecret:微信开放平台corpsecret
- SNMP_COMMUNITY:SNMP读写密码
- web_username:网页用户名
- web_password:网页登录密码
- switch_password:交换机密码
- corpid:微信开放平台corpid
- corpsecret:微信开放平台corpsecret
- SNMP_COMMUNITY:SNMP读写密码
- 默认报警参数(详见Config.py)
- 交换机掉线5分钟后发送微信通知以及提交工单
- 每天下午18点发送统计信息。每天凌晨4点自动重启过载的交换机。
- CPU过载阈值:80%
- 内存过高阈值:80%
- 温度过高阈值:60℃
- 交换机掉线5分钟后发送微信通知
- 每天下午18点发送统计信息。每天凌晨4点自动重启过载的交换机。
- CPU过载阈值:80%
- 内存过高阈值:80%
- 温度过高阈值:60℃

# 更新日志

- v5.2.0:
- 部分代码重构
- 更新SNMP模块,提高速度
- 优化网页交互体验
- 修复一些BUG
- v5.1.0:
- 整合部分参数到配置文件
- 性能调优,加快启动速度,减少CPU占用。
- 现在交换机端口历史流量页面修改单位后不会重新获取数据,提高了相应速度。
- 修复一些小BUG
- 整合部分参数到配置文件
- 性能调优,加快启动速度,减少CPU占用。
- 现在交换机端口历史流量页面修改单位后不会重新获取数据,提高了相应速度。
- 修复一些小BUG
- v5.0.0:
- 重构代码。
- 重构代码。
1 change: 0 additions & 1 deletion RunSwitchMonitor(WINDOWS).bat

This file was deleted.

Binary file removed bin/netsnmp.dll
Binary file not shown.
Binary file removed bin/snmpset.exe
Binary file not shown.
Binary file removed bin/snmpwalk.exe
Binary file not shown.
202 changes: 0 additions & 202 deletions mod_helpdesk.py

This file was deleted.

4 changes: 0 additions & 4 deletions mod_new_helpdesk.py

This file was deleted.

14 changes: 8 additions & 6 deletions mod_reboot_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import telnetlib
import time
import traceback
import mod_snmp
from mod_snmp import SnmpSet
from Config import SWITCH_PASSWORD

'''
Expand Down Expand Up @@ -33,9 +33,9 @@ def reboot_switch_telnet(ip):
tn.write("y\n".encode('gbk'))
print('Send "y"')
if a.decode('GBK').find('This command will reboot the device') != -1:
a=tn.read_until("):".encode('gbk'), 60)
a = tn.read_until("):".encode('gbk'), 60)
print(a)
if a.decode==':y':
if a.decode == ':y':
tn.close()
print('reboot succeed!')
return
Expand All @@ -54,15 +54,17 @@ def reboot_switch_telnet(ip):
a = traceback.format_exc()
print(a[a.find('Error:') + 7:])


def reboot_switch_snmp(ip):
a=mod_snmp.SnmpSet(ip,'S2700',"reboot")# E152B不支持SNMP重启(我没找到MIB节点)
# print("重启交换机",ip,a)
a = SnmpSet(ip, 'S2700', "reboot") # E152B不支持SNMP重启(我没找到MIB节点)
print("重启交换机", ip, a)
return 0


def reboot_switches(ips):
for ip in ips:
reboot_switch_snmp(ip)
#reboot_switch_telnet(ip)
# reboot_switch_telnet(ip)


'''
Expand Down
Loading

0 comments on commit 51c1d42

Please sign in to comment.