From 9b136441bf264611b2b797e72a5a63ba0245775f Mon Sep 17 00:00:00 2001 From: Florian N Date: Mon, 17 Feb 2014 10:27:11 -0500 Subject: [PATCH] v 1.3 --- main/views.py | 18 ++++++++++++------ pydash/settings.py | 2 +- templates/main.html | 1 - usage/views.py | 6 +++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/main/views.py b/main/views.py index 5878bd8..b59f2d6 100755 --- a/main/views.py +++ b/main/views.py @@ -255,7 +255,7 @@ def get_cpu_usage(): """ Get the CPU usage and running processes """ - try: + try: pipe = os.popen("ps aux --sort -%cpu,-rss") data = pipe.read().strip().split('\n') pipe.close() @@ -295,19 +295,25 @@ def get_load(): return data def get_netstat(): + """ + Get ports and applications + """ try: - pipe = os.popen("netstat -tlnp|grep LISTEN|awk '{print $4, $5, $7}'") + pipe = os.popen("netstat -tlnp |" + "grep 'LISTEN' |" + "awk '{print $4, $5, $7}'") data = pipe.read().strip().split('\n') pipe.close() + data = [i.split(None, 3) for i in data] + except Exception, err: data = str(err) + if data[0] == []: - data = [['No', 'data', 'available']] - #for i in data: - # temp = i.split() - # print temp[3] + temp[4] + data = [['No', 'data', 'available']] + return data + + @login_required(login_url='/login/') def getall(request): diff --git a/pydash/settings.py b/pydash/settings.py index 4e56a0a..0238db5 100644 --- a/pydash/settings.py +++ b/pydash/settings.py @@ -36,7 +36,7 @@ TIME_JS_REFRESH = 30000 TIME_JS_REFRESH_LONG = 120000 TIME_JS_REFRESH_NET = 2000 -VERSION = 1.2 +VERSION = 1.3 ALLOWED_HOSTS = ['*'] diff --git a/templates/main.html b/templates/main.html index f9bd6cd..edbbdc0 100644 --- a/templates/main.html +++ b/templates/main.html @@ -415,7 +415,6 @@ dashboard.getNetstat = function() { tr+=''+item[0]+''+item[1]+''+item[2]+''; }) tr+=''; - console.log(tr); $("#get-netstat").html( tr ); }); } diff --git a/usage/views.py b/usage/views.py index 0a8a366..79b23d5 100755 --- a/usage/views.py +++ b/usage/views.py @@ -38,7 +38,11 @@ def getnetstat(request): """ Return netstat output """ - net_stat = get_netstat() + try: + net_stat = get_netstat() + except Exception: + net_stat = None + data = json.dumps(net_stat) response = HttpResponse() response['Content-Type'] = "text/javascript"