grafana / grafana-zabbix

Zabbix plugin for Grafana dashboard
http://play.grafana-zabbix.org
Apache License 2.0
2.08k stars 458 forks source link

Support nested host groups #590

Open gustavoyanes opened 6 years ago

gustavoyanes commented 6 years ago

I'm submitting a ...

Hi it would be nice to be able to select variuos host groups on the triggers table or select a nested hostgroup weach doesnt show right now for example of nested hostgroup Latvia/Riga

Thanks Great work so far ....

alexanderzobnin commented 6 years ago

You can select multiple groups by using regex.

gustavoyanes commented 6 years ago

Thanks got it working i leave an example here if some one needs it. Lets say you have two groups Latvia and Riga and want to filter only the hosts of them you would write on the box /Latvia|Riga/ and it will give you the thes hosts of those groups only.

duuz commented 5 years ago

Problem with nested groups in variables, when i create a using "{*}" to get all groups isn't bring a first nest.

+1

anthonysomerset commented 5 years ago

to add my 2 cents here

i have nested host groups, in zabbix if i show all hosts in host group Parent/Child/1

i see all hosts in that and its sub groups .e.g. Parent/Child/1/Access

but in Grafana i see nothing because all of the hosts are in the lowest level hostgroup only, they are not directly in Parent/Child/1

i would at least loosely to expect behaviour similar to zabbix

i tried the workaround of /Latvia|Riga/ however this appears not to work because of the presense of / in the hostgroup name for nested, i also tried escaping and appears not to work - debugging if this is specifically because of that or my query is now large because its a LOT of devices (some 650)

isaqueprofeta commented 4 years ago

I was creating some scripts at work, and looking at the debug from Zabbix frontend, I found that it makes a query using search in the name with the forward-slash (which I'm using in my script):

Array
(
    [output] => Array
        (
            [0] => groupid
        )
    [search] => Array
        (
            [name] => Array
                (
                    [0] => MyRootGroup/
                )
        )
    [searchByAny] => 1
    [startSearch] => 1
)

Makin a little search at plugin code I found that you always get all groups:

https://github.com/alexanderzobnin/grafana-zabbix/blob/94c5059fb1d21f481678b9dc275a3533c39e7c71/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js#L106-L114

And then filters them using the defined regex:

https://github.com/alexanderzobnin/grafana-zabbix/blob/94c5059fb1d21f481678b9dc275a3533c39e7c71/src/datasource-zabbix/zabbix/zabbix.js#L166-L184

Maybe an if using a clause where the value is not a regex and contains a forward-slash can solve the issue?

I'm really sorry for not making up the code and sending a PR, but I'm not a JS/TS developer (more like a Python/PHP one), so at the moment I only can share my logic.

mike-sol commented 3 years ago

Any way I can buy someone some beer/coffee/whatever to implement this change?

isaqueprofeta commented 3 years ago

@mike-sol just try to put the full group if it's just one. If it's more, I'd just put it in a Regex like this: 'customer_a\/servers\/.*' For me, using this way works just fine.

HorselessName commented 1 year ago

I was creating some scripts at work, and looking at the debug from Zabbix frontend, I found that it makes a query using search in the name with the forward-slash (which I'm using in my script):

Array
(
    [output] => Array
        (
            [0] => groupid
        )
    [search] => Array
        (
            [name] => Array
                (
                    [0] => MyRootGroup/
                )
        )
    [searchByAny] => 1
    [startSearch] => 1
)

Makin a little search at plugin code I found that you always get all groups:

https://github.com/alexanderzobnin/grafana-zabbix/blob/94c5059fb1d21f481678b9dc275a3533c39e7c71/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js#L106-L114

And then filters them using the defined regex:

https://github.com/alexanderzobnin/grafana-zabbix/blob/94c5059fb1d21f481678b9dc275a3533c39e7c71/src/datasource-zabbix/zabbix/zabbix.js#L166-L184

Maybe an if using a clause where the value is not a regex and contains a forward-slash can solve the issue?

I'm really sorry for not making up the code and sending a PR, but I'm not a JS/TS developer (more like a Python/PHP one), so at the moment I only can share my logic.

I see. Does @alexanderzobnin allow us to do pull requests and implement this on the plugin or we can't deploy stuff for his plugin zabbix code? I am really needing this - Created the perfect architecture that can adapt to many hosts, clients and scenarios and all this using a single Dashboard - But the ONE thing preventing me to deploying is to filter using Groups. T_T

If only we had a option Comma Delinmted Groups with a AND operator... 😥

isaqueprofeta commented 1 year ago

I was creating some scripts at work, and looking at the debug from Zabbix frontend, I found that it makes a query using search in the name with the forward-slash (which I'm using in my script):

Array
(
    [output] => Array
        (
            [0] => groupid
        )
    [search] => Array
        (
            [name] => Array
                (
                    [0] => MyRootGroup/
                )
        )
    [searchByAny] => 1
    [startSearch] => 1
)

Makin a little search at plugin code I found that you always get all groups: https://github.com/alexanderzobnin/grafana-zabbix/blob/94c5059fb1d21f481678b9dc275a3533c39e7c71/src/datasource-zabbix/zabbix/connectors/zabbix_api/zabbixAPIConnector.js#L106-L114 And then filters them using the defined regex: https://github.com/alexanderzobnin/grafana-zabbix/blob/94c5059fb1d21f481678b9dc275a3533c39e7c71/src/datasource-zabbix/zabbix/zabbix.js#L166-L184 Maybe an if using a clause where the value is not a regex and contains a forward-slash can solve the issue? I'm really sorry for not making up the code and sending a PR, but I'm not a JS/TS developer (more like a Python/PHP one), so at the moment I only can share my logic.

I see. Does @alexanderzobnin allow us to do pull requests and implement this on the plugin or we can't deploy stuff for his plugin zabbix code? I am really needing this - Created the perfect architecture that can adapt to many hosts, clients and scenarios and all this using a single Dashboard - But the ONE thing preventing me to deploying is to filter using Groups. T_T

If only we had a option Comma Delinmted Groups with a AND operator... 😥

You can do nested groups using regex on group names. Like:

CUSTOMER-A/NETWORK/ROUTER
CUSTOMER-A/NETWORK/SWITCH
CUSTOMER-A/SERVERS/WINDOWS
CUSTOMER-A/SERVERS/LINUX

CUSTOMER-B/NETWORK/ROUTER
CUSTOMER-B/NETWORK/SWITCH
CUSTOMER-B/SERVERS/WINDOWS
CUSTOMER-B/SERVERS/LINUX

And some examples:

All CUSTOMER-A hosts: /CUSTOMER-A.*/
All CUSTOMER-A network devices: /CUSTOMER-A\/NETWORK\/.*/
All customers SERVERS: /.*SERVERS.*/

This issue should be closed. There's no need for more than the already existent regex support.

For something like "comma separated groups" , you can use pipes "|" on parenthesis regex expression for boolean logic. Like:

All CUSTOMER-A 'OR' B Linux Servers: /CUSTOMER-(A|B).*.\/LINUX/
isaqueprofeta commented 1 year ago

@alexanderzobnin you should just close the issue with the reference to regex support