Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
74149f93
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
74149f93
编写于
3月 21, 2014
作者:
曾
曾伟伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
u
上级
a18989a2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
69 addition
and
72 deletion
+69
-72
cat-script/switchcat.py
cat-script/switchcat.py
+69
-72
未找到文件。
cat-script/switchcat.py
浏览文件 @
74149f93
...
...
@@ -25,81 +25,78 @@ SERVER = '10.128.120.38:2281'
if
__name__
==
'__main__'
:
while
True
:
try
:
for
unit
in
monitor
:
if
not
unit
.
get
(
'name'
):
try
:
cmd
=
'snmpwalk -c '
+
unit
[
'public'
]
+
' -v '
+
unit
[
'version'
]
+
' '
+
unit
[
'ip'
]
+
' '
+
CISCO_NAME_OID
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
p
.
wait
()
unit
[
'name'
]
=
p
.
stdout
.
read
().
split
(
': '
)[
1
].
strip
()
except
Exception
,
e
:
print
str
(
e
)
unit
[
'name'
]
=
'unknown'
cmd
=
'snmpget -c '
+
unit
[
'public'
]
+
' -v '
+
unit
[
'version'
]
+
' '
+
unit
[
'ip'
]
+
' '
if
unit
[
'type'
]
==
'cisco'
:
in_traffic_oid
=
CISCO_IN_TRAFFIC_OID
out_traffic_oid
=
CISCO_OUT_TRAFFIC_OID
in_count_oid
=
CISCO_IN_COUNT_OID
out_count_oid
=
CISCO_OUT_COUNT_OID
else
:
print
'The unit '
+
unit
[
'name'
]
+
'
\'
s type can not resolved!! ['
+
unit
[
'type'
]
+
']'
for
unit
in
monitor
:
if
not
unit
.
get
(
'name'
):
try
:
cmd
=
'snmpwalk -c '
+
unit
[
'public'
]
+
' -v '
+
unit
[
'version'
]
+
' '
+
unit
[
'ip'
]
+
' '
+
CISCO_NAME_OID
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
p
.
wait
()
unit
[
'name'
]
=
p
.
stdout
.
read
().
split
(
': '
)[
1
].
strip
()
except
Exception
,
e
:
print
str
(
e
)
unit
[
'name'
]
=
'unknown'
cmd
=
'snmpget -c '
+
unit
[
'public'
]
+
' -v '
+
unit
[
'version'
]
+
' '
+
unit
[
'ip'
]
+
' '
if
unit
[
'type'
]
==
'cisco'
:
in_traffic_oid
=
CISCO_IN_TRAFFIC_OID
out_traffic_oid
=
CISCO_OUT_TRAFFIC_OID
in_count_oid
=
CISCO_IN_COUNT_OID
out_count_oid
=
CISCO_OUT_COUNT_OID
else
:
print
'The unit '
+
unit
[
'name'
]
+
'
\'
s type can not resolved!! ['
+
unit
[
'type'
]
+
']'
continue
if
not
unit
.
get
(
'portname'
):
try
:
cmd
=
'snmpget -c '
+
unit
[
'public'
]
+
' -v '
+
unit
[
'version'
]
+
' '
+
unit
[
'ip'
]
+
' '
if
unit
[
'type'
]
==
'cisco'
:
for
p
in
unit
[
'port'
]:
cmd
+=
CISCO_PORT_NAME_OID
+
str
(
p
)
+
' '
else
:
raise
Exception
(
'unknown device type!'
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
p
.
wait
()
unit
[
'portname'
]
=
p
.
stdout
.
read
().
split
(
': '
)[
1
].
strip
()
except
Exception
,
e
:
print
str
(
e
)
unit
[
'portname'
]
=
unit
[
'port'
]
for
port
in
unit
[
'port'
]:
if
not
port
:
continue
if
not
unit
.
get
(
'portname'
):
cmd
+=
in_traffic_oid
+
str
(
port
)
+
' '
cmd
+=
out_traffic_oid
+
str
(
port
)
+
' '
cmd
+=
in_count_oid
+
str
(
port
)
+
' '
cmd
+=
out_count_oid
+
str
(
port
)
+
' '
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
p
.
wait
()
result
=
[
r
.
split
(
': '
)[
1
]
for
r
in
p
.
stdout
.
read
().
split
(
'
\n
'
)
if
r
]
if
not
unit
.
get
(
'last'
):
unit
[
'last'
]
=
[
int
(
r
)
for
r
in
result
]
else
:
now
=
[
int
(
r
)
for
r
in
result
]
diff
=
[]
i
=
0
while
i
<
len
(
now
):
d
=
now
[
i
]
-
unit
[
'last'
][
i
]
if
d
<
0
:
d
+=
4294967296
diff
.
append
(
d
)
i
+=
1
unit
[
'last'
]
=
now
print
unit
[
'last'
]
i
=
0
while
i
<
len
(
unit
[
'port'
]):
try
:
cmd
=
'snmpget -c '
+
unit
[
'public'
]
+
' -v '
+
unit
[
'version'
]
+
' '
+
unit
[
'ip'
]
+
' '
if
unit
[
'type'
]
==
'cisco'
:
for
p
in
unit
[
'port'
]:
cmd
+=
CISCO_PORT_NAME_OID
+
str
(
p
)
+
' '
else
:
raise
Exception
(
'unknown device type!'
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
p
.
wait
()
unit
[
'portname'
]
=
p
.
stdout
.
read
().
split
(
': '
)[
1
].
strip
()
#in
print
'http://'
+
SERVER
+
'/cat/r/systemMonitor?group='
+
unit
[
'group'
]
+
'&domain='
+
\
unit
[
'name'
]
+
'&key='
+
str
(
unit
[
'portname'
][
i
])
+
'-in&op=sum&sum='
+
str
(
diff
[::
4
][
i
])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
#out
print
'http://'
+
SERVER
+
'/cat/r/systemMonitor?group='
+
unit
[
'group'
]
+
'&domain='
+
\
unit
[
'name'
]
+
'&key='
+
str
(
unit
[
'portname'
][
i
])
+
'-in&op=sum&sum='
+
str
(
diff
[
1
::
4
][
i
])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
except
Exception
,
e
:
print
str
(
e
)
unit
[
'portname'
]
=
unit
[
'port'
]
for
port
in
unit
[
'port'
]:
if
not
port
:
continue
cmd
+=
in_traffic_oid
+
str
(
port
)
+
' '
cmd
+=
out_traffic_oid
+
str
(
port
)
+
' '
cmd
+=
in_count_oid
+
str
(
port
)
+
' '
cmd
+=
out_count_oid
+
str
(
port
)
+
' '
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
p
.
wait
()
result
=
[
r
.
split
(
': '
)[
1
]
for
r
in
p
.
stdout
.
read
().
split
(
'
\n
'
)
if
r
]
if
not
unit
.
get
(
'last'
):
unit
[
'last'
]
=
[
int
(
r
)
for
r
in
result
]
else
:
now
=
[
int
(
r
)
for
r
in
result
]
diff
=
[]
i
=
0
while
i
<
len
(
now
):
d
=
now
[
i
]
-
unit
[
'last'
][
i
]
if
d
<
0
:
d
+=
4294967296
diff
.
append
(
d
)
i
+=
1
unit
[
'last'
]
=
now
print
unit
[
'last'
]
i
=
0
while
i
<
len
(
unit
[
'port'
]):
try
:
#in
print
'http://'
+
SERVER
+
'/cat/r/systemMonitor?group='
+
unit
[
'group'
]
+
'&domain='
+
\
unit
[
'name'
]
+
'&key='
+
str
(
unit
[
'portname'
][
i
])
+
'-in&op=sum&sum='
+
str
(
diff
[::
4
][
i
])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
#out
print
'http://'
+
SERVER
+
'/cat/r/systemMonitor?group='
+
unit
[
'group'
]
+
'&domain='
+
\
unit
[
'name'
]
+
'&key='
+
str
(
unit
[
'portname'
][
i
])
+
'-in&op=sum&sum='
+
str
(
diff
[
1
::
4
][
i
])
#urllib2.urlopen('http://'+SERVER+'/cat/r/systemMonitor?group='+unit['group']+'&domain='+
# unit['name']+'&key='+unit['name']+'-'+group['key']+'/in-traffic'+'&op=sum&sum='+str(data),timeout=0)
except
Exception
,
e
:
print
str
(
e
)
i
+=
1
except
Exception
,
e
:
print
'exception!!! '
+
str
(
e
)
i
+=
1
time
.
sleep
(
SLEEP_TIME
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录