Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Dependency on fieldMap.js with mappings API Call [merge with WWW and PB] #75

Merged
merged 5 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ build
*.log
esvm
.htpasswd
src/kibana/netmon_libs/fieldMap.js
21 changes: 5 additions & 16 deletions scripts/buildRpm.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
#!/bin/bash
set -e
set -x

if [[ $# -gt 3 || $# -lt 2 ]] ; then
echo 'Usage: sh buildRpm <KIBANA-OFFICIAL-BRANCH> <PROTOBUFFER-BRANCH> <PROTOBUFFER-GIT-USER<optional>>'
if [ $# -ne 1 ] ; then
echo 'Usage: sh buildRpm <KIBANA-OFFICIAL-BRANCH>'
exit 0
fi

set -e
set -x

PACKAGE=kibana
GIT_VERSION=`git rev-list --branches HEAD | wc -l`
GIT_BRANCH="$1"
VERSION="$GIT_BRANCH.$GIT_VERSION"
PWD=`pwd`


PROTO_BRANCH=$2
if [ $# -eq 3 ]; then
PROTO_USER=$3
else
PROTO_USER="Logrhythm"
fi


rm -rf ~/rpmbuild
rpmdev-setuptree
cp packaging/$PACKAGE.spec ~/rpmbuild/SPECS
rm -f $PACKAGE-$VERSION.tar.gz
tar cvzf ~/rpmbuild/SOURCES/$PACKAGE-$VERSION.tar.gz -C $PWD .
rpmbuild -v -bb --define="version ${VERSION}" --define="kibana_version ${GIT_BRANCH}" --define="protobuf_user $PROTO_USER" --define="proto_branch $PROTO_BRANCH" --target=x86_64 ~/rpmbuild/SPECS/$PACKAGE.spec
rpmbuild -v -bb --define="version ${VERSION}" --define="kibana_version ${GIT_BRANCH}" --target=x86_64 ~/rpmbuild/SPECS/$PACKAGE.spec
32 changes: 2 additions & 30 deletions scripts/kibanaBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,10 @@ set -e
set -x

# This script will build kibana and update the .tar.gz file in the target directory
if [[ $# -gt 2 || $# -lt 1 ]] ; then
echo 'Usage: sh kibanaBuild.sh <PROTOBUFFER-BRANCH> <PROTOBUFFER-GIT-USER<optional>>'
exit 0
fi


LOCATION=$PWD

BRANCH="$1"

if [ $# -eq 2 ]; then
USER=$2
else
USER="Logrhythm"
fi
echo "USER IS $USER";

echo "Building: $BRANCH for USER: $USER"

git clone [email protected]:$USER/Protobuffers.git -b $BRANCH

kibanaBuildDir=$PWD

cd Protobuffers
sh scripts/buildUIFieldMap.sh
cp js/fieldMap.js $kibanaBuildDir/src/kibana/netmon_libs/
cd $kibanaBuildDir
rm -rf Protobuffers

# The steps below are commented out but kept to show
# what is needed to to when re-building
# bower_components, node_modules etc.
# what is needed to to when re-building
# bower_components, node_modules etc.
# -----------------------------------------------------
#sed -i s/\'shasum/\'sha1sum/g tasks/create_shasums.js
#sed -i s/0.10.x/0.10.42/g .node-version
Expand Down
88 changes: 48 additions & 40 deletions src/kibana/netmon_libs/custom_modules/save_rule/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,56 @@ define(function (require) {
$scope.modalState.state = 'unconfirmed';
$scope.modalState.loading = true;
form.$setPristine();

kbnIndex.indices(from, to, '[network_]YYYY_MM_DD', 'day')
.then(
function(indices) {
$scope.ejs.Request()
.indices(indices)
.facet(
$scope.ejs.QueryFacet('rules')
.query(
$scope.ejs.FilteredQuery(
$scope.ejs.QueryStringQuery($scope.elasticSearchFields.convertQuery(rule.query)),
$scope.ejs.RangeFilter('TimeUpdated')
.from(from)
.to(to)
$scope.elasticSearchFields.fetchMapping().then( function(statusCode) {
if (statusCode === 200) {
rule.query = $scope.elasticSearchFields.convertQuery(rule.query);
kbnIndex.indices(from, to, '[network_]YYYY_MM_DD', 'day')
.then(
function(indices) {
$scope.ejs.Request()
.indices(indices)
.facet(
$scope.ejs.QueryFacet('rules')
.query(
$scope.ejs.FilteredQuery(
$scope.ejs.QueryStringQuery(rule.query),
$scope.ejs.RangeFilter('TimeUpdated')
.from(from)
.to(to)
)
)
)
)
)
.doSearch()
.then(
function(result) {
$scope.modalState.loading = false;
.doSearch()
.then(
function(result) {
$scope.modalState.loading = false;

if (result && result.facets && result.facets.rules && result.facets.rules.count !== undefined) {
$scope.modalState.numMatches = result.facets.rules.count;
} else {
$scope.modalState.state = 'error';
$scope.modalState.error = 'There was a problem executing your search.';
}
},
function() {
$scope.modalState.loading = false;
$scope.modalState.state = 'error';
$scope.modalState.error = 'There was a problem executing your search.';
}
);
},
function() {
$scope.modalState.loading = false;
$scope.modalState.state = 'error';
$scope.modalState.error = 'There was a problem executing your search.';
}
);
if (result && result.facets && result.facets.rules && result.facets.rules.count !== undefined) {
$scope.modalState.numMatches = result.facets.rules.count;
} else {
$scope.modalState.state = 'error';
$scope.modalState.error = 'There was a problem executing your search.';
}
},
function() {
$scope.modalState.loading = false;
$scope.modalState.state = 'error';
$scope.modalState.error = 'There was a problem executing your search.';
}
);
},
function() {
$scope.modalState.loading = false;
$scope.modalState.state = 'error';
$scope.modalState.error = 'There was a problem executing your search.';
}
);
} else {
$scope.modalState.loading = false;
$scope.modalState.state = 'error';
$scope.modalState.error = "Unable to retrieve metadata mappings.";
}
});
};

$scope.saveRule = function(rule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,31 @@
*/
define(function (require) {
var _ = require('lodash');
require('fieldmap');
var app = require('modules').get('app/dashboard');
app.factory('elasticSearchFields', function() {
var DEFAULT_TYPE = 'networkData',
NETWORK_DATA_FIELDS = getFieldMap(),
FIELD_MAP = {
// default is the "network_*" indices
'networkData': NETWORK_DATA_FIELDS,
// alarms is the "events_*" indices
'alarms': _.extend({
'rulename': 'RuleName',
'ruleseverity': 'RuleSeverity'
}, NETWORK_DATA_FIELDS),
// rules is the "networkrules" index
'alarmRules': {
'enabled': 'enabled',
'severity': 'severity',
'query': 'query',
'createddate': 'createdDate',
'lastmodifieddate': 'lastModifiedDate'
}
};
app.factory('elasticSearchFields', function($http) {
var fieldMap = {};
var FIELDMAP_ROUTE = "/api/metadata/fieldmap";

var ElasticSearchFields = function() {
this.type = DEFAULT_TYPE;
};

ElasticSearchFields.prototype.getType = function() {
return this.type;
};

ElasticSearchFields.prototype.setType = function(type) {
this.type = !!FIELD_MAP[type] ? type : DEFAULT_TYPE;
return this;
};
ElasticSearchFields.prototype.fetchMapping = function() {
return $http.get(FIELDMAP_ROUTE).then(
function success(response) {
fieldMap = response.data;
return response.status;
}, function error(response) {
return response.status;
});
}

ElasticSearchFields.prototype.getMap = function() {
var type = this.getType();
return !!FIELD_MAP[type] ? FIELD_MAP[type] : FIELD_MAP[DEFAULT_TYPE];
};

ElasticSearchFields.prototype.convertQuery = function(query) {
query = typeof(query) !== 'string' ? query.toString() : query;

var type = this.getType(),
fieldMap = this.getMap(type),
regexField = /([\w\d]+):/ig,
regexExists = /(_exists_:)\s*([\w\d]+)(?=\s|$)/ig,
regexMAC = /(DestMAC:|SrcMAC:)\s*\"([0-9a-f]{2}[:-]){5}([0-9a-f]{2}\")/i;
var regexField = /([\w\d]+):/ig;
var regexExists = /(_exists_:)\s*([\w\d]+)(?=\s|$)/ig;
var regexMAC = /(DestMAC:|SrcMAC:)\s*\"([0-9a-f]{2}[:-]){5}([0-9a-f]{2}\")/i;

function convertField(field) {
return fieldMap[field.toLowerCase()];
Expand All @@ -63,7 +39,7 @@ define(function (require) {
return (field === undefined) ? str : field + ':';

});

query = query.replace(regexExists, function(str, p1, p2) {
var field = convertField(p2);
return field === undefined ? str : p1 + field;
Expand All @@ -73,7 +49,7 @@ define(function (require) {
var field = str.replace(p1, '').toLowerCase().trim();
return p1 + field;
});

return query;
};

Expand Down