JSON Schema definitions

---
"$schema": "http://json-schema.org/schema#"
id: "hat://logging.yaml#"
title: Logging
description: Logging configuration
type: object
required:
    - version
properties:
    version:
        title: Version
        type: integer
        default: 1
    formatters:
        title: Formatters
        type: object
        patternProperties:
            "(.)+":
                title: Formatter
                type: object
                properties:
                    format:
                        title: Format
                        type: string
                        default: null
                    datefmt:
                        title: Date format
                        type: string
                        default: null
    filters:
        title: Filters
        type: object
        patternProperties:
            "(.)+":
                title: Filter
                type: object
                properties:
                    name:
                        title: Logger name
                        type: string
                        default: ''
    handlers:
        title: Handlers
        type: object
        patternProperties:
            "(.)+":
                title: Handler
                type: object
                description: |
                    Additional properties are passed as keyword arguments to
                    constructor
                required:
                    - class
                properties:
                    class:
                        title: Class
                        type: string
                    level:
                        title: Level
                        type: string
                    formatter:
                        title: Formatter
                        type: string
                    filters:
                        title: Filters
                        type: array
                        items:
                            title: Filter id
                            type: string
    loggers:
        title: Loggers
        type: object
        patternProperties:
            "(.)+":
                title: Logger
                type: object
                properties:
                    level:
                        title: Level
                        type: string
                    propagate:
                        title: Propagate
                        type: boolean
                    filters:
                        title: Filters
                        type: array
                        items:
                            title: Filter id
                            type: string
                    handlers:
                        title: Handlers
                        type: array
                        items:
                            title: Handler id
                            type: string
    root:
        title: Root logger
        type: object
        properties:
            level:
                title: Level
                type: string
            filters:
                title: Filters
                type: array
                items:
                    title: Filter id
                    type: string
            handlers:
                title: Handlers
                type: array
                items:
                    title: Handler id
                    type: string
    incremental:
        title: Incremental configuration
        type: boolean
        default: false
    disable_existing_loggers:
        title: Disable existing loggers
        type: boolean
        default: true
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://syslog.yaml#"
title: Syslog server
description: Syslog server configuration
type: object
required:
    - type
    - log
    - syslog_addr
    - ui_addr
    - db_path
    - db_low_size
    - db_high_size
    - db_enable_archive
    - db_disable_journal
properties:
    type:
        enum:
            - syslog
        description: configuration type identification
    version:
        type: string
        description: component version
    log:
        "$ref": "hat://logging.yaml#"
    syslog_addr:
        type: string
        description: |
            syslog listening address in form `<protocol>://<host>:<port>`
            where `<protocol>` can be `tcp`, `udp` or `ssl`
    syslog_pem:
        type: string
        description: |
            path to PEM file is mandatory if syslog address is ssl
    ui_addr:
        type: string
        description: |
            web server listening address in form `<protocol>://<host>:<port>`
            where `<protocol>` can be `http` or `https`
    ui_pem:
        type: string
        description: |
            path to PEM file is mandatory if ui address is https
    db_path:
        type: string
        description: |
            path to sqlite database file
    db_low_size:
        type: integer
        description: |
            number of messages kept in database after database cleanup
    db_high_size:
        type: integer
        description: |
            number of messages that will trigger database cleanup
    db_enable_archive:
        type: boolean
        description: |
            should messages, deleted during database cleanup, be kept in
            archive files
    db_disable_journal:
        type: boolean
        description: |
            disable sqlite jurnaling
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://orchestrator.yaml#"
title: Orchestrator
description: Orchestrators's configuration
type: object
required:
    - type
    - log
    - components
    - ui
properties:
    type:
        enum:
            - orchestrator
        description: configuration type identification
    version:
        type: string
        description: component version
    log:
        "$ref": "hat://logging.yaml#"
    components:
        title: Components
        type: array
        items:
            "$ref": "hat://orchestrator.yaml#/definitions/component"
    ui:
        "$ref": "hat://orchestrator.yaml#/definitions/ui"
