Skip to content
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

Can't create more than one graph with add_graphs.php from one template #2202

Closed
pweibbre opened this issue Dec 5, 2018 · 4 comments
Closed

Comments

@pweibbre
Copy link

pweibbre commented Dec 5, 2018

Hi,

i'm using cacti 1.1.38

i create a graph from commandline with add_graps.php:

php add_graphs.php --graph-type=cg --graph-template-id=138 --host-id=14 --graph-title="A/T WLS JMS Queue: JMS_EILOG" --input-fields="117:queuename=JMS_EILOG"

when i try to create a second graph from the same template ( multiple instances is set to true) it fails with this error on commandline:

php add_graphs.php --graph-type=cg --graph-template-id=138 --host-id=14 --graph-title="A/T WLS JMS Queue: HDSQueue" --input-fields="117:queuename=HDSQueue"
NOTE: Not Adding Graph - this graph already exists - graph-id: (1671) - data-source-id: (1671)

in the webinterface i can create hundreds of graphs on the same host of this template with different settings for input field "queuename"

@pweibbre
Copy link
Author

pweibbre commented Dec 5, 2018

I think that is related to issue #2201
is the script only lookink if there is a graph already existing with the same title for this host?

@netniV
Copy link
Member

netniV commented Dec 5, 2018

So, on a CG graph, the only check performed is the following:

$existsAlready = db_fetch_cell_prepared('SELECT id
                        FROM graph_local
                        WHERE graph_template_id = ?
                        AND host_id = ?', array($template_id, $host_id));

So, if you have already used the graph template on that host, it prevents you from using it again. You can use the --force option to bypass this on a 'cg' add, though I do wonder if we should be patching it to check the multiple column of the template using something like:

diff --git a/cli/add_graphs.php b/cli/add_graphs.php
index 9a16891b..c966a577 100644
--- a/cli/add_graphs.php
+++ b/cli/add_graphs.php
@@ -550,10 +550,13 @@ if (cacti_sizeof($parms)) {
        $returnArray = array();

        if ($graph_type == 'cg') {
-               $existsAlready = db_fetch_cell_prepared('SELECT id
-                       FROM graph_local
+               $existsAlready = db_fetch_cell_prepared('SELECT gl.id
+                       FROM graph_local gl
+                       INNER JOIN graph_templates gt on gt.id = gl.graph_template_id
                        WHERE graph_template_id = ?
-                       AND host_id = ?', array($template_id, $host_id));
+                       AND host_id = ?
+                       AND multiple = \'\'',
+                       array($template_id, $host_id));

                if ((isset($existsAlready)) &&
                        ($existsAlready > 0) &&
@@ -646,12 +649,14 @@ if (cacti_sizeof($parms)) {
                        foreach ($snmp_indexes as $snmp_index) {
                                $snmp_query_array['snmp_index'] = $snmp_index['snmp_index'];

-                               $existsAlready = db_fetch_cell_prepared('SELECT id
-                                       FROM graph_local
+                               $existsAlready = db_fetch_cell_prepared('SELECT gl.id
+                                       FROM graph_local gl
+                                       INNER JOIN graph_templates on gt.id = gl.graph_template_id
                                        WHERE graph_template_id = ?
                                        AND host_id = ?
                                        AND snmp_query_id = ?
-                                       AND snmp_index = ?',
+                                       AND snmp_index = ?
+                                       AND multiple = \'\'',
                                        array($template_id, $host_id, $dsGraph['snmpQueryId'], $snmp_query_array['snmp_index']));

                                if (isset($existsAlready) && $existsAlready > 0) {

@pweibbre
Copy link
Author

pweibbre commented Dec 5, 2018

Ok, thats fine for me.
i thought, why i should use --force when multiple ist already set to on.

@pweibbre pweibbre closed this as completed Dec 5, 2018
netniV added a commit that referenced this issue Dec 5, 2018
@netniV
Copy link
Member

netniV commented Dec 5, 2018

I have now made the above change to the 1.2 dev code.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants