~cypheon/ecertmon

08c2ae1c68467643a1f27d2c8340dd90070ab87b — Johann Rudloff 1 year, 9 months ago c3d1a0f
Externalize configuration

Path to the configuration file is now passed via an environment
variable. This makes it possible to run the same release with different
configurations.
5 files changed, 27 insertions(+), 11 deletions(-)

M README.md
A config/certmon.sample.config
R config/{sys.config => sys.config.src}
M relx.config
M src/certmon_app.erl
M README.md => README.md +8 -4
@@ 10,7 10,7 @@ You configure which hosts should be scanned:
           {"neo.sinyax.net", 443},
           {"git.sinyax.net", 443}
          ]
}
}.
```

And ecertmon will export one metric for each configured target presenting the


@@ 37,16 37,20 @@ make app

## Configure

The config file is in `config/sys.config` under the key `certmon`. The config
settings have quite descriptive names and should be self-explanatory.
A config sample is in `config/certmon.sample.config`. The config settings have
quite descriptive names and should be self-explanatory.

The path to the config file needs to be passed as value of the environment
variable `CERTMON_CONFIG_FILE`.

## Run (from Source)

```sh
# Run the project
# (run from inside the source root directory)
# Using an absolute path for $CERTMON_CONFIG_FILE helps to prevent headaches

make run
CERTMON_CONFIG_FILE="$PWD/config/certmon.sample.config" make run
```

## Run (from Release)

A config/certmon.sample.config => config/certmon.sample.config +6 -0
@@ 0,0 1,6 @@
{port, 9101}.
{scan_interval, 30000}.
{targets, [
           {"neo.sinyax.net", 443}
          ]
}.

R config/sys.config => config/sys.config.src +1 -6
@@ 3,11 3,6 @@
           {logger_level, notice}
          ]},
 {certmon, [
            {port, 9101},
            {scan_interval, 30000},
            {targets, [
                       {"neo.sinyax.net", 443}
                      ]
            }
            {config_file, "${CERTMON_CONFIG_FILE}"}
           ]}
].

M relx.config => relx.config +1 -1
@@ 1,4 1,4 @@
{release, {certmon_release, "1"}, [certmon, sasl, runtime_tools]}.
{extended_start_script, true}.
{sys_config, "config/sys.config"}.
{sys_config_src, "config/sys.config.src"}.
{vm_args, "config/vm.args"}.

M src/certmon_app.erl => src/certmon_app.erl +11 -0
@@ 5,6 5,8 @@
-export([stop/1]).

start(_Type, _Args) ->
  {ok, ConfigFilePath} = application:get_env(config_file),
  ok = load_config_file(ConfigFilePath),
  {ok, Targets} = application:get_env(targets),
  {ok, Port} = application:get_env(port),
  Dispatch = cowboy_router:compile([


@@ 20,3 22,12 @@ start(_Type, _Args) ->

stop(_State) ->
  ok.

load_config_file(FilePath) ->
  case file:consult(FilePath) of
    {ok, Config} -> application:set_env([{certmon, Config}]),
                    logger:notice("Config loaded from ~n", [FilePath]),
                    ok;
    {error, Error} -> logger:error("Unable to load config file from path ~p: ~p, please set the environment variable CERTMON_CONFIG_FILE accordingly", [FilePath, Error]),
         Error
  end.