definitions:
    component:
        title: Component
        type: object
        required:
            - name
            - args
            - delay
            - revive
            - start_delay
            - create_timeout
            - sigint_timeout
            - sigkill_timeout
        properties:
            name:
                title: Component name
                type: string
            args:
                title: Command line arguments
                description: |
                    Shell command executed by orchestrator from
                    orchestrator's current working directory
                type: array
                items:
                    type: string
            delay:
                title: Delay
                description: |
                    Startup delay applied only for first component's
                    startup. If value is 0, timeout is ignored.
                type: number
            revive:
                title: Revive
                description: |
                    If this property is set to true, orchestrator will start
                    component's process if process is stopped.
                type: boolean
            start_delay:
                title: Start delay
                description: |
                    Delay in seconds applied before each component's startup.
                type: number
                default: 0.5
            create_timeout:
                title: Create timeout
                description: |
                    Timeout in seconds for creating process.
                type: number
                default: 2
            sigint_timeout:
                title: SIGINT timeout
                description: |
                    Timeout in seconds for waiting return code after sending
                    SIGINT.
                type: number
                default: 5
            sigkill_timeout:
                title: SIGKILL timeout
                description: |
                    Timeout in seconds for waiting return code after sending
                    SIGKILL.
                type: number
                default: 2
    ui:
        title: Server
        type: object
        required:
            - address
        properties:
            address:
                title: UI address
                type: string
                default: "http://localhost:23021"
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://manager/main.yaml#"
title: Manger
description: Manager's configuration
type: object
required:
    - type
    - log
    - settings
    - devices
properties:
    type:
        const: manager
        description: configuration type identification
    version:
        type: string
        description: component version
    log:
        "$ref": "hat://logging.yaml#"
    settings:
        "$ref": "hat://manager/main.yaml#/definitions/settings"
    devices:
        type: array
        items:
            "$ref": "hat://manager/main.yaml#/definitions/device"
definitions:
    settings:
        type: object
        required:
            - ui
            - log
        properties:
            ui:
                type: object
                required:
                    - address
                properties:
                    address:
                        type: string
            log:
                type: object
                required:
                    - level
                    - syslog
                    - console
                properties:
                    level:
                        type: string
                    syslog:
                        type: object
                        required:
                            - enabled
                            - host
                            - port
                        properties:
                            enabled:
                                type: boolean
                            host:
                                type: string
                            port:
                                type: integer
                    console:
                        type: object
                        required:
                            - enabled
                        properties:
                            enabled:
                                type: boolean
    device:
        allOf:
          - type: object
            required:
                - type
                - name
                - auto_start
            properties:
                name:
                    type: string
                auto_start:
                    type: boolean
          - oneOf:
                - "$ref": "hat://manager/orchestrator.yaml#"
                - "$ref": "hat://manager/monitor.yaml#"
                - "$ref": "hat://manager/event.yaml#"
                - "$ref": "hat://manager/iec104.yaml#"
                - "$ref": "hat://manager/modbus.yaml#"
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://manager/iec104.yaml#"
title: IEC104 devices
oneOf:
  - type: object
    properties:
        type:
            const: iec104_master
  - type: object
    properties:
        type:
            const: iec104_slave
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://manager/event.yaml#"
title: Event device
required:
    - address
properties:
    type:
        const: event
    address:
        type: string
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://manager/orchestrator.yaml#"
title: Orchestrator device
required:
    - address
properties:
    type:
        const: orchestrator
    address:
        type: string
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://manager/monitor.yaml#"
title: Monitor device
required:
    - address
properties:
    type:
        const: monitor
    address:
        type: string
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://manager/modbus.yaml#"
title: Modbus devices
oneOf:
  - type: object
    properties:
        type:
            const: modbus_master
  - type: object
    properties:
        type:
            const: modbus_slave
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://gui/main.yaml#"
title: GUI server
description: GUI server's configuration
type: object
required:
    - type
    - log
    - monitor
    - event_server_group
    - adapters
    - views
    - address
    - initial_view
    - users
