albertodonato / query-exporter

Export Prometheus metrics from SQL queries
GNU General Public License v3.0
447 stars 103 forks source link

using parameters in queries fails #131

Closed cooperspencer closed 2 years ago

cooperspencer commented 2 years ago

Hi,

is it possible to create a query like this? I tried to run it but I end up getting an error message.

    sql: >
      SELECT ':servers__name' as MACHINE, ':usernames__name' as USERNAME, COUNT(*) AS test
      WHERE MACHINE like ':servers__name%'
      AND USERNAME like ':usernames__name%'
    parameters:
      servers:
        - name: server1
        - name: server2
      usernames:
        - name: user1
        - name: user2

The error I get is this:

2022-09-08 17:50:25,182 - ERROR - query-exporter - query "test[params3]" on database "DB" failed: (cx_Oracle.DatabaseError) ORA-01036: illegal variable name/number

Am I doing something wrong with the parameters? Because if I put the values into the queries it works fine.

albertodonato commented 2 years ago

Have you tried using just like :servers_name and setting the paramter to server1% and server2%?

cooperspencer commented 2 years ago

Thanks, that solved my issue.

servers:
- name: server1
  query: server1%