Lightmeter ControlCenter (Alpha)

Introduction to the

Welcome to the Lightmeter Control Center, an open source MailOps monitoring application.

Supported mail transfer agents

Postfix MTA is currently supported. More MTA support is planned for the future.

Quick start

  1. Install the Lightmeter control center as you like.

    1. Download the Docker image
    2. Download the source from Gitlab
    3. Download from the Gitlab Software Package Registry
  2. When using binaries, you can use the./ lightmeter-workspace ~/ lightmeter_workshop-watch_dir /var/log command to start the application monitoring /var/log in real time (including old logs found there), And store the action files in lightmeter_workspace in the user’s home directory.

  3. If you are using docker images, see the usage, Docker images section in readme. md

  4. Open http://localhost:8080/ to view the network interface

  5. Secure network access to the Web UI when necessary (see known issues)

  6. If necessary, change the date range to see the chart for the log period you just imported

The installation

Install using Docker

Each version generates Docker images and is published in Gitlab’s Lightmeter registry and Docker Hub.

You can use the Latest tag if you want. See Docker image for usage.

In addition, we publish two Docker images every night (UTC time) labeled snack-master and Snack-Develop. Snack-develop consists of builds from the Develop branch that contain the latest changes and are very unstable and suitable for use in production. Cng-master is more stable and contains changes that will be included in the next release, but is also not recommended for production use.

Building from source

The following dependencies are required during development.

  • Bash
  • Any recent (such as 2020) version of Git.
  • Go compiler version 1.15 or later.
  • GCC9.3 or later.
  • Libc development file. Glibc and MUSL have been successfully tested.
  • GNU Make or compatible.
  • Ragel6. X version. We have successfully tested version 6.10. Ragel 7 is not currently supported.
  • Vue CLI – For web-based user interface.

On Alpine Linux 3.12, for example, they can be installed.

$apk add git make GCC go libc-dev ragel NPM $NPM install -g@vue /[email protected] @vue/[email protected]Copy the code

To create a release, dynamically link to the local liBC and execute.

make release

Copy the code

To create a statically linked version (only supported if your LIBC is statically linked), do this.

make static_release
Copy the code

This will download all the dependencies and create a file called lightMeter, which you can simply copy to your Postfix server and use as described in the Usage section.

If you’re going to contribute code (thank you! :-)), please check out the development.

upgrade

Limited automatic data migration is supported during the upgrade. Since the data format is not yet stable, we cannot guarantee 100% data security.

We recommend that you create a backup of your workspace directory before making a major upgrade. Backups can be made by stopping The ControlCenter, copying the workspace directory elsewhere (or creating an archive, etc.), upgrading the ControlCenter, and finally starting it again.

This is easily achieved using manual upgrades based on replacement binaries. For docker-based installations, you should configure a workspace directory outside of the Lightmeter Docker container. See “Usage” for details on how to specify which workspace directory Lightmeter should use.

We already plan to support instant backup in future releases, and the process will become easier, more secure, and more flexible.

The installation

Install from binary

We provide pre-built, architecture-specific binaries on Gitlab that should run on any modern Linux distribution. Simply download them, set them up as executables, and execute as described in the usage.

Your operating system should provide certificate authority certificates by default (the CA-certificates package in many distributions), but if you want to keep your own CA certificates, you will need to set the environment variable SSL_CERT_DIR.

On Alpine Linux, for example, you can use the binaries before executing them.

export
Copy the code

But this is almost always unnecessary because the control center can find them correctly.

For more information on how to find CA certificates, check out the corresponding Go source code.

Logs managed by Rsync

If the log directory passed by -watch_dir is not in the same file system that Postfix writes to, but is copied by rsync, you must pass the command line argument -logs_use_rsync, otherwise the new log line received after the first rsync execution will not be noticed.

When using Rsync, be careful not to use any in-place synchronization options, such as –append, because the control center expects the default Rsync behavior to be used when updating files, including first creating a temporary file at the destination and renaming it to the final file when it’s fully migrated.

Docker mirror

The easiest way to use the latest version of Docker is with commands.

$ docker run -p 8080:8080 -v "<path_to_workspace>:/workspace:rw" -v "/var/log/:/logs:ro" \
  registry.gitlab.com/lightmeter/controlcenter -workspace /workspace -watch_dir /logs

Copy the code

Where is a directory where the control center will save data that must persist during a reboot.

Then at http://localhost:8080, open your browser and access the Web-based user interface.

