Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e477dd8
x
Apr 7, 2015
95d2d5b
modified api to increase mana_monitor interface
Apr 7, 2015
1a2736b
Delete conf.py.bak
yangwanyuan Apr 7, 2015
df617c6
commplete send mail to receivers
Apr 8, 2015
f8b0199
Delete data
yangwanyuan Apr 8, 2015
19294f4
modify api interface to get instance
Apr 9, 2015
730a70f
Merge branch 'master' of https://github.com/yangwanyuan/mana
Apr 9, 2015
65612c8
modify the monitor send messeges
Apr 9, 2015
30d4aa8
modify the bin script
Apr 10, 2015
908ffdb
modify the api interface to get project and user
Apr 10, 2015
c62fc57
modify the debug machine on ywy host
Apr 10, 2015
f027105
modify add monitor time
Apr 10, 2015
689b69e
Delete mana.sh
yangwanyuan Apr 10, 2015
6c6bdc1
Delete mana-monitor
yangwanyuan Apr 10, 2015
8ea42a8
fix etc
Apr 10, 2015
e9d35e0
Merge branch 'master' of https://github.com/yangwanyuan/mana
Apr 10, 2015
e13be7c
modified +x
Apr 10, 2015
257d302
modify start stop script
Apr 10, 2015
478bfdd
add centos script
Apr 10, 2015
7e203b0
modify email chinese code
Apr 10, 2015
d3deaa7
modify code utf-8
Apr 10, 2015
2623f8b
fix project and user in chinese
Apr 13, 2015
383c3cc
fix
Apr 13, 2015
5a3f91f
add try
Apr 13, 2015
e052359
fix
Apr 13, 2015
f3820e1
fix encode latin-1 from mysql , abandon django_db
Apr 14, 2015
81d9c79
fix mana_monitor.py use utf-8
Apr 14, 2015
f60fe25
fix some bug
Apr 14, 2015
b9eb118
126 user and password
Apr 14, 2015
be09c4d
add ztgame_work@126.com
Apr 14, 2015
4c00915
add SMS and modify some code archite
Apr 15, 2015
d158a97
complete sms
Apr 16, 2015
c175d76
fix sms data and network unit
Apr 16, 2015
e609f3f
fix network sms bug
Apr 16, 2015
849429a
fix some bug
Apr 16, 2015
3b4716c
fix some too long code
Apr 16, 2015
fe03f9b
fix long code
Apr 16, 2015
22eecbb
fix Mbits
Apr 16, 2015
757af02
fix B to bit
Apr 16, 2015
d352cf9
set the program use muti-thread
Apr 20, 2015
7ce5590
Delete mana_email.py
yangwanyuan Apr 20, 2015
89b9400
Delete mana_global.py
yangwanyuan Apr 20, 2015
22c1050
Delete timer.py
yangwanyuan Apr 20, 2015
06bf1e8
delete alarm
Apr 29, 2015
535dd7d
add api url:/api/statics/<region>/<Meteric>/<UUID>/seconds/<time>/
Apr 29, 2015
bfe8904
fix tab to space, fix instance reboot limit network bug
May 5, 2015
49ed0df
revert limit network
May 5, 2015
3ba5efe
add api for client alarm
May 8, 2015
1086ae7
add build and etc file
May 8, 2015
a471e90
fix bug
May 19, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions api/alarm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from django.http import HttpResponse
from public import NOVA_DB,NEUTRON_DB,NOVA,NEUTRON,RTN_200,RTN_500,getConnIp
import ks_auth
import time
import utils
import base64,urllib,httplib,json,os
from beans import InstanceManager,KeyStoneManager,NetworkFlowManager,AlarmManager



def connUrl(url):
rtn=url.replace("http://","")
return rtn[:(rtn.index("/"))] if "/" in rtn else rtn

def ifaceID(uuid,portid,instid):
vir="instance-%s" % hex(instid)[2:].zfill(8)
return "%s-%s-%s" % (vir,uuid,"tap"+portid[:11])

def virs_list(req,region):
REGION=region
virs=InstanceManager().getallActiveInstances(NOVA_DB(region))
data = []
for vir in virs:
item= {}
item['instance_id']= vir.uuid
item['user'] = KeyStoneManager().getUserByUserID(vir.user_id)
item['project'] = KeyStoneManager().getProjectByProjectID(vir.project_id)
item['instance_name'] = vir.hostname
data.append(item)
body = json.dumps({"code":200,"message":"ok","data":data},ensure_ascii=False, indent=2)
return HttpResponse(body)

####same wit statics, need fix later
def alarm_statics(req,Meteric,UUID,time,region):
vir=InstanceManager().getInstanceByID(NOVA_DB(region),UUID)
if not vir:
return None
RTN=[]
if "network" in Meteric:
ports=NetworkFlowManager().getNetInfoByUUID(UUID,NEUTRON_DB(region))
print ports
for port in ports:
obj={}
obj["name"]=port["ip_address"]
ifaceId=ifaceID(UUID,port["id"],int(vir.id))
print "ifaceid:",ifaceId
obj["data"]=alarm_statistics(region,Meteric.replace("_","."),time,ifaceId)
RTN.append(obj)
elif "disk" in Meteric:
obj={}
obj["name"]=vir.hostname
obj["data"]=alarm_statistics(region,Meteric.replace("_","."),time,UUID)
RTN.append(obj)
elif "cpu_util"==Meteric:
obj={}
obj["name"]=vir.hostname
obj["data"]=alarm_statistics(region,Meteric,time,UUID)
RTN.append(obj)
return HttpResponse(json.dumps(RTN))


def alarm_statistics(region,Meteric,duration,RES_ID):
metricUrl=KeyStoneManager().getServiceUrl("metering",region)
token=ks_auth.getToken()
print "token:",token
headers1 = { "X-Auth-Token":token, "Content-type":"application/json" }
now=int(time.time())
duration_sec=int(duration)
period_start=utils.msecs2utc(now-8*3600-duration_sec)
data1={
"Meteric":Meteric,
"RES_ID":RES_ID,
"period":1,
"period_start":urllib.quote(period_start,''),
}
print "metricUrl:",metricUrl
print "->:",connUrl(metricUrl)
conn1 = httplib.HTTPConnection(connUrl(metricUrl))
m_url="/v2/meters/%(Meteric)s/statistics?q.field=resource_id&q.field=timestamp&q.op=eq&q.op=gt&q.type=&q.type=&q.value=%(RES_ID)s&q.value=%(period_start)s&period=%(period)s" % data1
print "m_url:",m_url
conn1.request("GET",m_url,None,headers1)
response1 = conn1.getresponse()
rtn = response1.read()
conn1.close()
if rtn:
rtn = json.loads(rtn)
print "rtn:",rtn
return rtn

def getAlarmTask(req, region, time):
time = int(time)
data=AlarmManager().getAlarmFromCycletime(region, time)
#for line in data:
# instance_id = line.get('instance').get('instance_id')
# vir = InstanceManager().getInstanceByID(NOVA_DB(region),instance_id)
# line.get('instance')['user'] = KeyStoneManager().getUserByUserID(vir.user_id)
# line.get('instance')['project'] = KeyStoneManager().getProjectByProjectID(vir.project_id)
# line.get('instance')['instance_name'] = vir.hostname
return HttpResponse(json.dumps({"code":200,"message":"ok","data":data},ensure_ascii=False, indent=2))
Loading