properties:
    type:
        enum:
            - gui
        description: configuration type identification
    version:
        type: string
        description: component version
    log:
        "$ref": "hat://logging.yaml#"
    monitor:
        "$ref": "hat://monitor/client.yaml#"
    event_server_group:
        type: string
    adapters:
        type: array
        items:
            type: object
            required:
                - name
                - module
            properties:
                name:
                    type: string
                module:
                    type: string
    views:
        type: array
        items:
            type: object
            required:
                - name
                - view_path
                - conf_path
            properties:
                name:
                    type: string
                view_path:
                    type: string
                conf_path:
                    type:
                        - string
                        - "null"
    address:
        type: string
        default: "http://localhost:23023"
    initial_view:
        type:
            - string
            - "null"
    users:
        type: array
        items:
            type: object
            required:
                - name
                - password
                - roles
                - view
            properties:
                name:
                    type: string
                password:
                    type: object
                    required:
                        - hash
                        - salt
                    properties:
                        hash:
                            type: string
                            description: |
                                SHA256(salt + SHA256(password)) hash encoded as
                                hex string
                        salt:
                            type: string
                            decription: |
                                unique salt used for generating hash encoded as
                                hex string
                roles:
                    type: array
                    items:
                        type: string
                view:
                    type:
                        - string
                        - "null"
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://gui/adapters/latest.yaml#"
title: Latest adapter
type: object
required:
    - authorized_roles
    - items
properties:
    authorized_roles:
        type: array
        items:
            type: string
    items:
        type: array
        items:
            type: object
            required:
                - key
                - event_type
            properties:
                key:
                    type: string
                event_type:
                    type: array
                    items:
                        type: string
---
"$schema": "http://json-schema.org/schema#"
id: "hat://monitor/main.yaml#"
title: Monitor Server
description: Monitor Server's configuration
type: object
required:
    - type
    - log
    - server
    - master
    - slave
    - ui
properties:
    type:
        enum:
            - monitor
        description: configuration type identification
    version:
        type: string
        description: component version
    log:
        "$ref": "hat://logging.yaml#"
    server:
        "$ref": "hat://monitor/main.yaml#/definitions/server"
    master:
        "$ref": "hat://monitor/main.yaml#/definitions/master"
    slave:
        "$ref": "hat://monitor/main.yaml#/definitions/slave"
    ui:
        "$ref": "hat://monitor/main.yaml#/definitions/ui"
definitions:
    server:
        title: Local monitor server
        type: object
        required:
            - address
            - default_rank
        properties:
            address:
                title: Listening address
                type: string
                default: "tcp+sbs://127.0.0.1:23010"
            default_rank:
                type: integer
    master:
        title: Master interface
        type: object
        required:
            - address
            - default_algorithm
            - group_algorithms
        properties:
            address:
                title: Listening address
                type: string
                default: "tcp+sbs://127.0.0.1:23011"
            default_algorithm:
                "$ref": "hat://monitor/main.yaml#/definitions/algorithm"
            group_algorithms:
                description: |
                    keys represent group names
                type: object
                patternProperties:
                    "(.)+":
                        "$ref": "hat://monitor/main.yaml#/definitions/algorithm"
    slave:
        type: object
        required:
            - parents
        properties:
            parents:
                title: parent addresses
                type: array
                items:
                    type: string
    ui:
        title: UI Web Server
        type: object
        required:
            - address
        properties:
            address:
                title: UI address
                type: string
                default: "http://127.0.0.1:23022"
    algorithm:
        enum:
            - BLESS_ALL
            - BLESS_ONE
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://monitor/client.yaml#"
title: Monitor client
description: Monitor client's configuration
type: object
required:
    - name
    - group
    - monitor_address
    - component_address
properties:
    name:
        type: string
    group:
        type: string
    monitor_address:
        type: string
    component_address:
        type:
            - string
            - "null"
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://event/main.yaml#"
title: Event Server
description: Event Server's configuration
type: object
required:
    - type
    - log
    - monitor
    - backend_engine
    - module_engine
    - communication
properties:
    type:
        enum:
            - event
        description: configuration type identification
    version:
        type: string
        description: component version
    log:
        "$ref": "hat://logging.yaml#"
    monitor:
        "$ref": "hat://monitor/client.yaml#"
    backend_engine:
        "$ref": "hat://event/main.yaml#/definitions/backend_engine"
    module_engine:
        "$ref": "hat://event/main.yaml#/definitions/module_engine"
    communication:
        "$ref": "hat://event/main.yaml#/definitions/communication"
definitions:
    backend_engine:
        type: object
        required:
            - server_id
            - backend
        properties:
            server_id:
                type: integer
            backend:
                "$ref": "hat://event/main.yaml#/definitions/backend"
    module_engine:
        type: object
        required:
            - modules
        properties:
            modules:
                type: array
                items:
                    "$ref": "hat://event/main.yaml#/definitions/module"
    communication:
        type: object
        required:
            - address
        properties:
            address:
                type: string
                default: "tcp+sbs://localhost:23012"
    backend:
        type: object
        description: |
            structure of backend configuration depends on backend type
        required:
            - module
        properties:
            module:
                type: string
                description: |
                    full python module name that implements backend
    module:
        type: object
        description: |
            structure of module configuration depends on module type
        required:
            - module
        properties:
            module:
                type: string
                description: |
                    full python module name that implements module
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://event/backends/sqlite.yaml#"
title: Sqlite backend
description: Sqlite backend configuration
type: object
required:
    - db_path
    - query_pool_size
