# SmartSense Server Configuration

## Introduction

This manual describes the configuration of the server-side components of the application *GBS SmartSense*. GBS SmartSense is an application developed to monitor GBDS Clusters, allowing the user to view real-time reports about the health and performance of the environment.

The configuration procedure should be done only after the installation step. For more information, consult the [GBS Apps Installation Manual](https://docs.griaule.com/gbs/en/web-components/gbsappssetup).

## Configuration

The configuration steps are:

1. Configure Tomcat;
2. Configure the Certificates;
3. Generate the encrypted password;
4. Install the Elastic Stack (ELK);
5. Finalize the configurations in the config.properties file.

All steps are described below. An example of the file `config.properties` can be found in the section [Configuration File Example](#exemplo-do-arquivo-de-configuracao).

{% hint style="danger" %}
All lines must be present in the configuration file. Commenting out or deleting lines may cause unexpected behavior. For additional information, contact the Griaule Support Team.
{% endhint %}

### Tomcat Configuration

Edit Tomcat's configuration file to configure the certificates and the port the application will use.

```sh
vi /var/lib/tomcats/smart-sense/conf/server.xml
```

To change the port, search for `Connector port=`. This is the port for backend operations.

### Certificates Configuration

To enable SSL authentication, search for `connector port=` in the file `/conf/server.xml`.

There are two entries. The commented one is the configuration for SSL. Remove the comment delimiters `<!--` and `-->`, then adjust the following parameters:

```properties
port="58194"
keystoreFile="/home/griaule/keystore"
keystorePass="password"
keyAlias="1"
clientAuth="true"
truststoreFile="/home/griaule/keystore"
truststorePass="password"
```

The parameter `port` must be the desired network port for the application.

Change the path of the `keystoreFile` and the `truststoreFile` to the appropriate values. Do the same for the `keystorePass` and the `truststorePass`.

The parameter `clientAuth="true"` will require server authentication to the client and client authentication to the server. This means the client will need to import the certificate into the browser to be able to access the application.

{% hint style="warning" %}
When **clientAuth** is set to *true*, the system administrator must provide the file **certificate.pfx** to end users.
{% endhint %}

### Database Password Encryption

In the file `config.properties`, the parameter `jdbc.password` is an encrypted password. To generate the encrypted password, follow these steps:

1. Go to the following directory:

   ```sh
   cd /var/lib/tomcats/smart-sense/webapps/gbs-smart-sense-server/WEB-INF/lib
   ```
2. Run the command:

   ```sh
   java -cp gbs-common-db-<version>.jar com.griaule.commons.util.EncryptUtil <desiredPassword>
   ```
3. The encrypted password will appear after the message: *"Encrypted password is:"*

{% hint style="info" %}
Save the encrypted password. It will be used in later configurations.
{% endhint %}

### Application Configuration File

To configure the file, open it with:

```sh
vi /var/lib/tomcats/smart-sense/conf/config.properties
```

The most important changes in this file are the parameters `jdbc.url`, `jdbc.username`, `jdbc.password` and `gbds.url`. Configure them according to your environment.

The complete configuration file is shown in the section [Configuration File Example](#exemplo-do-arquivo-de-configuracao).

{% hint style="info" %}
Remember to replace the encrypted password generated in the section [Database Password Encryption](#criptografia-da-senha-do-banco-de-dados) in this file.
{% endhint %}

#### SmartSense Settings

The last step is to configure the IP and port of the application that the end user will access. It must be the same IP and port configured in the section [Tomcat Configuration](#configuracao-do-tomcat).

```properties
smart-sense.ip=<ip>
smart-sense.port=<port>
smart-sense.protocol=<protocol>
```

{% hint style="warning" %}
Make sure the configuration parameters `smart-sense.ip`, `smart-sense.port` and `smart-sense.protocol` are correctly specified in the file `config.properties`. In many cases, the IP will be the same for several applications. However, each application will have a **different and unique port**.
{% endhint %}

#### Nodes (optional)

Optionally, instead of using the [SmartSense graphical interface](https://docs.griaule.com/gbs/en/applications/smartsense), you can configure the nodes to be monitored by inserting them directly into the `smartsense.hosts` table in the database. To do this, execute the following command in the database, replacing the *placeholders* with the correct values:

```sql
INSERT INTO smartsense.hosts (hostname,ip,port,active) VALUES ('<server_hostname>','<ip>','<smartsense agent port>',1);
COMMIT;
```

## Installing the Elastic Stack (ELK)

Go to the [ELK Installation Manual](https://docs.griaule.com/gbs/en/auxiliary-tools/elk) for detailed instructions on how to install and configure the Elastic Stack.

## Finishing the Configurations

After completing all configuration steps, return to the [GBS Apps Installation Manual - Configuration Section](https://docs.griaule.com/gbs/en/gbsappssetup#configuracoes).

## Configuration File Example

This section shows an example of the file `config.properties`.

```properties
# *********************************************************************
#
#         /$$$$$$  /$$      /$$  /$$$$$$  /$$$$$$$  /$$$$$$$$
#        /$$__  $$| $$$    /$$$ /$$__  $$| $$__  $$|__  $$__/
#       | $$  \__/| $$$$  /$$$$| $$  \ $$| $$  \ $$   | $$
#       |  $$$$$$ | $$ $$/$$ $$| $$$$$$$$| $$$$$$$/   | $$
#        \____  $$| $$  $$$| $$| $$__  $$| $$__  $$   | $$
#        /$$  \ $$| $$\  $ | $$| $$  | $$| $$  \ $$   | $$
#       |  $$$$$$/| $$ \/  | $$| $$  | $$| $$  | $$   | $$
#        \______/ |__/     |__/|__/  |__/|__/  |__/   |__/
#
#
#
#         /$$$$$$  /$$$$$$$$ /$$   /$$  /$$$$$$  /$$$$$$$$
#        /$$__  $$| $$_____/| $$$ | $$ /$$__  $$| $$_____/
#       | $$  \__/| $$      | $$$$| $$| $$  \__/| $$
#       |  $$$$$$ | $$$$$   | $$ $$ $$|  $$$$$$ | $$$$$
#        \____  $$| $$__/   | $$  $$$$ \____  $$| $$__/
#        /$$  \ $$| $$      | $$\  $$$ /$$  \ $$| $$
#       |  $$$$$$/| $$$$$$$$| $$ \  $$|  $$$$$$/| $$$$$$$$
#        \______/ |________/|__/  \__/ \______/ |________/
#
# *********************************************************************

# DATABASE (RDB)
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://<host-ip>:3306/smartsense?useSSL=false
jdbc.username=griaule
jdbc.password=CDrt8vbewA2YAubPNOLZkw==
jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.showSql=false

# GBDS CONNECTION
gbds.url=http://<host-ip>:8085
gbds.user=gbds.authenticate
gbds.key=Griaule.123
gbds.logLevel=INFO
gbds.timeout=300

# SMARTSENSE - GUI
smart-sense.ip=<host-ip>
smart-sense.port=8126
smart-sense.protocol=http
locale=en_us

# SMARTSENSE - CONFIGURATION

fingerprint.useSDK=true
useLatentExtrator.fingerprint=true
useLatentExtrator.palmprint=false
image.convert.useJnbis=true
server.standalone.port=8085

gbds.smartSenseUser=smart_sense_server
sync.logLevel=INFO
same.user.simultaneous.login=false
notification.delay=5

poolingLoadBalancing.time=60
poolingLoadBalancing.active=true
poolingLoadBalancing.last=

# SMARTSENSE - ELK CONFIGURATION

linkEnroll=
linkIdentify=
linkIdentifyLatent=
linkUpdate=
linkVerify=

consumerQueue.active=true
```
