batch CHANGE of host ip adresses

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
choefing
Posts: 29
Joined: Tue May 04, 2010 4:47 am

batch CHANGE of host ip adresses

Post by choefing »

Hi,

(edit: plain old 0.8.7b)

we have a dedicated Cacti instance to provide customers with the "Advanced ping graphs". Unfortunately there is quite a lot of add/delete/changes for the remote hosts, so I wrote a script using cli to update the devices. It simply reads from a txt file holding "hostname - ip".

Within the script I issue the command:

Code: Select all

`php cli/add_device.php --description=$hostname --ip=$ipaddress --template=$template --version=2 --community=$community  --avail="ping" --ping_method="icmp"`
This will also CHANGE the IP address of the device in case it already exists, but this is not reflected in the poller cache, even rebuilding the poller cache via webgui or cli doesn't help here, it still shows the OLD ip address in the query.
Additionally to the device creation or change I'll add a graph for it which is either prompted by "success" or "graph exists" (for now never got any errors so far).

Code: Select all

`php cli/add_graphs.php --graph-type=cg --graph-template-id=$graphtemplate --host-id=$cacti_host_id --graph-title="$hostname - Advanced Ping"`;
Poller cache after changing IP using my script from 1.2.3.4 to 1.2.3.5
Script Server: /var/www/html/cacti7b/scripts/ss_fping.php ss_fping 1.2.3.4 5 ICMP
RRD: /var/www/html/cacti7b/rra/hostname_loss_7595.rrd
When I issue the IP change within the webgui directly (no poller cache rebuild neccessary):
Script Server: /var/www/html/cacti7b/scripts/ss_fping.php ss_fping 1.2.3.5 5 ICMP
RRD: /var/www/html/cacti7b/rra/hostname_loss_7595.rrd
So it seems "edit" the host does apply some more "magic" which is not covered by my script. Can someone shed a light what I'm missing ?

Thanks
Chris
jantram
Posts: 12
Joined: Mon Aug 27, 2012 1:25 pm

Re: batch CHANGE of host ip adresses

Post by jantram »

I was looking at the database tables yesterday. I think the magic you are talking about is an update of the poller_item table, updating hostname, matching on host_id.

I found a couple of items in this table which seemed to be broken ( wrong hostname information ), when I opened the host and re-saved on the edit host page, all was repaired.

There are likely better ways to do this change - the functions in cacti can be called (as from a plugin) so you may be able to automate that update. Or, update the poller_item table based on the host table after your script runs.
choefing
Posts: 29
Joined: Tue May 04, 2010 4:47 am

Re: batch CHANGE of host ip adresses

Post by choefing »

Jantram,

thanks for you feedback, but I'm afraid you lost me in between.
What is this plugins you talk about ? Which better way you can imagine ? Unfortunately I'm just the guy who has to do that, w/o any expertise in php.

My script is a simple perl script parsing the text file for values and execute the php cli files provided by cacti.
With update poller table you mean manually change the Cacti DB with the value it "should" have and then the "rebuild poller cache" should fetch those information properly ?

Thx
Chris
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests