Enhanced /cli/add_graphs.php to be less specific

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
Deviloper
Cacti User
Posts: 256
Joined: Tue Jul 07, 2009 8:03 am

Enhanced /cli/add_graphs.php to be less specific

Post by Deviloper »

HI,

the /cli/add_graphs.php script as a "Feature" that allows to specify to add only graphs which has a give value for a given SNMP-Field.

This leads into unnecessary trouble auto-importing graphs for devices which do not have a specific value like Up/Down, but has an unguessable or unforcastable Value like the Temperature Sensor IDs or something like that.

The Fix:
Therefor the Check in Line 329 should be changed to "any value" or a userspecified Regexp allowing the User giving specific details which Item should be graphed and which not.

OLD:
328 if ($dsGraph["snmpValue"] != "") {
329 if(!isset($snmpValues[$dsGraph["snmpValue"]])) {
330 echo "ERROR: Unknown snmp-value for field " . $dsGraph["snmpField"] . " - " . $dsGraph["snmpValue"] . "\n";

331 echo "Try --snmp-field=" . $dsGraph["snmpField"] . " --list-snmp-values\n";

332 exit(1);
333 }
334 }

NEW:
if ($dsGraph["snmpValue"] != "") {
329 $muster = "/" . $dsGraph["snmpValue"] . "/";
330 $x = 0;
331 foreach ($snmpValues as $sv => $ss) {
332 if ( preg_match($muster, $sv)) {
333 $x = 1;
334 }
335 }
336 if(!isset($snmpValues[$dsGraph["snmpValue"]]) and ! $x) {
337 echo "ERROR: Unknown snmp-value for field " . $dsGraph["snmpField"] . " - " . $dsGraph["snmpValue"] . "\n";
338 echo "Try --snmp-field=" . $dsGraph["snmpField"] . " --list-snmp-values\n";
339 exit(1);
340 }
341 }



This Enables:
Users are able to automaticly import devices by given RegExes to match Descriptions, Names or Types... which would be a BIG enhancement for automatic cactis backend.

Another Problem:
Also CACTIs add_graphs.php should be able adding graphs for Nodes which a currently offline.
Last edited by Deviloper on Mon Aug 17, 2009 4:58 am, edited 2 times in total.
Deviloper
Cacti User
Posts: 256
Joined: Tue Jul 07, 2009 8:03 am

Post by Deviloper »

Additionaly you have to change the SQL Statement around line 480!

#################################################
$snmp_indexes = db_fetch_assoc("SELECT snmp_index
FROM host_snmp_cache
WHERE host_id=" . $hostId . "
AND snmp_query_id=" . $dsGraph["snmpQueryId"] . "
AND field_name='" . $dsGraph["snmpField"] . "'
AND field_value REGEXP '" . $dsGraph["snmpValue"] . "'"); ################################################

Replacing the last line of the statement with REGEXP (mostly perl-like)
###############################################
AND field_value='" . $dsGraph["snmpValue"] . "'");
###############################################
With
###############################################
AND field_value REGEXP '" . $dsGraph["snmpValue"] . "'");
###############################################


Instead of nearly useless junk, you now got a working tool, that allows a BIG BIG BIG amount of automisation.

Only changing a bunch of php-code....

At this place I have to thank the developers for the gigantic in code documentation.... NOT!

BTW:
Until tomorrow morning I never did anything with php....
Deviloper
Cacti User
Posts: 256
Joined: Tue Jul 07, 2009 8:03 am

Post by Deviloper »

The File:
allows the use of php/mysql/perl compatible (only a subset of all the fine things you would find in perl and mysql regex-machines, because of php) as --SNMP-Value= argument in form of [[:digit:]] or [0123456789] or ^If ...
Attachments
enhanced_add_graphs.php.txt
(18.74 KiB) Downloaded 395 times
User avatar
TheWitness
Developer
Posts: 17059
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

Bug report for Feature please.

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 2 guests