properties:
    db_path:
        type: string
        description: path to sqlite database file
    query_pool_size:
        type: integer
        description: |
            number of connections in a pool used for querying
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://event/backends/lmdb.yaml#"
title: LMDB backend
type: object
required:
    - db_path
    - max_db_size
    - sync_period
    - server_id
    - conditions
    - latest
    - ordered
properties:
    db_path:
        type: string
    max_db_size:
        type: number
    sync_period:
        type: number
    server_id:
        type: integer
    conditions:
        type: array
        items:
            type: object
            required:
                - subscriptions
                - condition
            properties:
                subscriptions:
                    "$ref": "hat://event/backends/lmdb.yaml#/definitions/event_types"
                condition:
                    "$ref": "hat://event/backends/lmdb.yaml#/definitions/condition"
    latest:
        type: object
        required:
            - subscriptions
        properties:
            subscriptions:
                "$ref": "hat://event/backends/lmdb.yaml#/definitions/event_types"
    ordered:
        type: array
        items:
            type: object
            required:
                - order_by
                - subscriptions
            properties:
                order_by:
                    enum:
                        - TIMESTAMP
                        - SOURCE_TIMESTAMP
                subscriptions:
                    "$ref": "hat://event/backends/lmdb.yaml#/definitions/event_types"
                limit:
                    "$ref": "hat://event/backends/lmdb.yaml#/definitions/limit"
definitions:
    event_types:
        type: array
        items:
            type: array
            items:
                type: string
    limit:
        type: object
        properties:
            min_entries:
                type: number
                description: |
                    number of entries kept despite of other limits
            max_entries:
                type: number
                description: |
                    maximum number of entries
            duration:
                type: number
                description: |
                    limit for the persisted history based on keys
                    expressed as duration in seconds
            size:
                type: number
                description: |
                    memory consumption size in bytes that triggers
                    additional cleanup based on average entry size
    condition:
        oneOf:
            - "$ref": "hat://event/backends/lmdb.yaml#/definitions/conditions/all"
            - "$ref": "hat://event/backends/lmdb.yaml#/definitions/conditions/any"
            - "$ref": "hat://event/backends/lmdb.yaml#/definitions/conditions/json"
    conditions:
        all:
            type: object
            required:
                - type
                - conditions
            properties:
                type:
                    const: all
                conditions:
                    type: array
                    items:
                        "$ref": "hat://event/backends/lmdb.yaml#/definitions/condition"
        any:
            type: object
            required:
                - type
                - conditions
            properties:
                type:
                    const: any
                conditions:
                    type: array
                    items:
                        "$ref": "hat://event/backends/lmdb.yaml#/definitions/condition"
        json:
            type: object
            required:
                - type
            properties:
                type:
                    const: json
                data_path:
                    "$ref": "hat://event/backends/lmdb.yaml#/definitions/path"
                data_type:
                    enum:
                        - "null"
                        - boolean
                        - string
                        - number
                        - array
                        - object
                data_value: {}
    path:
        oneOf:
          - type: string
          - type: integer
          - type: array
            items:
                "$ref": "hat://event/backends/lmdb.yaml#/definitions/path"
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://gateway/main.yaml#"
title: Gateway
description: Gateway's configuration
type: object
required:
    - type
    - log
    - monitor
    - event_server_group
    - gateway_name
    - devices
properties:
    type:
        enum:
            - gateway
        description: configuration type identification
    version:
        type: string
        description: component version
    log:
        "$ref": "hat://logging.yaml#"
    monitor:
        "$ref": "hat://monitor/client.yaml#"
    event_server_group:
        type: string
    gateway_name:
        type: string
    devices:
        type: array
        items:
            "$ref": "hat://gateway/main.yaml#/definitions/device"
definitions:
    device:
        type: object
        description: |
            structure of device configuration depends on device type
        required:
            - module
            - name
        properties:
            module:
                type: string
                description: |
                    full python module name that implements device
            name:
                type: string
