Cacti / cacti

Cacti ™
http://www.cacti.net
GNU General Public License v2.0
1.63k stars 404 forks source link

Input Field with variable hostname not automatically provisioned #1661

Closed emeidi closed 6 years ago

emeidi commented 6 years ago

Cacti 1.1.36

Hi Cacti Community

Although I specified an Input Field for a new Data Input Method ...

screen shot 2018-06-07 at 10 37 24

... and assigned it the device variable hostname ...

screen shot 2018-06-07 at 10 34 08

... the IP address was not automatically passed to the script by Cacti.

I deleted the graph and data sources created with this template and activated the checkbox in the Data Source template:

screen shot 2018-06-07 at 10 39 34

Then I recreated the graphs again, for each device.

Now I have to provide the IP address of each device when creating the graphs (which is silly, because Cacti already knows this attribute), but then at least the value gets properly passed to the script.

What am I doing wrong?

Thank you & best regards Mario

SergejLT commented 6 years ago

It is opposite. You need to untick in Custom Data "IP Adress of Server". Then ds will take IP of your hostname automatically.

emeidi commented 6 years ago

@SergejLT The checkbox was ORIGINALLY unticked but it would not provide the variable associated with the device to the script.

That‘s why I had to enable it and to provide the IP by myself for every device. Bummer.

netniV commented 6 years ago

What does the poller cache have for that device? Please provide a copy of it as it shows what it would try and send to the script. Also, it should be noted that you used the field hostname, not ip but as long as that's what you've entered in the hostname field, it should work.

You may also try rebuilding the poller cache.

cigamit commented 6 years ago

@SergejLT was correct, you should only tick that box if you want to overwrite a setting. For the ip address of the hostname for example, you should always keep it unticked.

eschoeller commented 6 years ago

Funny, I am having some problems with this right now myself. For whatever reason the 'hostname' attribute is simply blank no matter what I've tried. Running 1.1.38 and building a new template. The debug output shows this: 2018/06/26 21:30:47 - SPINE: Poller[1] Device[8] TH[1] DS[84] SCRIPT: perl /cacti/cacti-1.1.38-test/scripts/query_cellwatch.pl --hostname --temperature, output: U And I have the data input method setup like this: image image No idea what is causing this problem. I've rebuilt the poller cache plenty of times. I still get this: image

eschoeller commented 6 years ago

And I have a valid IP address set in the "hostname" field for the device. I've tried with having SNMP enabled, and disabled. No difference. I've deleted and added the host back in several times. If I change the data input method to use '--hostname 1.2.3.4' it works just fine. It's that the \ directive is getting passed through as just a ' '.

netniV commented 6 years ago

Does the standard Unix - Ping Host data query work with this host? That also specifies a hostname field as a parameter.

eschoeller commented 6 years ago

Yes, the Unix - Ping Host works. But there is an odd bug here. I started to replace parts of the Unix - Ping Host data input method to match my own data input method I was trying to create, and it mostly worked - until I changed "\" to "\". Suddenly the Name of the data input method was changed to the Friendly Name of the first input field! image And now it is broken. Same as the data input method I had originally created. So I have gone back and decided to recreate the Data Input Method again. I am seeing this same strange behavior ... as I add more Output Fields the Name of the Data Input Method keeps changing to match the Friendly Name of the last Output Field I entered: image But now, finally after recreating the data input method (and not making any mistakes along the way), changing the data input method name back to what it should be after adding all the output fields, then re-associating it with the necessary data sources (which had to be disassociated first in order to delete the bad data input method) I have it working as expected. Moral of the story, you can't make any mistakes and great care and attention is required to work around this bug. I just don't know exactly what it is. The renaming of the Data Input Method is a good first start.

eschoeller commented 6 years ago

And I would bet money that if I change <ip> to <hostname> (which is I believe what I did originally to end up here) the whole thing would blow up again.

netniV commented 6 years ago

Interesting analysis. On the field front, the creation of an input field shouldn’t be auto assigning a name. However creation of an output field does as it takes the first that hasn’t been used and sets it accordingly.

Not sure if that was something I did for 1.2 or 1.1.38

I’ll review what you’ve written later and see if I can spot anything.

netniV commented 6 years ago

Oh and if you edit your post, you can use single back ticks around the code so it does not then think you are trying to insert html tags.

eschoeller commented 6 years ago

Oh, and this is happening firefox, but not in chrome.

netniV commented 6 years ago

Hmm, in that case, I wonder if Firefox is seeing the HTMl fields and doing something with it. Lets check what you have in the database.

[10:33:07] (cacti) cacti1> select * from data_input_fields where data_name = 'hostname';
+----+----------------------------------+---------------+------------+-----------+--------------+------------+----------+-----------+--------------+-------------+
| id | hash                             | data_input_id | name       | data_name | input_output | update_rra | sequence | type_code | regexp_match | allow_nulls |
+----+----------------------------------+---------------+------------+-----------+--------------+------------+----------+-----------+--------------+-------------+
| 29 | 5fbadb91ad66f203463c1187fe7bd9d5 |            10 | IP Address | hostname  | in           |            |        1 | hostname  |              |             |
+----+----------------------------------+---------------+------------+-----------+--------------+------------+----------+-----------+--------------+-------------+
1 row in set (0.00 sec)

[10:33:48] (cacti) cacti1> select * from data_input where id in (10);
+----+----------------------------------+------------------+----------------------------------------------+---------+
| id | hash                             | name             | input_string                                 | type_id |
+----+----------------------------------+------------------+----------------------------------------------+---------+
| 10 | 8bd153aeb06e3ff89efc73f35849a7a0 | Unix - Ping Host | perl <path_cacti>/scripts/ping.pl <hostname> |       1 |
+----+----------------------------------+------------------+----------------------------------------------+---------+
1 row in set (0.00 sec)

In the second query, the (10) is a comma separated list of ids. So if you had three rows from the first query of 1, 40 and 52, you would replace (10) with (1, 40, 52). If you do the same queries with both browsers, see if there is any change. The typecode field of the data_input_field is the important part as that says it is using the hostname (if I remember correctly).

netniV commented 6 years ago

Did you manage to take a look at this @eschoeller ?

netniV commented 6 years ago

Closed due to no further response.

eschoeller commented 6 years ago

I am just getting back from being on vacation. I may make an effort to wrap my head around this again and respond to your post on 7/1. My apologies for dropping off the radar!

krishnachaitanya7 commented 4 years ago

@eschoeller asked me to work on this. Here is the solution for guys who will be stumbling upon this link in the future: First In the (Management -> Devices -> Your Custom Device Name)Device, have the hostname IP correctly indicated image In my case, it's localhost (127.0.0.1) as shown in the above pic.

Next in the Data Input Method (Data Collection -> Data Input Methods -> Your custom Data Input Method -> Click on one of the input methods)

In the "Special Type Code" field input "hostname" as shown in the below pic. The input field name is "IP". image Now in the Data Sources (Templates -> Data Sources -> Your Custom Data Source Name -> Input Method) data input method, keep the data input method blank image Which in my case it is "IP" is kept blank.

Save all and re-check the poller cache. The hostname is detected and passed to your script correctly.