2009年4月10日星期五

Mobile Broadband --- 上网本风暴接近中

在国外正在流行的无线上网本风暴,很快就要在国内登录了。
今天在某移动运营商处见到两台用来做测试的上网本,一台是Dell的,型号好象是Mini 9,另一台是方正的,没记着型号。方正的外形比较憨厚,键盘却又很娇小,敲打起来不是很舒服;而Dell的外观和手感还不错。
在两台上网本的键盘手托处都贴有一个“mobile broadband”以及运营商自己的3G标记。据说该本本卖3千多块,包括2500的预付上网费用,折算下本本只需要900元左右。

上网本本身除了都带有RJ45的有线网卡和WIFI无线网卡外,还内置了3G HSDPA高速上网卡。

2009年4月8日星期三

一輩子受用的 Regular Expressions -- 兼談另類的電腦學習態度 (更新)

一輩子受用的 Regular Expressions -- 兼談另類的電腦學習態度 是一位台湾同胞关于RE的文章,最近再次温习,发现又有更新了。

2009年3月10日星期二

收集Cisco交换机配置的小工具


前段时间做care的同事提出,在平时维护时发现以前安装调测的交换机上有很多不规范或错误的配置。这大概都是由于验收时无法去很仔细地看配置造成的。由此想到有没有一个工具可以提取交换机的配置,生成一个易读的报告?在网上用Cisco Configuration parser做keyword搜了一下,只找到一个用perl写的只能分析出交换机接口的脚本,用处不大。于是自己用Python写了一个sw_confparser,目前基本上能达到当初的目的,就差完善相关的配置模板了。

脚本上传到google code的net-mon-man项目里了,下载在这里

sw_confparser.py使用说明
sw_confparser可以将交换机的配置提取出来,导入到excel或数据库里去。
sw_confparser需要两个文件:
  1. cisco交换机的show running config命令的输出文本
  2. 以yaml格式编写的交换机配置模板。例子如下:
#more c6509.yml

Hostname:
configname: [Hostname]
pattern: hostname (.*)

hardware:
configname: [Name,description,PID,VID,SN]
pattern: |
NAME: "(.*)", DESCR: "(.*)"
PID: (.*), VID: (.*), SN: (.*)

Memory:
configname: [Free memory,Used memory]
pattern: cisco WS-C6509-E \(R7000\) processor \(revision 1.2\) with (.*)/(.*) bytes of memory

IOS Version:
configname: [IOS version]
pattern: IOS \(tm\) s3223_rp Software \(s3223_rp-IPBASEK9-M\), Version (.*), RELEASE SOFTWARE \(fc3\)

ROM version:
configname: [Rom version]
pattern: "ROM: System Bootstrap, Version (.*), RELEASE SOFTWARE"

System Image:
configname: [Image file]
pattern: System image file is "(.*)"

System Register:
configname: [Register]
pattern: Configuration register is (.*)

Timezone:
configname: [Timezone]
pattern: clock timezone (.*)

STP Mode:
configname: [STP Mode]
pattern: spanning-tree mode (.*)

Log Server:
configname: [Log Server]
pattern: logging (\d+.\d+.\d+.\d+)

Snmp Agent:
configname: [RO string, RW string, trap-source]
pattern: |
snmp-server community (\w+) RO
snmp-server community (\w+) RW
snmp-server trap-source (\w+)
SNMP Trap Server:
configname: [server address,server string]
pattern: snmp-server host (\d+.\d+.\d+.\d+) (\w+)

NTP server:
configname: [server]
pattern: ntp server (\d+.\d+.\d+.\d+)

Static Route:
configname: [dest, netmark, gateway,description]
pattern: |
ip route (\d+.\d+.\d+.\d+) (\d+.\d+.\d+.\d+) (\d+.\d+.\d+.\d+) name (.*)

将以上两个文件作为脚本的参数执行,就可以啦。如不加任何参数则会打印出帮助信息。

输出例子:
python sw_confparser.py log/dgswtest1.log c6509.yml -c

///// Parsing schema:c6509.yml...

