#!/usr/bin/env python
#coding=utf-
8
#xiaorui.cc
from flask
import
Flask,url_for,request,render_template,redirect,abort,
escape
,session
from werkzeug
import
secure_filename
import
os
print __name__
app = Flask(__name__)
app.secret_key =
'hello'
@app.route(
'/'
)
def index():
p=os.popen(
'salt \'*\' grains.item psnum netnum'
).read()
p=os.popen(
'salt \* cmd.run \'netstat -an|wc -l\''
).read()
return
''
'
<!DOCTYPE html>
<!-- saved from url=(
0053
)http:
<html lang=
"en"
><head><meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<meta charset=
"utf-8"
>
<title>xiaorui.cc</title>
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta name=
"description"
content=
""
>
<meta name=
"author"
content=
""
>
<!-- Le styles -->
<link href=
"http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css"
rel=
"stylesheet"
>
<style type=
"text/css"
>
body {
padding-top: 20px;
padding-bottom: 40px;
}
.container-narrow {
margin:
0
auto;
max-width: 700px;
}
.container-narrow > hr {
margin: 30px
0
;
}
.jumbotron {
margin: 60px
0
;
text-align: center;
}
.jumbotron h1 {
font-size: 72px;
line-height:
1
;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.marketing {
margin: 60px
0
;
}
.marketing p + h4 {
margin-top: 28px;
}
</style>
<link href=
"http://cdnjs.bootcss.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css"
rel=
"stylesheet"
>
<!-- HTML5 shim,
for
IE6-
8
support of HTML5 elements -->
<!--[
if
lt IE
9
]>
<script src=
"//cdnjs.bootcss.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"
></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel=
"apple-touch-icon-precomposed"
sizes=
"144x144"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-144-precomposed.png"
>
<link rel=
"apple-touch-icon-precomposed"
sizes=
"114x114"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-114-precomposed.png"
>
<link rel=
"apple-touch-icon-precomposed"
sizes=
"72x72"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-72-precomposed.png"
>
<link rel=
"apple-touch-icon-precomposed"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-57-precomposed.png"
>
<link rel=
"shortcut icon"
href=
"http://www.bootcss.com/assets/ico/favicon.png"
>
<script>window[
"_GOOG_TRANS_EXT_VER"
] =
"1"
;</script></head>
<body>
<div
class
=
"container-narrow"
>
<div
class
=
"masthead"
>
<ul
class
=
"nav nav-pills pull-right"
>
<li
class
=
"active"
><a href=
"http://www.bootcss.com/examples/marketing-narrow.html#"
>Home</a></li>
<li><a href=
"http://www.bootcss.com/examples/marketing-narrow.html#"
>命令推送</a></li>
<li><a href=
"http://www.bootcss.com/examples/marketing-narrow.html#"
>图标监控</a></li>
</ul>
<h3
class
=
"muted"
>实时监控</h3>
</div>
<hr>
<div
class
=
"jumbotron"
>
<pre>%s</pre>
<a
class
=
"btn btn-large btn-success"
href=
"http://10.10.10.66:8888"
>刷新</a>
</div>
<hr>
<hr>
<div
class
=
"footer"
>
<h4>by xiaorui.cc</h4>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body></html>
''
'%p
@app.route(
'/charts.html'
)
def show_username():
p=[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
1
,
2
,
3
]
return
''
'
<!DOCTYPE html>
<!-- saved from url=(
0053
)http:
<html lang=
"en"
><head><meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<meta charset=
"utf-8"
>
<title>xiaorui.cc</title>
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta name=
"description"
content=
""
>
<meta name=
"author"
content=
""
>
<link href=
"http://67.xiaorui.cc/bootstrap.min.css"
rel=
"stylesheet"
>
<script type=
"text/javascript"
src=
"http://code.jquery.com/jquery-1.4.1.min.js"
></script>
<script type=
"text/javascript"
src=
"http://67.xiaorui.cc/highcharts.js"
></script>
<script type=
"text/javascript"
src=
"http://67.xiaorui.cc/exporting.js"
></script>
<style type=
"text/css"
>
body {
padding-top: 20px;
padding-bottom: 40px;
}
.container-narrow {
margin:
0
auto;
max-width: 700px;
}
.container-narrow > hr {
margin: 30px
0
;
}
.jumbotron {
margin: 60px
0
;
text-align: center;
}
.jumbotron h1 {
font-size: 72px;
line-height:
1
;
}
.jumbotron .btn {
font-size: 21px;
padding: 14px 24px;
}
.marketing {
margin: 60px
0
;
}
.marketing p + h4 {
margin-top: 28px;
}
</style>
<script type=
"text/javascript"
>
var
chart;
$(document).ready(
function
() {
chart =
new
Highcharts.Chart({
chart: {
renderTo:
'container'
,
defaultSeriesType:
'line'
,
marginRight:
130
,
marginBottom:
25
},
title: {
text:
'netstat 监控'
,
x: -
20
},
subtitle: {
text:
'让我们看看连接书哈'
,
x: -
20
},
xAxis: {
categories: [
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'10'
,
'11'
,
'12'
]
},
yAxis: {
title: {
text:
'连接数'
},
plotLines: [{
value:
0
,
width:
1
,
color:
'#808080'
}]
},
tooltip: {
formatter:
function
() {
return
'<b>'
+
this
.series.name +
'</b><br/>'
+
this
.x +
': '
+
this
.y +
'°C'
;
},
},
legend: {
layout:
'vertical'
,
align:
'right'
,
verticalAlign:
'top'
,
x: -
10
,
y:
100
,
borderWidth:
0
},
series: [{
name:
'66.ruifengyun.cc'
,
data: [-
0.2
,
0.8
,
5.7
,
11.3
,
17.0
,
22.0
,
24.8
,
24.1
,
20.1
,
14.1
,
8.6
,
2.5
]
}, {
name:
'67.ruifengyun.cc'
,
data: [-
0.9
,
0.6
,
3.5
,
8.4
,
13.5
,
17.0
,
18.6
,
17.9
,
14.3
,
9.0
,
3.9
,
1.0
]
}, {
name:
'ceshi'
,
data: %s
}]
});
});
</script>
<!-- Fav and touch icons -->
<link rel=
"apple-touch-icon-precomposed"
sizes=
"144x144"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-144-precomposed.png"
>
<link rel=
"apple-touch-icon-precomposed"
sizes=
"114x114"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-114-precomposed.png"
>
<link rel=
"apple-touch-icon-precomposed"
sizes=
"72x72"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-72-precomposed.png"
>
<link rel=
"apple-touch-icon-precomposed"
href=
"http://www.bootcss.com/assets/ico/apple-touch-icon-57-precomposed.png"
>
<link rel=
"shortcut icon"
href=
"http://www.bootcss.com/assets/ico/favicon.png"
>
<script>window[
"_GOOG_TRANS_EXT_VER"
] =
"1"
;</script></head>
<body>
<div
class
=
"container-narrow"
>
<div
class
=
"masthead"
>
<ul
class
=
"nav nav-pills pull-right"
>
<li><a href=
"http://66.xiaorui.cc:8888"
>Home</a></li>
<li><a href=
"http://66.xiaorui.cc:8888/pushcmd"
>命令推送</a></li>
<li
class
=
"active"
><a href=
"http://66.xiaorui.cc:8888/charts.html#"
>图表监控</a></li>
</ul>
<h3
class
=
"muted"
>图表监控</h3>
</div>
<hr>
<div
class
=
"jumbotron"
>
<div id=
"container"
style=
"width: 800px; height: 400px; margin: 0 auto"
></div>
<a
class
=
"btn btn-large btn-success"
href=
"http://10.10.10.66:8888"
>刷新</a>
</div>
<hr>
<hr>
<div
class
=
"footer"
>
<h4>by xiaorui.cc</h4>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body></html>
''
'%p
@app.route(
'/post/<int:post_id>'
)
def show_post(post_id):
return
'post_id:%d'
% post_id
@app.route(
'/index/'
)
def test_session():
if
'username'
in
session:
return
'logged in as %s'
%
escape
(session[
'username'
])
return
redirect(url_for(
'login'
))
@app.route(
'/login/'
,methods=[
'GET'
,
'POST'
])
def login():
if
request.method ==
'POST'
:
session[
'username'
] = request.form[
'username'
]
return
redirect(url_for(
'test_session'
))
else
:
return
''
'
<form action=
"/login/"
method=
"post"
>
<input type=text name=username>
<input type=submit value=login>
</form>
''
'
if
__name__ ==
"__main__"
:
app.run(host=
"10.10.10.66"
,port=
8888
,debug=True)