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

Commit

Permalink
METRON-1206 Make alerts UI conform to ops UI for install (merrimanr) c…
Browse files Browse the repository at this point in the history
…loses #773
  • Loading branch information
merrimanr authored and merrimanr committed Sep 27, 2017
1 parent b005563 commit eaae515
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 72 deletions.
90 changes: 53 additions & 37 deletions metron-interface/metron-alerts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,64 @@
- [Installing on an existing Cluster](#installing-on-an-existing-cluster)

## Caveats
* UI doesn't have an authentication module yet
* UI uses local storage to save all the data. A middleware needs to be designed and developed for persisting the data

## Prerequisites
* Elastic search should be up and running and should have some alerts populated by metron topologies
* The Metron REST application should be up and running and Elasticsearch should have some alerts populated by Metron topologies
* The Management UI should be installed (which includes [Express](https://expressjs.com/))
* The alerts can be populated using Quick Dev, Full Dev or any other setup
* UI is developed using angular4 and uses angular-cli
* node.JS >= 7.8.0

## Installation

### From Source

1. Package the application with Maven:

```
cd metron-interface/metron-alerts
mvn clean package
```

1. Untar the archive in the $METRON_HOME directory. The directory structure will look like:

```
bin
metron-alerts-ui
web
expressjs
alerts-server.js
alerts-ui
web assets (html, css, js, ...)
```

1. Copy the `$METRON_HOME/bin/metron-alerts-ui` script to `/etc/init.d/metron-alerts-ui`

1. [Express](https://expressjs.com/) is installed at `$METRON_HOME/web/expressjs/` as part of the Management UI installation process. The Management UI should be installed first on the same host as the Alerts UI.

## Configuration

The Alerts UI is configured in the `$METRON_HOME/config/alerts_ui.yml` file. Create this file and set the values to match your environment:

```
port: port the alerts UI will run on
rest:
host: REST application host
port: REST applciation port
```

## Usage

After configuration is complete, the Management UI can be managed as a service:

```
service metron-alerts-ui start
```

The application will be available at http://host:4201 assuming the port is set to `4201`. Logs can be found at `/var/log/metron/metron-alerts-ui.log`.

## Development Setup

1. Install all the dependent node_modules using the following command
Expand All @@ -26,9 +75,9 @@
```
./scripts/start-dev.sh
```
1. You can view the GUI @http://localhost:4200 . The default credentials for login are admin/password
1. You can view the GUI @http://localhost:4201. The default credentials for login are admin/password

**NOTE**: *In the development mode ui by default connects to ES at http://node1:9200 for fetching data. If you wish to change it you can change the ES url at metron/metron-interface/metron-alerts/proxy.conf.json*
**NOTE**: *In the development mode ui by default connects to REST at http://node1:8082 for fetching data. If you wish to change it you can change the REST url at metron/metron-interface/metron-alerts/proxy.conf.json*

## E2E Tests

Expand All @@ -49,36 +98,3 @@ An expressjs server is available for mocking the elastic search api.
1. E2E tests uses data from full-dev wherever applicable. The tests assume rest-api's are available @http://node1:8082

**NOTE**: *e2e tests covers all the general workflows and we will extend them as we need*

## Mpack Integration
Yet to come

## Installing on an existing Cluster
1. Build Metron:
```
mvn clean package -DskipTests
```

1. Copy `metron/metron-interface/metron-alerts/target/metron-alerts-METRON_VERSION-archive.tar.gz` to the desired host.

1. Untar the archive in the target directory. The directory structure will look like:
```
bin
start_alerts_ui.sh
web
alerts-ui
package.json
server.js
web assets (html, css, js, ...)
```

1. [Expressjs](https://github.com/expressjs/express) webserver script is included in the build that will serve the application. (The script has few rewrite rules and we can replace expressjs with any other webserver)

1. Then start the application with the script:
```
./bin/start_alerts_ui.sh
Usage: server.js -p [port] -r [restUrl]
Options:
-p Port to run metron alerts ui [required]
-r, --resturl Url where elastic search rest api is available [required]
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
Expand All @@ -15,10 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
port: 4201

METRON_VERSION=${project.version}
METRON_HOME=/usr/metron/$METRON_VERSION

cd $METRON_HOME/web/alerts-ui
npm install
node $METRON_HOME/web/alerts-ui/alerts-server.js $*
rest:
host: localhost
port: 8080
8 changes: 4 additions & 4 deletions metron-interface/metron-alerts/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
<directory>${project.basedir}/dist</directory>
<outputDirectory>/web/alerts-ui</outputDirectory>
<excludes>
<exclude>**/.npmignore</exclude>
</excludes>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>${project.basedir}/scripts</directory>
<outputDirectory>/web/alerts-ui</outputDirectory>
<outputDirectory>web/expressjs</outputDirectory>
<includes>
<include>package.json</include>
<include>alerts-server.js</include>
</includes>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<directory>${project.basedir}/scripts</directory>
<outputDirectory>/bin</outputDirectory>
<outputDirectory>bin</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>start_alerts_ui.sh</include>
<include>metron-alerts-ui</include>
</includes>
<fileMode>0755</fileMode>
<lineEnding>unix</lineEnding>
Expand Down
34 changes: 11 additions & 23 deletions metron-interface/metron-alerts/scripts/alerts-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,22 @@ var serveStatic = require('serve-static');
var favicon = require('serve-favicon');
var proxy = require('http-proxy-middleware');
var argv = require('optimist')
.demand(['p', 'r'])
.usage('Usage: alert-server.js -p [port] -r [restUrl]')
.describe('p', 'Port to run metron management ui')
.describe('r', 'Url where metron rest application is available')
.demand(['c'])
.alias('c', 'config_file')
.usage('Usage: alerts-server.js -c [config_file]')
.describe('c', 'Path to alerts_ui.yml')
.argv;
var YAML = require('yamljs');

var port = argv.p;
var metronUIAddress = '';
var ifaces = os.networkInterfaces();
var restUrl = argv.r || argv.resturl;
var conf = {
"rest": {
"target": restUrl,
"secure": false
}
};
var uiConfig = YAML.load(argv.c);

Object.keys(ifaces).forEach(function (dev) {
ifaces[dev].forEach(function (details) {
if (details.family === 'IPv4') {
metronUIAddress += '\n';
metronUIAddress += 'http://' + details.address + ':' + port;
metronUIAddress += 'http://' + details.address + ':' + uiConfig.port;
}
});
});
Expand All @@ -60,17 +54,11 @@ function setCustomCacheControl (res, path) {
res.setHeader("Expires", new Date(Date.now() + 2592000000).toUTCString());
}

var rewriteSearchProxy = proxy({
target: restUrl,
ws: true,
pathRewrite: {
'^/search' : ''
}
});

app.use(compression());

app.use('/api', proxy(conf.rest));
var restUrl = 'http://' + uiConfig.rest.host + ':' + uiConfig.rest.port;
app.use('/api/v1', proxy(restUrl));
app.use('/logout', proxy(restUrl));

app.use(favicon(path.join(__dirname, '../alerts-ui/favicon.ico')));

Expand All @@ -83,6 +71,6 @@ app.get('*', function(req, res){
res.sendFile(path.resolve('../alerts-ui/index.html'));
});

app.listen(port, function(){
app.listen(uiConfig.port, function(){
console.log("Metron alerts ui is listening on " + metronUIAddress);
});
159 changes: 159 additions & 0 deletions metron-interface/metron-alerts/scripts/metron-alerts-ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# metron alerts UI service
# chkconfig: - 20 80
# description: Alerts UI
# processname: metron-alerts-ui
#

# all LSB compliant distributions provide the following
# http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptfunc.html
if [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
fi

NAME=metron-alerts-ui
DESC="Metron Alerts UI"
METRON_VERSION=${project.version}
METRON_HOME=/usr/metron/$METRON_VERSION
METRON_LOG_DIR="/var/log/metron"
METRON_PID_DIR="/var/run/metron"
METRON_USER="metron"
METRON_GROUP="metron"
METRON_SYSCONFIG="/etc/default/metron"
if [ -f "$METRON_SYSCONFIG" ]; then
set -a
. "$METRON_SYSCONFIG"
fi

PIDFILE="$METRON_PID_DIR/$NAME.pid"

DAEMON="node $METRON_HOME/web/expressjs/alerts-server.js -c $METRON_HOME/config/alerts_ui.yml"

#
# start the rest application
#
start() {

# if pidfile exists, do not start another
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
printf "OK [$PID]\n"
return
fi

if [ ! -d "$METRON_LOG_DIR" ]; then
mkdir -p "$METRON_LOG_DIR" && chown "$METRON_USER":"$METRON_GROUP" "$METRON_LOG_DIR"
fi

if [ ! -d "$METRON_PID_DIR" ]; then
mkdir -p "$METRON_PID_DIR" && chown "$METRON_USER":"$METRON_GROUP" "$METRON_PID_DIR"
fi

# kick-off the daemon
CMD="$DAEMON >> $METRON_LOG_DIR/$NAME.log 2>&1 & echo \$!"
PID=`su -c "$CMD" $METRON_USER`

if [ -z $PID ]; then
printf "Fail\n"
else
echo $PID > $PIDFILE
printf "Ok [$PID]\n"
fi
}

#
# stop the rest application
#
stop() {
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
while sleep 1
echo -n "."
kill -0 $PID >/dev/null 2>&1
do
kill $PID
done
rm -f $PIDFILE
printf "%s\n" "Ok"
else
printf "%s\n" "Not running"
fi
}

#
# status check of the rest application
#
status() {
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
printf "%s\n" "Process dead but pidfile exists"
else
echo "Running"
fi
else
printf "%s\n" "Service not running"
fi
}

case "$1" in

##############################################################################
# start
#
start)
printf "%-50s \n" "Starting $NAME..."
start
;;

##############################################################################
# status
#
status)
printf "%-50s \n" "Checking $NAME..."
status
;;

##############################################################################
# stop
#
stop)
printf "%-50s \n" "Stopping $NAME..."
stop
;;

##############################################################################
# restart
#
restart)
$0 stop
$0 start
;;

##############################################################################
# reload
#
reload)
;;

*)
echo "Usage: $0 {status|start|stop|restart}"
exit 1
esac
2 changes: 1 addition & 1 deletion metron-interface/metron-alerts/scripts/start-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# limitations under the License.
#
SCRIPTS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$SCRIPTS_ROOT/../node_modules/@angular/cli/bin/ng serve --proxy-config proxy.conf.json $@
$SCRIPTS_ROOT/../node_modules/@angular/cli/bin/ng serve --proxy-config proxy.conf.json --port 4201 $@

0 comments on commit eaae515

Please sign in to comment.