Log Server|None
System Image|sup-bootdisk:s3223-ipbasek9-mz.122-18.SXF5.bin
ROM version|12.2(17r)SX3
IOS Version|12.2(18)SXF5
Hostname|SW301
STP Mode|pvst
NTP server|21.17.1.15
Timezone|Beijing 8
System Register|0x2102
Snmp Agent|RO string|RW string|trap-source
Static Route|dest|netmark|gateway|description
Static Route|0.0.0.0|0.0.0.0|121.17.70.136|TO_GnFW_Gn7_VRRP
Static Route|10.201.55.192|255.255.255.192|10.201.147.34|TO_GZOSS
Static Route|10.201.57.64|255.255.255.192|10.201.147.34|TO_GZWANGWEI
Static Route|10.201.62.0|255.255.255.0|10.201.147.34|TO_ANQUANWANGGUAN
Static Route|10.243.163.128|255.255.255.192|10.201.147.34|TO_GZOM
Static Route|10.245.107.0|255.255.255.128|10.201.147.34|TO_SZOM
Static Route|10.245.108.0|255.255.255.192|10.201.147.34|TO_DGSGSN_GA
Static Route|10.245.111.0|255.255.255.192|10.201.147.34|TO-DGLAN1_LAN2-OM
Static Route|132.119.19.0|255.255.255.0|10.201.147.34|TO_DGOM
hardware|Name|description|PID|VID|SN
hardware|WS-C6509-E|Cisco Systems Catalyst 6500 9-slot Chassis System|WS-C6509-E|V02|SMG1015NEF3
hardware|WS-C6K-VTT-E 1|VTT-E FRU 1|WS-C6K-VTT-E||SMT1008J988
hardware|WS-C6K-VTT-E 2|VTT-E FRU 2|WS-C6K-VTT-E||SMT1008A415
hardware|WS-C6K-VTT-E 3|VTT-E FRU 3|WS-C6K-VTT-E||SMT1008J807
hardware|CLK-7600 1|OSR-7600 Clock FRU 1|CLK-7600||SMT1005B110
hardware|CLK-7600 2|OSR-7600 Clock FRU 2|CLK-7600||SMT1005B110
hardware|1|WS-X6148A-GE-TX 48-port 10/100/1000 RJ45 EtherModule Rev. 1.6|WS-X6148A-GE-TX|V03|SAL1221RF94
hardware|2|WS-X6148-RJ-45 48-port 10/100 mb RJ45 Rev. 5.1|WS-X6148-RJ-45|V01|SAL1012H0KA
hardware|3|WS-X6148A-GE-TX 48-port 10/100/1000 RJ45 EtherModule Rev. 1.6|WS-X6148A-GE-TX|V03|SAL1221RF7G
hardware|5|WS-SUP32-GE-3B 9 ports Supervisor Engine 32 8GE Rev. 4.2|WS-SUP32-GE-3B|V02|SAL1014HYEZ
hardware|msfc sub-module of 5|WS-F6K-MSFC2A Cat6k MSFC 2A daughterboard Rev. 3.0|WS-F6K-MSFC2A||SAL1014HXYT
hardware|switching engine sub-module of 5|WS-F6K-PFC3B Policy Feature Card 3 Rev. 2.1|WS-F6K-PFC3B||SAL1013H7Q1
hardware|6|WS-SUP32-GE-3B 9 ports Supervisor Engine 32 8GE Rev. 4.2|WS-SUP32-GE-3B|V02|SAL1014J1DR
hardware|msfc sub-module of 6|WS-F6K-MSFC2A Cat6k MSFC 2A daughterboard Rev. 3.0|WS-F6K-MSFC2A||SAL1014HXXF
hardware|switching engine sub-module of 6|WS-F6K-PFC3B Policy Feature Card 3 Rev. 2.1|WS-F6K-PFC3B||SAL1014HX56
hardware|WS-C6509-E-FAN 1|Enhanced 9-slot Fan Tray 1|WS-C6509-E-FAN|V02|DCH10091210
hardware|PS 1 WS-CAC-3000W|AC power supply, 3000 watt 1|WS-CAC-3000W|V01|AZS10521F0T
hardware|PS 2 WS-CAC-3000W|AC power supply, 3000 watt 2|WS-CAC-3000W|V01|AZS10100ASN
Memory|Free memory|Used memory
Memory|227328K|34816K
SNMP Trap Server|server address|server string
这是帮助信息:
# python sw_confparser.py
Usage: sw_confparser.py logfile schema1 schema2 ... [options]

example: sw_confparser.py switch.log c6509.yml -vs

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-d, --debug print the debug information
-v, --verbose output the records and table infomation
-s, --single output the single records only
-t, --table output the table records only
-c, --csv output the records with csv formation