## Setup

1. Create a monitoring user on MSSQL for Zabbix to connect to:
    - for MSSQL Server 2022
    ```sql
    CREATE LOGIN zabbix WITH PASSWORD = 'password'
    GRANT VIEW SERVER PERFORMANCE STATE TO zabbix
    GRANT VIEW ANY DEFINITION TO zabbix
    USE msdb
    CREATE USER zabbix FOR LOGIN zabbix
    GRANT EXECUTE ON msdb.dbo.agent_datetime TO zabbix
    GRANT SELECT ON msdb.dbo.sysjobactivity TO zabbix
    GRANT SELECT ON msdb.dbo.sysjobservers TO zabbix
    GRANT SELECT ON msdb.dbo.sysjobs TO zabbix
    GO
    ```
    - for MSSQL versions 2017 and 2019
    ```sql
    CREATE LOGIN zabbix WITH PASSWORD = 'password'
    GRANT VIEW SERVER STATE TO zabbix
    GRANT VIEW ANY DEFINITION TO zabbix
    USE msdb
    CREATE USER zabbix FOR LOGIN zabbix
    GRANT EXECUTE ON msdb.dbo.agent_datetime TO zabbix
    GRANT SELECT ON msdb.dbo.sysjobactivity TO zabbix
    GRANT SELECT ON msdb.dbo.sysjobservers TO zabbix
    GRANT SELECT ON msdb.dbo.sysjobs TO zabbix
    GO
    ```

    To allow Zabbix to query SQL Server Agent job information, a dedicated login must be created and granted the required permissions through T-SQL:
        - **VIEW SERVER STATE** is required for Microsoft SQL Server 2017 and 2019
        - **VIEW SERVER PERFORMANCE STATE** is required for Microsoft SQL Server 2022
        - **VIEW ANY DEFINITION** allows access to object definitions and metadata
        - **SELECT** allows the user to read data from the sysjobschedules, sysjobhistory, and sysjobs tables in the msdb database  
    
    
    For more information, see MSSQL documentation:
        - [Create a database user](https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-database-user?view=sql-server-ver16)
        - [GRANT Server Permissions](https://docs.microsoft.com/en-us/sql/t-sql/statements/grant-server-permissions-transact-sql?view=sql-server-ver16)
        - [Configure a User to Create and Manage SQL Server Agent Jobs](https://docs.microsoft.com/en-us/sql/ssms/agent/configure-a-user-to-create-and-manage-sql-server-agent-jobs?view=sql-server-ver16)

2. Set the username and password in the `MSSQL user` and `MSSQL password` host wizard configuration fields.  
3. Set the connection string for the MSSQL instance in the `MSSQL URI` host wizard configuration field as a URI, such as `<protocol://host:port>`, or specify the named session - `<sessionname>`.

    The `Service's TCP port state` item uses the `MSSQL address` and `MSSQL TCP port` host wizard configuration fields to check the availability of the MSSQL instance, change these if necessary. Keep in mind that if dynamic ports are used on the MSSQL server side, this check will not work correctly.
    
    Additional notes:
    - You can use the `Monitoring of full backup`, `Monitoring of log backup`, and `Monitoring of differential backup` host wizard configuration fields to disable backup age triggers. If set to unselected state, the trigger expression for the backup age will not fire.
    - Since version 7.2.0, you can also connect to the MSSQL instance using its name. To do this, set the connection string in the `MSSQL URI` host wizard configuration field as `<protocol://host/instance_name>`.