Ad Widget

Collapse

MSSQL Plugin work but parameter of custom query not

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brambo
    Senior Member
    • Jul 2023
    • 245

    #1

    MSSQL Plugin work but parameter of custom query not

    So like the title says:
    Code:
    mssql.ping[sqlserver://{$1DBSERVER}:{$1DBPORT},{$1MSSQL_USER},{$1MSSQL_PASSWORD}]
    Works and gives a 1 as response, changing a value in the macro to an incorrect one results in output 0.
    In the MSSQL.conf beside the system.path i have also set the CustomQueriesDir paramater.
    And that is all i have in the conf file.
    A file with the MyCquery.sql extension contains the following query
    Code:
    SELECT [Application], [Hostname], [Status]
    FROM @p1
    Nothing special but the scenario is that during a software install of the product I want to monitor the database name i flexibel so i want to use a host macro to set this up.
    In the following code block are the item keys i tried but all fail with the same message:
    {$DBNAME} = TheDBname.table.dbo.name
    Code:
    mssql.custom.query[sqlserver://{$1DBSERVER}:{$1DBPORT},{$1MSSQL_USER},{$1MSSQL_PASSWORD},MyCquery,TheDBname.table.dbo.name]
    mssql.custom.query[sqlserver://{$1DBSERVER}:{$1DBPORT},{$1MSSQL_USER},{$1MSSQL_PASSWORD},MyCquery,'TheDBname.table.dbo.name']
    mssql.custom.query[sqlserver://{$1DBSERVER}:{$1DBPORT},{$1MSSQL_USER},{$1MSSQL_PASSWORD},MyCquery,"TheDBname.table.dbo.name"]
    mssql.custom.query[sqlserver://{$1DBSERVER}:{$1DBPORT},{$1MSSQL_USER},{$1MSSQL_PASSWORD},MyCquery,{$DBNAME}]
    The first few alo
    The error: Failed to execute handler: failed to execute handler: failed to query: mssql: Must declare the table variable "@p1".
    The query's work fine with database.table.dbo.name when running it with the same user credentials in SQL Management Studio
    In the Zabbix agent log I see
    [MSSQL] Creating new connection to "sqlserver://my-db-server", with user "zabbix" to database "", with CA certificate "", trust server certificate "", host name in certificate "" encrypt "", TLS min version ""
  • Brambo
    Senior Member
    • Jul 2023
    • 245

    #2
    I got a bit futher in my testing.
    When doing a query in the customquery.sql
    Code:
    @@VERSION
    I do get a response
    I change my SQL statement now with
    Code:
    USE TheDBname
    Select * from thetable
    This now errors in mssql: Database 'TheDBname' does not exist. Well it does exist, and again with the same username and password used SSMS i can perfectly navigate in this database and run the SQL statement.

    Comment

    Working...