Changing hostname of devices on the net.

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
sawj83
Posts: 1
Joined: Fri Nov 22, 2024 1:37 am

Changing hostname of devices on the net.

Post by sawj83 »

Hello.
I propose to add functionality for changing the IP address of devices previously added through automation.
For example, there is a device added via automation. Someone on the network changed the IP address of this device but did not change the name in the settings. Our discovery (if you look at the debug) discards these devices because the name is already in the database.

I suggest doing something like this in poller_automation.php to automaticaly change IP address of the host after 1 day not accessibility:

Code: Select all

if ($network['same_sysname'] == '') {
	$isDuplicateSysNameDiscovery = db_fetch_cell_prepared('SELECT COUNT(*)
			FROM automation_devices
			WHERE network_id = ?
			AND sysName != ""
			AND ip != ?
			AND sysName = ?',
			array($network_id, $device['ip_address'], $snmp_sysName));

	$isDuplicateSysNameCacti = db_fetch_cell_prepared('SELECT COUNT(*)
			FROM host
			WHERE snmp_sysName = ?
			AND hostname != ?',
			array($snmp_sysName, $device['ip_address']));

	if ($isDuplicateSysNameDiscovery || $isDuplicateSysNameCacti) {
			$old_host_id = db_fetch_cell_prepared('SELECT h.id
					FROM host h
					WHERE h.snmp_sysName = ?
					AND h.hostname != ?
					AND h.status = 1 AND h.status_event_count * ( IFNULL( (SELECT value FROM settings WHERE name = \'poller_interval\' LIMIT 1), 300 ) ) > 1*24*60*60',				   
					array($snmp_sysName, $device['ip_address']));
			if ( $old_host_id ) {
					db_execute_prepared('UPDATE host
							SET hostname = ?
							WHERE id = ?',
							array($device['ip_address'], $old_host_id));
										
					cacti_log(sprintf("INFO: Old device hostname not accesseble. Changeing hostname address to new - '" .$device['ip_address']. "'" ), true, 'AUTOM8');
			}
						
			automation_debug(", Skipping sysName '" . $snmp_sysName . "' already Discovered!\n");
			markIPDone($device['ip_address'], $network_id);
			continue;
	}
}
User avatar
macan
Cacti Guru User
Posts: 1137
Joined: Tue Mar 18, 2008 2:30 am
Location: Czech

Re: Changing hostname of devices on the net.

Post by macan »

Please add your feautre request here:
https://github.com/Cacti/cacti/issues
Let the Cacti grow!
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Changing hostname of devices on the net.

Post by TheWitness »

This looks pretty close to the sysname mapping feature via snmp.
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 0 guests