...
---
"$schema": "http://json-schema.org/schema#"
id: "hat://gateway/modbus.yaml#"
title: Modbus devices
definitions:
    master:
        type: object
        title: Modbus master
        required:
            - connection
            - remote_devices
        properties:
            connection:
                type: object
                required:
                    - modbus_type
                    - transport
                    - connect_timeout
                    - connect_delay
                    - request_timeout
                    - request_retry_count
                    - request_retry_delay
                properties:
                    modbus_type:
                        description: |
                            Modbus message encoding type
                        enum:
                            - TCP
                            - RTU
                            - ASCII
                    transport:
                        oneOf:
                          - type: object
                            required:
                                - type
                                - host
                                - port
                            properties:
                                type:
                                    const: TCP
                                host:
                                    type: string
                                    description: |
                                        Remote host name
                                port:
                                    type: integer
                                    description: |
                                        Remote host TCP port
                                    default: 502
                          - type: object
                            required:
                                - type
                                - port
                                - baudrate
                                - bytesize
                                - parity
                                - stopbits
                                - flow_control
                                - silent_interval
                            properties:
                                type:
                                    const: SERIAL
                                port:
                                    type: string
                                    description: |
                                        Serial port name (e.g. /dev/ttyS0)
                                baudrate:
                                    type: integer
                                    description: |
                                        Baud rate (e.g. 9600)
                                bytesize:
                                    description: |
                                        Number of data bits
                                    enum:
                                        - FIVEBITS
                                        - SIXBITS
                                        - SEVENBITS
                                        - EIGHTBITS
                                parity:
                                    description: |
                                        Parity checking
                                    enum:
                                        - NONE
                                        - EVEN
                                        - ODD
                                        - MARK
                                        - SPACE
                                stopbits:
                                    description: |
                                        Number of stop bits
                                    enum:
                                        - ONE
                                        - ONE_POINT_FIVE
                                        - TWO
                                flow_control:
                                    type: object
                                    required:
                                        - xonxoff
                                        - rtscts
                                        - dsrdtr
                                    properties:
                                        xonxoff:
                                            type: boolean
                                            description: |
                                                Enable software flow control
                                        rtscts:
                                            type: boolean
                                            description: |
                                                Enable hardware (RTS/CTS) flow control
                                        dsrdtr:
                                            type: boolean
                                            description: |
                                                Enable hardware (DSR/DTR) flow control
                                silent_interval:
                                    type: number
                                    description: |
                                        Serial communication silet interval
                    connect_timeout:
                        type: number
                        description: |
                            Maximum number of seconds available to single connection
                            attempt
                    connect_delay:
                        type: number
                        description: |
                            Delay (in seconds) between two consecutive connection
                            establishment attempts
                    request_timeout:
                        type: number
                        description: |
                            Maximum duration (in seconds) of read or write
                            request/response exchange.
                    request_retry_count:
                        type: integer
                        description: |
                            Number of request retries before remote data is considered
                            unavailable
                    request_retry_delay:
                        type: number
                        description: |
                            Delay (in seconds) between two consecutive request retries
            remote_devices:
                type: array
                items:
                    type: object
                    required:
                        - device_id
                        - data
                    properties:
                        device_id:
                            type: integer
                            description: |
                                Modbus device identifier
                        data:
                            type: array
                            items:
                                type: object
                                required:
                                    - name
                                    - interval
                                    - data_type
                                    - start_address
                                    - bit_offset
                                    - bit_count
                                properties:
                                    name:
                                        type: string
                                        description: |
                                            Data point name
                                    interval:
                                        type:
                                            - number
                                            - "null"
                                        description: |
                                            Polling interval in seconds or
                                            null if polling is disabled
                                    data_type:
                                        description: |
                                            Modbus register type
                                        enum:
                                            - COIL
                                            - DISCRETE_INPUT
                                            - HOLDING_REGISTER
                                            - INPUT_REGISTER
                                            - QUEUE
                                    start_address:
                                        type: integer
                                        description: |
                                            Starting address of modbus register
                                    bit_offset:
                                        type: integer
                                        description: |
                                            Bit offset (number of bits skipped)
                                    bit_count:
                                        type: integer
                                        description: |
                                            Number of bits used for
                                            encoding/decoding value (not
                                            including offset bits)
...