New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add_graphs.php with multiples --snmp-field and --snmp-value #1306
Comments
Looking at the code, snmp-field, snmp-value-regex and snmp-value are all designed to be multi value case 'snmp-field':
$dsGraph['snmpField'][] = $value;
break;
case 'snmp-value-regex':
$dsGraph['snmpValueRegex'][] = $value;
break;
case 'snmp-value':
$dsGraph['snmpValue'][] = $value;
break; The problem here is not that you are trying to add multiples but more that it doesn't return that field when queried. There is a problem with the output of the error though in that it doesn't take into account it's an array. Hence you are seeing 'Array (value)' rather than 'Name (Value)' What I would do is try and grab a copy of the SQL actually being used at around line 615 of add_graphs.php: file_put_contents('/tmp/add_graphs.sql',$req,FILE_APPEND); <-- Add this
$snmp_indexes = db_fetch_assoc($req); Once you have the SQL in question, copy and paste that into MySQL and you'll find it is returning nothing. Paste it here so I can compare what you input vs what was being looked up. Don't forget to take the above line back out once you're done testing or it'll keep writing to that file. |
Ok, I used this code.
In add_graph.sql:
I used code in at around line 605 of add_graphs.php
Array in the Array ? |
Is:
Should:
|
What that original bit of coding should be doing is getting the value $dsGraph['index'] and then [] means to add an element to the array. What I am curious about here, what is the value of $value when it is adding it. If you change it the way you suggest, that would only have a single value for all instances. |
I've improved the code a bit :
and 686-693:
Result:
I know, not a pretty code, but graphs is added to Cacti. |
Can you create a diff between the original and your current version of the code? I can use that to generate a pull request then. |
OK, thanks for your change. However, I think the problem is actually solved by a more simple change. On any field that can be an array, we should check if the parameter is an array and if not, make it an array. Then we remove the [] on the left hand side of the assignment. The issue is that getopts returns a single value as a singe value and multiple values as an array. |
Can you test the PR I have pushed out to see if it works for you. |
I saw a few issues as well, that may be unrelated. I'll merge one of the two and then take a second look. |
I tested - Works. Thanks. |
Hello, I have this issue when i try to use reg with another snmp-field
ERROR: Could not find one of more snmp-fields ifSpeed,ifOperStatus with values (Up) for host-id 9 BUT
Graph Added - graph-id: (1782) - data-source-ids: (1778, 1778) -- |
My mistake, both field and value must be regex. -- |
Hello,
I would like to use multiples --snmp-field:
or
or
snmp-fields is fine:
Single one --snmp-field is OK:
Jacek
The text was updated successfully, but these errors were encountered: