Hi guys,
decided to create advanced filtering in the dashboard for printers by vendor and model.
- I have grafana integrated with zabbix (PostgreSQL DB).
- I define a variable “prtDeviceVendor” that contains the names of the printer vendors in string form: HP, Lexmark, Brother, etc. Data for the variable is taken from the Zabbix database.
- Then I define the second variable (prtDeviceModel) for a SQL query that finds a list of printer models by the given parameter:
SELECT distinct on (model) history_str.value as model FROM hosts as id2 LEFT JOIN items ON id2.hostid = items.hostid LEFT JOIN history_str ON history_str.itemid = items.itemid RIGHT JOIN ( SELECT distinct hosts.hostid, value as vendor FROM hosts LEFT JOIN items ON hosts.hostid = items.hostid LEFT JOIN history_str ON history_str.itemid = items.itemid WHERE items.key_ like 'prtDeviceVendor' AND value like '$ {prtDeviceVendor: raw}' ) AS id1 ON id2.hostid = id1.hostid WHERE items.key_ like 'prtDeviceModel' and history_str.value is not null
This request works great! And returns me a list of printer models for the selected vendor!
4. I am trying to add the All option to the prtDeviceVendor variable. I define it as “%” (Probably not an optimal solution, but I haven’t come up with a better solution yet).
And it works - I get a list of all printers for all models and all vendors. But the previously obtained Brothher, Lexmark and etc. stop working. I get this error:
Templating
Template variables could not be initialized: pq: syntax error at or near “Brother”
(prtDeviceVendor values are displayed insted of Brother): Brother,Lexmark,HP and etc.
I tried different Advanced variable format options but it not help.
It feels like grafana is doing data preprocessing. But I don’t understand how I can fix it!!
Help as much as you can!
- Where can I see the actual SQL query that grafana is doing?
- Maybe my solution is not optimal and i can filter data from zabbix by several parameters in another way?
I would be grateful for any advice!