neuralfraud / grafana-prtg

A PRTG Datasource plugin for Grafana
180 stars 75 forks source link

How to return only a subset of Hosts? #154

Open Ginolard opened 4 years ago

Ginolard commented 4 years ago

For example, we have about 100 file servers with a Disk Space sensor. The channels in that sensor are for all disks.

However, the file servers are actually in several groups called Windows Servers (one group per remote probe).

So, if I select Windows Servers as the group in a dashboard, naturally, I get every Windows server in every group called Windows Servers. How can I return on the file servers (e..g. ones called FSVxxxx)?

angela-d commented 4 years ago

Make a sub-group in PRTG under Windows Servers > Move all FSVxxxx machines (in the device window, click the chevron in the upper-right corner and a Move to Group link is in the context menu) to it and (in Grafana) select the sub-group (as the Group), instead of Windows Servers.

I didn't test it, but presumably if you're in a situation where you want to pull all Windows Servers, (selecting 'Windows Servers') would select those in the sub-group, as well. So the sub-group should only affect the finer sorting.

Ginolard commented 4 years ago

Make a sub-group in PRTG under Windows Servers > Move all FSVxxxx machines (in the device window, click the chevron in the upper-right corner and a Move to Group link is in the context menu) to it and (in Grafana) select the sub-group (as the Group), instead of Windows Servers.

I didn't test it, but presumably if you're in a situation where you want to pull all Windows Servers, (selecting 'Windows Servers') would select those in the sub-group, as well. So the sub-group should only affect the finer sorting.

I'm not sure that's the best approach for us. Each remote site has a remote probe and each remote site has just 5 servers (with the file server being just one of them). As I understand it, if I move all the file servers under another remote probe's group it will be that remote probe that tries to scan them

So, for example, it looks like this

Root
--HQ
----Windows Servers
----Hypervisors
--RemoteProbe1
----Windows Servers
----Hypervisors
--RemoteProbe2
----Windows Servers
----Hypervisors

I don't think we can move the file servers in the WIndows Servers group to a single sub-group under a single Windows Server group because they're assigned to each remote probe

angela-d commented 4 years ago

This was a bit of a head scratcher for me, so it piqued my interest.

I suspect this is what you're after: filtername

Give these values a try:

In the Query window: Query Mode: Metrics Group: (the group your Windows machines are in) - Windows Servers, based on your example Host: /FSV/ Sensor: /Disk Free\: C:\\ Label */ Channel: Free Space

You could even drill it down further with the tags property, too, if the above options aren't exactly filtering as-expected.

Ginolard commented 4 years ago

Well how about that!!? That's perfect, thanks!

Our disk sensors are just called Disk Free and we have seperate channels per disk so I can just use DISK FREE for the Sensor and Free Space C: for the Channel

Ginolard commented 4 years ago

Now I need to see if there's a way to return only the results of the Disk Space sensor where Free Space is below, say, 10%

Not sure that's possible though

angela-d commented 4 years ago

It looks doable with the multiple object filtering: https://www.paessler.com/manuals/prtg/live_multiple_object_property_status - specifically filter_xyz=@below(40) but I haven't gotten it in a syntax that works, yet. (Under query > Raw)

I can get the plugin to return the tagged test items (which is only revealed in the query inspector), but its not putting them into the chart and I'm not sure why.. I think I'm missing some expected parameters in the query string field.

When I have more time I will take a stab at it again.

Ginolard commented 4 years ago

I can get this far

content=sensors&columns=device,sensor,status,lastvalue,lastvalue_raw&filter_sensor=Disk Free&filter_lastvalue_raw=@below(10)

But, from the PRTG documentation it says that multiple filters performs a logical OR and not a logical AND. GRrrrr.......!

angela-d commented 4 years ago

PRTG documentation it says that multiple filters performs a logical OR and not a logical AND

What a bizarre limitation!!

When I try the API direct (outside of the plugin) I run into the same hurdle.

I got my tests to populate under "Table" view, but it still doesn't filter by both sensor and value. Wondering if this might be a limitation of the API.

Assuming so, I would then draw focus to adding a condition to the javascript core of the plugin, maybe an additional input field for value filtering? The data would still be there, but if you pass a condition before the dashboard loads, it would 'hide' it from view (theoretically).

I haven't explored this area of the plugin that much, but I'm hoping to make some time to this weekend, this is a very challenging issue and I'm interested to see how it could be done!

Ginolard commented 4 years ago

It's a pretty stupid limitation if so from Paessler. It surely couldn't be that hard to implement something that lets you do an AND or an OR.

angela-d commented 4 years ago

It doesn't appear possible to unset the variables without triggering undefined collisions.

However, you may be able to overwrite or manipulate the data if you want to get creative.

Here's a working example from /var/lib/grafana/plugins/jasonlashua-prtg-datasource/dist/datasource.js

Inside the var datapoints = _.map(history, function (hist) {..} function for queryMetrics (tested in Bar Gauge using the Metrics query):

Beneath

var value = hist.value;

Append the following test code:

                    if (hist.value <40) {
                      hist.value = false;
                      value = false;
                      alias = false;
                      console.log('TRIGGER' + alias);
                    }

You'll see the graph "break": testpanel

and if you open your browser's console, you'll see the TRIGGER message with alias' rewritten value, attached (for records affected by that condition).

If you want to do some additional logic to detect the series array placement before the values are set, you could probably delete the result more cleanly, than setting them to false (not tested.. I was looking for something easy to do and that method would definitely not be in that realm)

Time permitting, I'll circle back to this after I dig around for why the graphs are breaking while a device is paused.. perhaps that'll turn on some light bulbs for other ways to manipulate the records.

If you're able to get anywhere with it, please do share!