Skip to content

1. Setup a WTS service

MarkVanDijkHG edited this page Jul 31, 2023 · 5 revisions

General

To setup a WTS service (after installation ofcourse) you need to configure a correct appsettings.json file, in this Wiki we will describe all the properties of the appsettings.json file.

'Wts' object

In the appsettings.json of the WTS, the Wiser Task Scheduler itself can be set under the key "Wts". This object contains the following properties;

Property name Mandatory Default value Explanation
Name no Wiser Task Scheduler (Machine name) The name of the WTS that can be used to identify the correct WTS in log files, for example.

If no name is specified, the default is used where the name of the machine on which the WTS is running is included.
SecretsBaseDirectory yes Null The absolute path to the folder containing the "wts-appsettings-secrets.json". This file contains all the secret keys. See section "Secrets" for more information.
MainService yes Null Determines how often new configurations must be read and where to find the configuration of the runschemes with its actions. See section "MainService" for more information.
CleanupService no Default values of 'Cleanupservice' How the cleanup of log files should be handled. See section "CleanupService" for more information.

MainService object

Property name Mandatory Default value Explanation
LocalConfiguration no Null The absolute path to a local configuration file for execution. When set, no configurations are loaded from Wiser.
LocalOAuthConfiguration no Null The absolute path to a local OAuth configuration file to use for OAuth with HTTP APIs. See the 'OAuth 2.0' section for more information.
RunScheme yes Null Determined when the MainService checks for new configurations added or existing ones modified or deleted. See the 'Run schemes' section for more information.

CleanupService object

Property name Mandatory Default value Explanation
FileFolderPaths no Null A collection of paths in which files should be deleted if they are older than NumberOfDaysToStore.
NumberOfDaysToStore no 14 The number of days before something may be deleted such as a log file or information from the database.
RunScheme no daily at 00.00 Determines when the CleanupService will start cleaning up. See the 'Run schemes' section for more information.
OptimizeLogsTableAfterCleanup no true After cleaning the logs, the wts_logs table is optimized.
NumberOfDaysToStoreRenderTimes no 14 The number of days before the render times may be deleted from the database.
OptimizeRenderTimesTableAfterCleanup no true After cleaning up the render times, the wiser_template_render_log and wiser_dynamic_content_render_log tables are optimized.

Example:

"Wts": {
    "Name": "Customer name",
    "SecretsBaseDirectory": "C:\\WiserSecrets\\",
    "MainService": {
        "LocalConfiguration": "C:\WTS configurations\WTSTestSettings.xml",
        "LocalOAuthConfiguration": "C:\WTS configurations\OAuthSettings.xml",
        "RunScheme": {
            "Type": "Continuous",
            "TimeId": 0,
            "Delay": "00:05:00"
            }
        },
    "CleanupService": {
        "LogFileFolderPaths": [ "C:/temp/wiser_task_scheduler/" ]
    }
}

Secrets

Properties that contain sensitive information are placed in an external json file so that it stays outside the application and thus does not, for example, end up on GitHub. The name of this 'secret' file is always wts-appsettings-secrets.json. The location of the file is set in the appsettings.json of the WTS.

The secret JSON object consists of the following subobjects;