You can find all published images on the registry page.

NixOS software packages and modules

You can find the published PKG, modules, test platform, and “how to build and install it” instructions on Github.

API

Lightmeter provides a simple REST API designed for user interfaces. It is used by the Web UI.

Swagger based API documentation and lab pages are automatically generated during development builds. Through http://lightmeter-address:8080/api, http://localhost:8080/api, for example, to access them.

Headless mode (no Web user interface

Headless mode allows ControlCenter to run only in the background, with no Web UI. Currently, this is for development purposes. Headless mode can be very useful for using only the API parts of an application.

Running headless mode requires building the ControlCenter for this purpose.

make devheadless # Build ControlCenter
./lightmeter -stdin -verbose --listen :8003 # Example command to start ControlCenter quickly (same as running a normal build)
Copy the code

certification

  • Currently, single-user, password-based authentication is supported by default.AllowMultipleUsersThrough self-registered multi-user accounts, changes can be made without approvalauth/auth.goAnd recompile to enable.

Password reset

You can reset the administrator password using the command line.

./lightmeter -email_reset '<registration-email>' -password '<new-password>'

Delete user

Method of use

See Usage for more information.

  • Run lightmeter -help to display a list of all available commands

  • After compiling (or downloading) the Lightmeter control center, you should run the binary Lightmeter file, read the logs, and start the local Web server so that you can view the Lightmeter Control center through a Web UI in a browser on port 8080 on the same network, for example: http://localhost:8080/. You can use -listen “:9999”, for example to use different ports or network interfaces, in which case all the interfaces are on port 9999.

  • An authentication session for a Web user interface lasts for one week by default.

  • To serve logs through stdin instead of logfile location, use the command line argument -stdin, such as lightmeter -stdin < [log-data].

  • You can also receive logs listened on Unix sockets or TCP ports, such as -socket “Unix; The/path/to/socket. The sock or TCP – socket “; Localhost: 9999.” It is important to note that this socket communication is unauthenticated and encrypted, so it can only be used in secure environments

  • To provide a single log file, use the command line argument – stdin, such as the tail -f/path – to – the file. The log | lightmeter – stdin.

  • Mail server data is stored in different workspaces so that different servers can be monitored individually. The default workspace directory is /var/lib/lightmeter_workspace. You can use -workspace /path/to/workspace.

  • Since the Postfix log does not contain the year as part of the date per line, when using -stdin, the year of the log being processed is assumed to be the current year. To override this and manually specify a year, use -log_starting_year, for example -log_starting_year 2018

  • Lightmeter can also “monitor” the Postfix log directory managed by Logrotate, import existing files (even if they are gzip-compressed), and wait for new log files to occur after import. To use it, start lightmeter with -watch_dir /path/to/dir, which might be /var/log/mail. If these logs have already been imported, Lightmeter does not import them again in case the process restarts.

  • You can run it behind a reverse HTTP proxy like Apache HTTPD or Nginx, or even on a different path. No additional configuration is required.

Currently, log files for the following modes are “monitored”.

  • mail.log
  • mail.warning
  • mail.err
  • maillog
  • zimbra.log

The environment variable

For a cloud installation of Lightmeter, you may need to set parameters through environment variables rather than command-line parameters (not always).

Below are all the parameters you can set with environment variables, along with their command-line equivalents.

  • LIGHTMETER_WORKSPACE=/path/to/workspace (-workspace)
  • LIGHTMETER_WATCH_DIR=/var/log (-watch_dir)
  • LIGHTMETER_VERBOSE=true (-verbose)
  • LIGHTMETER_LISTEN=localhost:9999 (-listen)
  • LIGHTMETER_LOGS_SOCKET=unix; /path/to/socket.sock (-logs_socket)
  • LIGHTMETER_LOGS_USE_RSYNC=true (-logs_use_rsync)
  • LIGHTMETER_LOGS_STARTING_YEAR=2019 (-log_starting_year)
  • LIGHTMETER_LOG_FORMAT=prepend-rfc3339 (-log_format)

Rotating file

We were able to identify the files archived by Logrotate and import them the first time the application was run. Currently only Gzipped and uncompressed files are supported.

The log files that support archiving are suffixes.

  • Mail.log.2.gz and similar files, the older the file, the larger the suffix number.
  • Mail.log-20030102.gz, the suffix number is a date, the smaller the number, the older the file.

If you use a different log naming convention, create a problem on Gitlab.

Syslog compatibility

If you use the -watch_DIR or LIGHTMETER_WATCH_DIR environment variable to read logs, we currently only support the following syslog file formats.

rsyslog.conf Command line options The environment variable
RSYSLOG_TraditionalFileFormat -log_format defaultOr not pass the option at all LIGHTMETER_LOG_FORMAT=defaultOr not at all
RSYSLOG_SyslogProtocol23Format -log_format rfc3339 LIGHTMETER_LOG_FORMAT=rfc3339

If you use a different format, please let us know via Gitlab questions.

The import logs

The import process can take a long time, depending on how many files you have and how big they are.

It is important not to use -watch_dir with other ways of getting logs, as this behavior will be disabled in future versions of Lightmeter.

If you make a similar mistake.

2020/05/29 13:45:05 Missing file mail.log . Instead, found:  /var/log/mail/mail.log.2.gz

Copy the code

This means you should have a file called mail.log, which means you should check your Postfix installation and make sure it logs correctly.

Read from the Logstash

Note: This is a very experimental support and has not been well tested or supported. It can eat your log!

The control center can read logs over a network or Unix domain socket, which can be used to receive logs from Logstash.

Note that this support does not support any authentication or security, so be sure to use it over a secure network or provide your own security layer (VPN, SSH tunnels, etc.).

First, start the control center and select -socket TCP =:9999 to listen on TCP port 9999, or -socket Unix =/path/to/socket.sock.

Use the default JSON-encoded log

Starting with version 1.8, we support default JSON-encoded logs sent via Logstash, which means you don’t need to change your Logstash configuration.

You need to add the command line option -log_format logstash or set the environment variable LIGHTMETER_LOG_FORMAT=logstash.

Then configure the Logstash as follows.

filter {
  if [log][file][path] == "/var/log/mail.log" {
      clone {
        add_field => { "log-type" => "mail" }
        clones => ["lightmeter"]
      }
  }
}

output {
  if [log-type] == "mail" and [type] == "lightmeter"{
        tcp {
            host => "address-of-control-center-host"
            port => 9999
        }
    }
}
Copy the code

Use a custom log format

Alternatively, add the command line option -log_format prepend-rfc3339 (or the environment variable LIGHTMETER_LOG_FORMAT=prepend-rfc3339), which means it expects a time at the beginning of each log line.

Then configure the Logstash to something like the following (thanks to Alexander Landmesser for help :-).

filter {
  if [log][file][path] == "/var/log/mail.log" {
      clone {
        add_field => { "log-type" => "mail" }
        clones => ["lightmeter"]
      }
  }
}

output {
  if [log-type] == "mail" and [type] == "lightmeter"{
        tcp {
            host => "address-of-control-center-host"
            port => 9999
            codec => line {
                format => "{[@timestamp]} %{[message]}"
            }
        }
    }
}

Copy the code

Important: The control center wants to receive all Postfix logs, so do not use Logstash or ElasticSearch to filter any logs or the control center will not work properly.

Such a mechanism is very powerful and we are just beginning to explore it. If your Postfix logs are wrapped in other formats (JSON, Protobuf, etc.), you should be able to add support for them easily. Take a look at the file logeater/transform/the prepend – rfc3339. Go and look at used above – log_format the prepend – rfc3339 implementation.

Characteristics of the file

notice

Integration of slack

Create an app on your Slack account and go to api.slack.com/

  • Click on “Create Custom APP”, then you will see a pop-up window, used to configure your application (https://api.slack.com/apps).

  • Choose a “Develop Slack workspace” and give your application a name.

  • Click on the “Permissions” card or click on “OAuth & Permissions” in the sidebar.
  • Under “Range” click “Add an OAuth range”.
  • Add “chat: Write “from the drop-down menu.
  • Under “OAuth token and Redirect URLs “, click “Install to Workspace”.
  • Click “Allow” on the following page.
  • Copy the newly generated OAuth token to a secure location.
  • Invite a robot to your channel by entering the desired channel:/invite @bot-nameReplace the name and use the autocomplete prompt.

Add token and channel details to LightMeter and go to the Settings page

Congratulations on configuring Slack notifications

Domain name mapping

Domain name mapping is supported. This means that interconnected remote hosts are treated as a whole when necessary (for example, Outlook.com and Hotmail.com).

Currently, the mapping is hard-coded in the application – changing the mapping requires rebuilding the application.

Map is stored in the domainmapping/mapping json, covering the biggest remote host by default. You can easily customize the mapping by editing the file and then rebuilding it.

Consider extending the default mapping to benefit all users by making merge requests

The message the detective

Management view

You can click the “search” icon on the navigation bar to enter the information Detective’s administrative view. Using the sender address, the recipient address, and the time interval you want to check, you can determine the status of any message processed within a given time frame.

The search results will include the status of the information, the queue ID, when the information was processed, and the status code for each delivery attempt.

A message can have one of the following states.

  • Send a success message
  • Messages rejected by the recipient’s mail provider are returned.
  • Messages that were temporarily rejected and retried were delayed
  • If the delivery is abandoned after too many delays, it is overdue.
  • Return: When a return notification is sent back to the original sender (only if your Postfix is configured to do so).

Public view

You can enable information detection for any unauthenticated user on the Settings page.

Authenticated users that you provide links to can independently check the fate of emails using the same search criteria as administrators. They will also see the same amount of information in search results as the administrator.

In addition, users can choose to report any returned and expired results to the mail server administrator. Lightmeter will then generate an insight that shows all the details, including the queue ID, for the administrator to investigate further. This will also trigger a notification if you have notifications enabled.

If you have enabled message detection for your end users, be sure to share the URLS of public pages with them. The rate limit applies to the number of searches, currently the maximum is 20.

Known problems

High risk

  • The Web UI is loaded without SSL (unencrypted) by default, so the certificate is at risk if transmitted over a public network (planned fix: #480).
  • Since there is no disk reclamation policy, SQLite database size will grow linearly forever (scheduled fix: #77).
  • Memory consumption of large mail servers is unknown (scheduled fix: #238).

Low risk

  • Some insight triggers too often (depending on usage) and can fill the home page with repetitive details (planned fix: #231,#157).

  • Clicking on the chart section on the home page may cause misleading statistics to be reported (Planned fix: #63

The development of

Front-end development using VueJs

ControlCenter’s Web UI uses the VueJS framework and related tools. The front end is essentially a stand-alone Javascript application that interacts with the back end through an API. When built for production, the ControlCenter back end serves front-end files for convenience.

Foreground files, such as javascipt and CSS, need to be compiled and moved to the correct directory before they can be used by Web browsers. This process is handled automatically by the make command/build script and the VueJS terminal tool for development.

The most efficient workflow for developing/modifying front-end files is to run the front-end and back-end separately (as opposed to production mode), provide services using the Vue CLI and automatically rebuild the files in development mode. This allows you to see changes to foreground files almost immediately, without having to execute any commands or manually rebuild or compile any files.

instructions

Open two terminal Windows or tabs, and set the working directory to the Repository root of the ControlCenter.

  1. In the first terminal, build and run the ControlCenter in headless mode.
  2. Start the VueJS front-end development server in the second terminal (in development mode).make serve_frontend_dev
  3. The output from the second terminal should tell you which local URL/ port can access the development interface

Any changes made to the front-end files are automatically detected, the necessary files are rebuilt, and the changes take effect immediately in your local browser. To apply the changes to the backend files, you need to rebuild the backend from the source, since the front end now runs independently and does not affect the backend/Golang files.

Browser Automation testing

These tests (also known as user acceptance tests) are found in the Acceptance_tests directory and are performed by Gauge and Taiko. These tests are part of the CI/CD and are performed on each GitLab commit.

Refer to the acceptance_tests/ readme.md file for details on how to run these tests manually.

The user interface can be translated (I18n).

The following command will look for translatable words in the interface file (currently in the WWW directory) and generate an English.po file. make code2po

Make back-end strings translatable (i18n

Translatable strings can be found in different files, such as the Go code used on the back end, or the Vue/ HTML/JS files used in the Web UI.

To update translatable strings, make them available to translators with commands.

$ make messages
Copy the code

Example.

package
Copy the code

troubleshooting

Problems after the upgrade from VERSION X to version Y

  • Many of the problems with ControlCenter loading the UI can be solved by clearing browser cookies and caches.

Support unit

This project is funded by the EU Horizon 2020 Research and Innovation Programme within the framework of the NGI-Pointer Project, funded by Grant Agreement No. 871528.

The project is funded within the framework of the NGI-Zero project by the European Union Horizon 2020 Research and Innovation Programme under grant Agreement Number 825310.

License and copyright information

This project is licensed under AGPL-3.0. However, some files are under different licenses, please check individual files and files for accurate information. Reuse /dep5.

Copyright 2021, Lightmeter[email protected]

GitHub

Github.com/lightmeteri…