mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-28 08:02:41 +02:00
Merge pull request #2798 from laf/issue-1698
Added the lookup of IP if device hostname is a hostname
This commit is contained in:
@@ -30,6 +30,13 @@ echo '<tr>
|
||||
<td>'.$device['sysName'].' </td>
|
||||
</tr>';
|
||||
|
||||
if ($ip = inet6_ntop($device['ip'])) {
|
||||
echo '<tr>
|
||||
<td>Resolved IP</td>
|
||||
<td>'.$ip.'</td>
|
||||
</tr>';
|
||||
}
|
||||
|
||||
if ($device['hardware']) {
|
||||
echo '<tr>
|
||||
<td>Hardware</td>
|
||||
|
||||
@@ -1041,6 +1041,20 @@ function version_info($remote=true) {
|
||||
|
||||
}//end version_info()
|
||||
|
||||
/**
|
||||
* Convert a MySQL binary v4 (4-byte) or v6 (16-byte) IP address to a printable string.
|
||||
* @param string $ip A binary string containing an IP address, as returned from MySQL's INET6_ATON function
|
||||
* @return string Empty if not valid.
|
||||
*/
|
||||
// Fuction is from http://uk3.php.net/manual/en/function.inet-ntop.php
|
||||
function inet6_ntop($ip) {
|
||||
$l = strlen($ip);
|
||||
if ($l == 4 or $l == 16) {
|
||||
return inet_ntop(pack('A' . $l, $ip));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert IP to use sysName
|
||||
* @param array device
|
||||
|
||||
@@ -1320,3 +1320,34 @@ function oxidized_reload_nodes() {
|
||||
curl_close($ch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform DNS lookup
|
||||
*
|
||||
* @param array $device Device array from database
|
||||
* @param string $type The type of record to lookup
|
||||
*
|
||||
* @return string ip
|
||||
*
|
||||
**/
|
||||
function dnslookup($device,$type=false,$return=false) {
|
||||
if (filter_var($device['hostname'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) == true || filter_var($device['hostname'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) == truee) {
|
||||
return '';
|
||||
}
|
||||
if (empty($type)) {
|
||||
// We are going to use the transport to work out the record type
|
||||
if ($device['transport'] == 'udp6' || $device['transport'] == 'tcp6') {
|
||||
$type = DNS_AAAA;
|
||||
$return = 'ipv6';
|
||||
}
|
||||
else {
|
||||
$type = DNS_A;
|
||||
$return = 'ip';
|
||||
}
|
||||
}
|
||||
if (empty($return)) {
|
||||
return '';
|
||||
}
|
||||
$record = dns_get_record($device['hostname'],$type);
|
||||
return $record[0][$return];
|
||||
}//end dnslookup
|
||||
|
||||
@@ -138,6 +138,14 @@ function poll_device($device, $options) {
|
||||
$device_start = microtime(true);
|
||||
// Start counting device poll time
|
||||
echo $device['hostname'].' '.$device['device_id'].' '.$device['os'].' ';
|
||||
$ip = dnslookup($device);
|
||||
|
||||
if (!empty($ip) && $ip != inet6_ntop($device['ip'])) {
|
||||
log_event('Device IP changed to '.$ip, $device, 'system');
|
||||
$db_ip = inet_pton($ip);
|
||||
dbUpdate(array('ip' => $db_ip), 'devices', 'device_id=?', array($device['device_id']));
|
||||
}
|
||||
|
||||
if ($config['os'][$device['os']]['group']) {
|
||||
$device['os_group'] = $config['os'][$device['os']]['group'];
|
||||
echo '('.$device['os_group'].')';
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ DROP TABLE IF EXISTS `component`;
|
||||
CREATE TABLE `component` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID for each component, unique index', `device_id` int(11) unsigned NOT NULL COMMENT 'device_id from the devices table', `type` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'name from the component_type table', `label` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Display label for the component', `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'The status of the component, retreived from the device', `disabled` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Should this component be polled', `ignore` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Should this component be alerted on', `error` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Error message if in Alert state', PRIMARY KEY (`id`), KEY `device` (`device_id`), KEY `type` (`type`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='components attached to a device.';
|
||||
DROP TABLE IF EXISTS `component_prefs`;
|
||||
CREATE TABLE `component_prefs` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID for each entry', `component` int(11) unsigned NOT NULL COMMENT 'id from the component table', `attribute` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Attribute for the Component', `value` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Value for the Component', PRIMARY KEY (`id`), KEY `component` (`component`), CONSTRAINT `component_prefs_ibfk_1` FOREIGN KEY (`component`) REFERENCES `component` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='AV Pairs for each component';
|
||||
INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('alert.macros.rule.component','(%component.disabled = 0 && %component.ignore = 0)','(%component.disabled = 0 && %component.ignore = 0)','Component that isn\'t disabled or ignored','alerting',0,'macros',0,'1','0'),('alert.macros.rule.component_normal','(%component.status = 1 && %macros.component)','(%component.status = 1 && %macros.component)','Component that is in a normal state','alerting',0,'macros',0,'1','0'),('alert.macros.rule.component_alert','(%component.status = 0 && %macros.component)','(%component.status = 0 && %macros.component)','Component that alerting','alerting',0,'macros',0,'1','0');
|
||||
INSERT INTO `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) VALUES ('alert.macros.rule.component','(%component.disabled = 0 && %component.ignore = 0)','(%component.disabled = 0 && %component.ignore = 0)','Component that isn\'t disabled or ignored','alerting',0,'macros',0,'1','0'),('alert.macros.rule.component_normal','(%component.status = 1 && %macros.component)','(%component.status = 1 && %macros.component)','Component that is in a normal state','alerting',0,'macros',0,'1','0'),('alert.macros.rule.component_alert','(%component.status = 0 && %macros.component)','(%component.status = 0 && %macros.component)','Component that alerting','alerting',0,'macros',0,'1','0');
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE `devices` ADD `ip` VARBINARY( 16 ) NOT NULL AFTER `sysName` ;
|
||||
Reference in New Issue
Block a user