Property name Explanation
GCL This is a JSON object that sets things like the connection string to the database and the smtp settings for sending email. The GCL is the .net core Library used by both Wiser and the WTS.
Wts This object in turn contains the following sub-objects described further below;
  • Wiser: information for linking to a Wiser account and the Wiser API from which to load configurations
  • SlackSettings: information for linking to a Slack account to receive notifications on it
  • Credentials: a dictionary of key/value pairs that can be used within the configurations of the WTS
  • The GCL object

    Property name Mandatory Default value Explanation
    DefaultEncryptionKey no Null The encryption key used to encrypt and decrypt the OAuth access and refresh tokens in the database. Use the same key that is set up for Wiser.

    Required only if an OAuth configuration is used. See the 'OAuth 2.0' section for more information.
    ConnectionString yes Null The connection string of the database used by the WTS for loading templates, storing logs and reading 'system objects' (in the easy_objects table).
    SmtpSettings no Null The SMTP settings to be used by the GCL. See the 'Communication' section for the settings.

    Used by ServiceFailedNotificationEmails, see the 'WTS secrets' sections below for more information.

    The Wts object

    Property name Mandatory Default value Explanation
    Wiser.Username yes Null The login name of the user for Wiser with which the WTS should log in to the API. See section "Creating WTS User."
    Wiser.Password yes Null The password for the Wiser user with which the WTS should log in to the API. See section "Creating WTS User."
    Wiser.Subdomain yes Null The client's subdomain that is logged into Wiser 3 (in case of multitenency)
    Wiser.WiserApiUrl yes Null The URL of the Wiser API being connected to.
    Wiser.ClientId yes Null The client ID of Wiser, this value is always: Wiser
    Wiser.ClientSecret yes Null Wiser's client secret, this value is defined by the used Wiser API
    Wiser.TestEnvironment no false Indicates whether the connection is set up from a test environment.
    Wiser.ConfigurationPath yes Null The path to the configurations to be read from Wiser . Seen from the WTS folder in the Wiser template module.

    All underlying folders are also read out.

    To designate a folder at a deeper level place the path to the desired folder with comma separated names settings,settings1.

    To specify multiple folders you can do so by indicating common;server1;server2 with semicolon separated names. (Each path is relative from the start.)
    ServiceFailedNotificationEmails no Null Email addresses separated by a semicolon (;) to which an email should be sent if a core service fails.
    ErrorNotificationsIntervalInMinutes no 60 The number of minutes to wait between sending the same error message again. For both email notifications and Slack messages.
    SlackSettings no Null The settings to send error messages to a Slack channel. See section "Slack" for more information.
    Credentials no Null A dictionary of credentials that can be used in configurations to extract login credentials or other secrets from the configuration.

    When loading the configuration into the WTS, these values are replaced. The configuration should then contain [{Credential:<key>}], for example [{Credential:ApiToken}].

    Create a Wiser user for the WTS

    To read configurations from Wiser, the WTS must be able to log in to the API. To do this, a new user can be set up or an existing one can be used.

    1. Log in to the appropriate Wiser account to which the WTS is to be linked;
    2. Open the "Users - Wiser" module;
    3. Click "Add new entry" and give the user a name;
    4. Enter a username and password and save the user;
    5. Give the user appropriate permissions by assigning the appropriate roles.
    6. In the secrets file, enter the username and password of the user created.

    The Slack object

    Error messages can be sent to a Slack channel. This requires adding the SlackSettings in the secrets file. By default, messages are sent on critical logs, this can be changed in the Log settings.

    Property name Mandatory Default value Explanation
    BotToken yes Null The bot token used for the Slack API to send messages.
    Channel yesy Null The channel to which the log should be sent. For public channels, there should be a hashtag (#) in front of this name.

    The BotToken is the same for all project channels that are within the same Slack organization. If messages need to be sent to a channel of an organization where a bot has not yet been set up, the steps under section "Setting up Slack bot" can be followed.

    Set up Slack bot

    1. Navigate to https://api.slack.com/apps and create a new app;
    2. Under "Add features and functionality" choose "Permissions";
    3. Under "Scopes" add the "chat:write" scope to "Bot Token Scopes";
    4. Click "Install to Workspace."
    5. Copy the "Bot User OAuth Token" and save it somewhere for later use (this is the token used in the BotToken prooperty;
    6. (Optional) After creating, under the "Collaborators" tab, add people who are also allowed to manage the app.

    Receiving messages in channel

    When an existing bot is used or a new one is deployed, it must be given access to the channel where messages are to be posted.

    1. Click the button for "View all members of this channel" in the upper right corner;
    2. Go to the "Integrations" tab;
    3. Under "Apps," click on "Add apps."
    4. Choose the "Wiser Task Scheduler" app (or the name set when it was created);
    5. The WTS can now send messages to this channel.

    Example of a secret JSON file

    {
        "GCL": {
            "DefaultEncryptionKey": "",
            "ConnectionString": "server=host;port=port;uid=username;pwd=password;database=db;pooling=false;Allow User Variables=True;CharSet=utf8"
        },
        "Wts": {
            "Wiser": {
                "Username": "",
                "Password": "",
                "Subdomain": "",
                "WiserApiUrl": "https://localhost:44349/",
                "ClientId": "wiser",
                "ClientSecret" : "",
                "TestEnvironment": true,
                "ConfigurationPath": "settings"
            },
            "ServiceFailedNotificationEmails": "",
            "ErrorNotificationsIntervalInMinutes": 60,
            "SlackSettings": {
                "AccessToken":	"",
                "Channel": ""
            },
        "Credentials": {
            "ApiKey": "ABCD1234",
            "DatabaseUser": "User",
            "DatabasePassword": "P@55w0rd"
            }
        }
    }