maper 发表于 2009-6-23 22:06:28

上面的这个我是在zmud7.21下面测试通过的。

chengsan 发表于 2009-6-23 22:12:43

谢谢
晃荡这么久,看来还是要回到zmud
现在连不上交换机,明天测试
sh arp返回数据是非常快的,瞬间一屏
#say %1 %2能跟上速度,在每行后面显示
也许#wa #alarm又有了用武之地

icer 发表于 2009-6-23 22:27:28

也许确实应该加#wa,在同一次sh arp里每条数据分别#wa 1、2、3...秒可能就没问题了

chengsan 发表于 2009-6-23 23:13:35

刚才到处查资料发现,很多人为了配置自动登录、设置路由器
自己做了些不通用、需要经常修改的程序
他们竟然不知道还有zmud

chengsan 发表于 2009-6-24 17:40:36

重新学习了zmud7.21数据库部分的帮助文档,调试1天还是失败了
感觉上就是交换机回显速度太快,基本上就类似于从本地文本发送到zmud的速度 #send {c:\a.txt}
经过测试#wa #alarm都不可行,#wa只是中断了dbput而已,tr继续执行
#alarm同样的道理,虽然是延时dbput,但是变量值已经被tr修改了
新的主要更新代码:
Internet%s(%x)%s(%x)%s(%x)%s%x%s(%x)
#addkey ip {ipmac=%1m%3|ip=%1|mac=%3|age=%2|vlan=%4|time=%time( c)}
#if (%find( @ip.ipmac)) {#dbput {%find( @ip.ipmac)} {@ip}} {#new {ip} {@ip}}
说明:单条显示,更新没有问题
于是想到tr执行时把取到的数据全部保存到变量,最后一次性更新:
#al sharp {i=1;sh arp;#10 #send " "}send命令用于发送一个空格给交换机,继续显示下一屏(用tr #wa等待,dbput照样重复,一屏内容就很多)
tr改为:
#addkey ip@i {ipmac=%1m%3|ip=%1|mac=%3|age=%2|vlan=%4|time=%time( c)}
#add i 1
执行结果是i=200, 增加了ip1-200共计200个rec变量
现在的问题是:
ip200变量中的内容怎么读取,@ip@i.ipmac不行@{ip@i}.ipmac也不行
最后还要unvar吧,
也不知道实际运行时间长了,内存消耗如何。
看到zmud7.21支持vbs js,能否采用三维数组保存?
继续测试去了,以前用过@ip.@i的方式,倒是没有问题

duno 发表于 2009-6-24 19:08:15

这里可能存在两种冲突
读读%find与%find
读写%find与#dbput

本地内存缓存,如hash,来的数据即时跟新缓存
单起一个流程,不断遍历缓存,更新最终数据库,这样就可以确认上一次操作结束或超时才进行下一个,从容进行
上G的内存,几千万条这种记录应该不成问题

maper 发表于 2009-6-24 20:30:32

我做了下测试,是没什么问题的,下面我把我的测试方法说一下。
新建一个test.txt记事本,里面输入的数据如下:
测试开始
show 192.168.1.1 4D-5F-2C-AC-DA 2009-06-24
......
show 192.168.1.2 4D-5F-2C-AC-DA 2009-06-24
......
show 192.168.1.3 4D-5F-2C-AC-DA 2009-06-24
.......
测试结束

说明:因为没有接触过交换机,我不知道数据是怎么样的,所以自己假设了一下,这里只有ip是变化的,因为后面的触发是检索ipmac,所以其他变不变化无所谓。

建立数据库:
数据库的fields有:ip 、 mac、ipmac、time、age,类型都为txt

建立触发如下:
#TRIGGER {show%s(%x)%s(%x)%s(%x)} {#add num 1;#var ipmac %1m%2;#if (%find( @ipmac, all, ipmac)) {#dbput %find( @ipmac, all, ipmac) {ip=%1|mac=%2|age=%3|ipmac=@ipmac|time=%time( c)}} {#new all {ip=%1|mac=%2|age=%3|ipmac=@ipmac|time=%time( c)}}}
#TRIGGER {测试结束} {#show @num}
#TRIGGER {测试开始} {#var num 0}

这里对%find命令和#dbput做一下说明:
1、%find
Syntax: %find(s[,view,col]))

returns a list of records in a database whose first column contains the string s.If view is specified, it is a string list whose first value is the name of the View to search, and optional second item is the two-character database name.Col is the name of the column to search instead of the first column and is optional.The string list that is returned is a list of record numbers with the database name attached.
s为要检索的字符串,view是视图,这里默认为all,col是要检索的fields。
对应上面触发的就是:%find( @ipmac, all, ipmac)   ;表示在all视图的ipmac中检索@ipmac

2、#dbput
Syntax: #DBPUT database-rec value-list
Saves new data to an existing database record.database-rec is the record number to set, with the optional two-character database name appended to it.The value-list is either a database variable, or a series of field names and values for the fields, or of th format "Name1=Value1|Name2=Value2|etc"

DBPUT Examples
#DBPUT 20 Name Zugg Class Warrior
sets the Name and Class fields of record 20 to Zugg and Warrior respectively

从例子中可以看出#dbput 后面要带序号再带内容。
对应触发是:#dbput %find( @ipmac, all, ipmac) {ip=%1|mac=%2|age=%3|ipmac=@ipmac|time=%time( c)}

好下面看一下结果


从图片中可以看出,共载入208条数据,数据库中ipmac栏没有重复的数据,说明测试是成功的。
另外我测试过把数据增加到5000条,然后用#send输入,也不会出现重复数据。

这是我的测试数据


[ 本帖最后由 maper 于 2009-6-24 08:34 PM 编辑 ]

icer 发表于 2009-6-24 20:38:01

向各位热心的大牛致敬!yct23

chengsan 发表于 2009-6-24 21:04:30

致敬
在家也无法访问交换机
完全按照maper步骤自己测试一下
也希望路过的朋友都学习一下,现在局域网、城域网非常多的交换机、路由器
大多数高昂的管理软件通过http snmp等方式,或多或少存在问题
不如telnet灵活
大家有zmud的基础,需要的时候非常有优势

ppeng 发表于 2009-6-25 07:09:52

oh..man..yct3
页: 1 2 [3] 4 5
查看完整版本: [已解决]用zmud telnet方式登录交换机、路由器,查询相关信息加入数据库的方法