Graph view filter

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
camiloclc
Posts: 2
Joined: Tue Aug 01, 2006 10:29 am

Graph view filter

Post by camiloclc »

My boss requested me to improve the filter for graph views, and he thought I should post it for the community.
I've created a very small function (not the most optimal, though) that improves the filter a bit.
I tested it under "List view' and 'Preview view'.
If you wish to add it to Cacti, no problem at all...
The code for this function is:

Code: Select all

function parse_filter($field, $filter) {
        if (!$filter) {
                return " " . $field . " like '%%%%'";
        }
        $farray = preg_split("/ /", $filter, -1, PREG_SPLIT_NO_EMPTY);
        if (sizeof($farray) == 0) {
                return " " . $field . " like '%%%%'";
        }
        $nfilter = "(";
        while (sizeof($farray) != 0) {
                $nfilter .= " " . $field . " like '%%" . array_shift($farray) . "%%'";
                if (sizeof($farray) != 0) {
                        $nfilter .= " and ";
                }
        }
        $nfilter .= ")";
        return $nfilter;
}
Just add it to graph_view.php and change lines 215 and 443,
From:

Code: Select all

and graph_templates_graph.title_cache like '%%" . $_REQUEST["filter"] . "%%'
To:

Code: Select all

and " . parse_filter("graph_templates_graph.title_cache", $_REQUEST["filter"]) . "
Just haven't checked if there are other places where I could use it...
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

Nice, can you submit this as a feature request at bugs.cacti.net

Also, have you though about possible security issues with injection and variable overwrites in this code?

I haven't inspected it closely to see.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

I would use a combination of explode and foreach instead but it serves the purpose of allowing multiple search combinations. Only lacks the feature that I miss so much on the internet:

What you have today Google: this that those
results in: this .or. that .or. those (if any terms selected)
results in this .and. that .and. those (if all terms selected)

What I used to have in the 80's: that .and. that .and. those
results in: this .and. that .and. those

You could also do things like:
Assume field names are:

Title == .ti.
Author == .au.
Publisher == .pb.
Date == .dt.
$ == Wildcard Character

$Johnson$ .au. .and. (O'Reily .pb. .or. Miff$ .pb.) .and. .dt. > 1997

I actually wrote a parser in 1990 to replicate this functionality in DBaseIV to repidly search online documents.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
camiloclc
Posts: 2
Joined: Tue Aug 01, 2006 10:29 am

Post by camiloclc »

Responding to rony, I haven't checked for security issues, hadn't even thought about it (hey, I'm still an intern, not even graduated from college yet!).... Guess there's no problem about it, for it's just used to make a select. The field parameter is completed by the Cacti code (where I changed it); in this case it'll always be "graph_templates_graph.title_cache". As for the filter parameter, it's just gonna search for those words in the DB...

But we don't have this kind of problem here in the company, accesses to Cacti are very restricted, just a few of our customers have it.

Now, The Witness, I just had to make something very simple, and I'm kinda short on time, this was just a side task I had to do... I chose to make a search where you can find any graph that includes all of the words you type, not this word or that word. Just needed to shorten the results as much as possible, without having to type a sentence you want to find (as it is done on the actual code). The results were satisfying, as it limited the results a lot whilst still finding what we needed.

But I'll make a request for better search filters... Thanks!!

PS: are you both part of the project??
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

First there was Ian Berry then Me, and then Tony. Now we have many more...

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests