ids scaling framework added

parent febe049f
......@@ -42,10 +42,6 @@ function signalSciPass(cmd :string)
return;
}
event new_connection(c: connection )
{
print c;
}
event bro_init() &priority=4
{
print "BRO FTP Starting#######################";
......
#!/bin/sh
CPU_USAGE=`grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'`
echo "CPU USAGE: $CPU_USAGE"
python /home/ubuntu/scale.py $CPU_USAGE
#!/bin/python
from subprocess import Popen, PIPE
import os
import sys
from config import Config
def sendIDSScalingMsg(usage):
f = file('/etc/whitelist.cfg')
cfg = Config(f)
print cfg.CONTROLLER_IP
cmd = "curl http://%s:120/deidtect/cpu/%d" % (cfg.CONTROLLER_IP, \
int(float(usage)) )
print cmd
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out, err
if out == 'standalone':
print "Stay in the same state"
else:
print "Copy the node.cfg to etc and restart bro"
return 0
if __name__ == '__main__':
sendIDSScalingMsg(sys.argv[1]);
......@@ -2,7 +2,9 @@
import requests, json
import sys
from config import Config
BASE_PATH='http://%s:8080/v1.0/nettopo/whitelist'
from subprocess import Popen, PIPE
#curl -v http://155.98.38.112:120/deidtect/whitelist/local/0000001/10.0.0.1/10.0.0.3
BASE_PATH="curl -v http://%s:120/deidtect/whitelist/\'%s\'/\'%s\'/\'%s\'/\'%s\'"
class postIntf:
f = file('/etc/whitelist.cfg')
......@@ -11,41 +13,26 @@ class postIntf:
def __init__(self):
print self.cfg.CONTROLLER_IP
print self.cfg.SWITCH_DPID
self.url = BASE_PATH % self.cfg.CONTROLLER_IP
print self.cfg.SITE
def formParams(self, sendParams):
url = self.url
if(len(sendParams) > 0):
url = url+'/'+('/').join(sendParams)
return url
def whitelist(self, args):
cmd = BASE_PATH % (self.cfg.CONTROLLER_IP, self.cfg.SITE, self.cfg.SWITCH_DPID, args.argv[2], args.argv[1])
print cmd
self.sendPostRyu(cmd);
def setCmd(self, dic):
return self.sendPostRyu(self.url, dic)
def sendPostRyu(self, payload):
url = self.url
print url
r = requests.post(url, data=payload)
type = (r.headers['content-type']).split(';')[0]
print type + str(r.status_code)
if r.status_code == 200:
if type == 'application/json':
#print url
print r.json()
else:
print r.text
print 'Non JSON FORMAT'
else:
print '404 error :P'
return -1
def sendPostRyu(self, cmd):
print cmd
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
print out, err
return 0
sys.stderr.write("\x1b[2J\x1b[H") #clear screen
x = postIntf()
send_data = {'dpid': x.cfg.SWITCH_DPID, 'ipv4_dst' : sys.argv[1],
'ipv4_src' : sys.argv[2], 'tcp_src' : sys.argv[3], 'tcp_dst':sys.argv[4]}
print "CNAC REST API Testing..."
print send_data
x.sendPostRyu(send_data)
print "CNAC REST API Testing..."
x.whitelist(sys);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment