Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
73b38315
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73b38315
编写于
6月 18, 2016
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add default gateway option
上级
bd8e36cf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
20 deletion
+50
-20
conf/glances.conf
conf/glances.conf
+11
-15
glances/plugins/glances_ports.py
glances/plugins/glances_ports.py
+10
-5
glances/ports_list.py
glances/ports_list.py
+29
-0
未找到文件。
conf/glances.conf
浏览文件 @
73b38315
...
...
@@ -185,23 +185,19 @@ mem_critical=90
refresh
=
30
# Set the default timeout for a scan (can be overwrite in the scan list)
timeout
=
3
# If True, add the default gateway on top of the port list
port_default_gateway
=
True
# Define the scan list
# host (name or IP) is mandatory
# port is optional (set to 0 = ICMP check by default)
# description is optional (set to host:port)
port_1_host
=
www
.
google
.
com
port_1_port
=
443
port_1_description
=
Internet
Web
port_2_host
=
www
.
google
.
com
port_2_description
=
Internet
Ping
port_3_host
=
www
.
free
.
fr
port_3_description
=
Free
ISP
port_4_host
=
192
.
168
.
0
.
1
port_4_port
=
80
port_5_description
=
Home
Box
port_5_host
=
192
.
168
.
5
.
1
port_5_port
=
80
port_5_timeout
=
2
# port (TCP port number) is optional (if not set, use ICMP)
# description is optional (if not set, define to host:port)
port_1_host
=
192
.
168
.
0
.
1
port_1_port
=
80
port_1_description
=
Home
Box
port_2_host
=
www
.
free
.
fr
port_2_description
=
My
ISP
port_3_host
=
www
.
google
.
com
port_3_description
=
Internet
##############################################################################
# Client/server
...
...
glances/plugins/glances_ports.py
浏览文件 @
73b38315
...
...
@@ -141,12 +141,17 @@ class Plugin(GlancesPlugin):
fnull
=
open
(
os
.
devnull
,
'w'
)
counter
=
Counter
()
ret
=
subprocess
.
check_call
(
cmd
,
stdout
=
fnull
,
stderr
=
fnull
,
close_fds
=
True
)
if
ret
==
0
:
# Ping return RTT.
port
[
'status'
]
=
counter
.
get
()
/
2.0
try
:
ret
=
subprocess
.
check_call
(
cmd
,
stdout
=
fnull
,
stderr
=
fnull
,
close_fds
=
True
)
except
Exception
as
e
:
logger
.
debug
(
"{0}: Error while pinging host ({2})"
.
format
(
self
.
plugin_name
,
port
[
'host'
],
e
))
return
1
else
:
port
[
'status'
]
=
False
if
ret
==
0
:
# Ping return RTT.
port
[
'status'
]
=
counter
.
get
()
/
2.0
else
:
port
[
'status'
]
=
False
return
ret
...
...
glances/ports_list.py
浏览文件 @
73b38315
...
...
@@ -21,6 +21,18 @@
from
glances.compat
import
range
from
glances.logger
import
logger
from
glances.globals
import
BSD
# XXX *BSDs: Segmentation fault (core dumped)
# -- https://bitbucket.org/al45tair/netifaces/issues/15
if
not
BSD
:
try
:
import
netifaces
netifaces_tag
=
True
except
ImportError
:
netifaces_tag
=
False
else
:
netifaces_tag
=
False
class
GlancesPortsList
(
object
):
...
...
@@ -47,8 +59,25 @@ class GlancesPortsList(object):
logger
.
warning
(
"No [%s] section in the configuration file. Cannot load ports list."
%
self
.
_section
)
else
:
logger
.
debug
(
"Start reading the [%s] section in the configuration file"
%
self
.
_section
)
refresh
=
config
.
get_value
(
self
.
_section
,
'refresh'
,
default
=
self
.
_default_refresh
)
timeout
=
config
.
get_value
(
self
.
_section
,
'timeout'
,
default
=
self
.
_default_timeout
)
# Add default gateway on top of the ports_list lits
default_gateway
=
config
.
get_value
(
self
.
_section
,
'port_default_gateway'
,
default
=
'False'
)
if
default_gateway
.
lower
().
startswith
(
'true'
)
and
netifaces_tag
:
new_port
=
{}
new_port
[
'host'
]
=
netifaces
.
gateways
()[
'default'
][
netifaces
.
AF_INET
][
0
]
# ICMP
new_port
[
'port'
]
=
0
new_port
[
'description'
]
=
'DefaultGateway'
new_port
[
'refresh'
]
=
refresh
new_port
[
'timeout'
]
=
timeout
new_port
[
'status'
]
=
None
logger
.
debug
(
"Add default gateway %s to the static list"
%
(
new_port
[
'host'
]))
ports_list
.
append
(
new_port
)
# Read the scan list
for
i
in
range
(
1
,
256
):
new_port
=
{}
postfix
=
'port_%s_'
%
str
(
i
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录