Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
rework veris stats call as a server-side call, consistent the spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbryner committed Jan 24, 2015
1 parent 69ee2e0 commit 1ee910b
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 99 deletions.
50 changes: 30 additions & 20 deletions meteor/app/client/incidentsveris.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Jeff Bryner jbryner@mozilla.com
*/

if (Meteor.isClient) {
var verisstatsResult = new Object;

Template.incidentsveris.rendered = function () {
var ndx = crossfilter();
Expand Down Expand Up @@ -48,26 +49,35 @@ if (Meteor.isClient) {
.range([0, maxRadius]);

container.style.cursor='wait'
d3.json(getSetting('rootAPI') + '/veris' , function(error, jsondata) {
//console.log(jsondata)
//jsondata.forEach(function(d){
// console.log(d);
//});
ndx.add(jsondata);
container.style.cursor='auto';
if ( ndx.size() >0 ){
var all = ndx.groupAll();
var tagsDim = ndx.dimension(function(d) {return d.tags;});
var phaseDim = ndx.dimension(function(d) {return d.phase});
}
r.domain([0, d3.max(tagsDim.group().all(), function(d) { return d.value; })]);
tagsDim.group().all().forEach(function(d){
d.r = r(d.value);
d.cr = Math.max(minRadius, d.r);
nodes.push(d);
});
start();
});
Meteor.apply('verisstats',
[],
onResultReceived = function(err,result){
//debugLog(err,result);
if (typeof err == 'undefined') {
verisstatsResult.status='completed';
verisstatsResult.result = result;
verisstatsResult.content=result.content;
verisstatsResult.data=result.data;
ndx.add(result.data);
container.style.cursor='auto';
if ( ndx.size() >0 ){
var all = ndx.groupAll();
var tagsDim = ndx.dimension(function(d) {return d.tags;});
var phaseDim = ndx.dimension(function(d) {return d.phase});
}
r.domain([0, d3.max(tagsDim.group().all(), function(d) { return d.value; })]);
tagsDim.group().all().forEach(function(d){
d.r = r(d.value);
d.cr = Math.max(minRadius, d.r);
nodes.push(d);
});
start();
} else {
//debugLog(err,result);
verisstatsResult.status='error';
verisstatsResult.error=err;
}
});

container.style.cursor='auto';

Expand Down
178 changes: 99 additions & 79 deletions meteor/app/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,106 @@ Copyright (c) 2014 Mozilla Corporation
Contributors:
Jeff Bryner jbryner@mozilla.com
*/
if (Meteor.isServer) {

//public functions
Meteor.methods({
'saySomething': saySomething,
'loadKibanaDashboards': loadKibanaDashboards,
'blockip': blockIP,
'ipwhois': ipwhois,
'ipcif': ipcif,
'ipdshield': ipdshield
});

function saySomething() {
console.log("something is said");
}

function loadKibanaDashboards() {
console.log('Loading Kibana dashboards... ' + mozdef.rootAPI + '/kibanadashboards');
var dashboardsRequest = HTTP.get(mozdef.rootAPI + '/kibanadashboards');
if (dashboardsRequest.statusCode==200 && dashboardsRequest.data) {
// set the current dashboards in the mongo collection
console.log("Updating kibana dashboards...");
kibanadashboards.remove({});
dashboardsRequest.data.forEach(function(dashboard, index, arr) {
kibanadashboards.insert(dashboard);
//public server-side functions
Meteor.methods({
'saySomething': saySomething,
'loadKibanaDashboards': loadKibanaDashboards,
'blockip': blockIP,
'ipwhois': ipwhois,
'ipcif': ipcif,
'ipdshield': ipdshield,
'verisstats': verisstats
});
//console.log(dashboardsRequest.data);
} else {
console.log("Could not retrieve kibana dashboards... check settings");
console.log(mozdef.rootAPI + '/kibanadashboards');
console.log("returned a " + dashboardsRequest.statusCode);
console.log(dashboardsRequest.data);
}
}

function blockIP(actionobj) {
var blockIPRequest = HTTP.post(mozdef.rootAPI + '/blockip', {data: actionobj});
if (blockIPRequest.statusCode==200) {
console.log(actionobj.address+"/"+actionobj.cidr+" blocked for "+actionobj.duration);
} else {
console.log("Could not block "+actionobj.address+"/"+actionobj.cidr+" for "+actionobj.duration);
}
}

function ipwhois(ipaddress){
//console.log('Posting ' + ipaddress + 'to ' + mozdef.rootAPI + '/ipwhois/');
var ipwhoisResponse = HTTP.post(mozdef.rootAPI + '/ipwhois/',{data: {'ipaddress':ipaddress}});

if ( typeof ipwhoisResponse == 'undefined') {
console.log("no response from server")
return "";
} else {
//console.log(ipwhoisResponse);
return ipwhoisResponse;

function saySomething() {
//debug function
console.log("something is said");
}
}

function ipdshield(ipaddress){
//console.log('Posting ' + ipaddress + 'to ' + mozdef.rootAPI + '/ipwhois/');
var ipdshieldResponse = HTTP.post(mozdef.rootAPI + '/ipdshieldquery/',{data: {'ipaddress':ipaddress}});

if ( typeof ipdshieldResponse == 'undefined') {
console.log("no response from server")
return "";
} else {
//console.log(ipdshieldResponse);
return ipdshieldResponse;
}

}

function ipcif(ipaddress){
//console.log('Posting ' + ipaddress + 'to ' + mozdef.rootAPI + '/ipcifquery/');
var ipcifResponse = HTTP.post(mozdef.rootAPI + '/ipcifquery/',{data: {'ipaddress':ipaddress}});

if ( typeof ipcifResponse == 'undefined') {
console.log("no response from server")
return "";
} else {
//console.log(ipdshieldResponse);
return ipcifResponse;

function loadKibanaDashboards() {
console.log('Loading Kibana dashboards... ' + mozdef.rootAPI + '/kibanadashboards');
var dashboardsRequest = HTTP.get(mozdef.rootAPI + '/kibanadashboards');

if (dashboardsRequest.statusCode==200 && dashboardsRequest.data) {
// set the current dashboards in the mongo collection
console.log("Updating kibana dashboards...");
kibanadashboards.remove({});
dashboardsRequest.data.forEach(function(dashboard, index, arr) {
kibanadashboards.insert(dashboard);
});
//console.log(dashboardsRequest.data);
} else {
console.log("Could not retrieve kibana dashboards... check settings");
console.log(mozdef.rootAPI + '/kibanadashboards');
console.log("returned a " + dashboardsRequest.statusCode);
console.log(dashboardsRequest.data);
}
}

function blockIP(actionobj) {
var blockIPRequest = HTTP.post(mozdef.rootAPI + '/blockip', {data: actionobj});

if (blockIPRequest.statusCode==200) {
console.log(actionobj.address+"/"+actionobj.cidr+" blocked for "+actionobj.duration);
} else {
console.log("Could not block "+actionobj.address+"/"+actionobj.cidr+" for "+actionobj.duration);
}
}

function ipwhois(ipaddress){
//console.log('Posting ' + ipaddress + 'to ' + mozdef.rootAPI + '/ipwhois/');
var ipwhoisResponse = HTTP.post(mozdef.rootAPI + '/ipwhois/',{data: {'ipaddress':ipaddress}});

if ( typeof ipwhoisResponse == 'undefined') {
console.log("ipwhois: no response from server")
return "";
} else {
console.log(ipwhoisResponse);
return ipwhoisResponse;
}
}

function ipdshield(ipaddress){
//console.log('Posting ' + ipaddress + 'to ' + mozdef.rootAPI + '/ipwhois/');
var ipdshieldResponse = HTTP.post(mozdef.rootAPI + '/ipdshieldquery/',{data: {'ipaddress':ipaddress}});

if ( typeof ipdshieldResponse == 'undefined') {
console.log("ipdshield: no response from server")
return "";
} else {
//console.log(ipdshieldResponse);
return ipdshieldResponse;
}

}

function ipcif(ipaddress){
//console.log('Posting ' + ipaddress + 'to ' + mozdef.rootAPI + '/ipcifquery/');
var ipcifResponse = HTTP.post(mozdef.rootAPI + '/ipcifquery/',{data: {'ipaddress':ipaddress}});

if ( typeof ipcifResponse == 'undefined') {
console.log("ipcif: no response from server")
return "";
} else {
//console.log(ipdshieldResponse);
return ipcifResponse;
}

}

function verisstats(){
//console.log('Calling ' + mozdef.rootAPI + '/veris/');
var verisstatsResponse = HTTP.get(mozdef.rootAPI + '/veris/');

if ( typeof verisstatsResponse == 'undefined') {
console.log("verisstats: no response from server")
return "";
} else {
//console.log(verisstatsResponse);
return verisstatsResponse;
}

}

}
};

0 comments on commit 1ee910b

Please sign in to comment.