Test different hostname formats in Oxidized integration #3617

merged 5 commits into from Jun 10, 2016


None yet

3 participants

wiad commented Jun 7, 2016

Solves issue librenms/librenms#3615

This commit will retry requests to Oxidized with new hostname if first one fail. If the original hostname contains domain suffix (crudely checked by looking for a dot (.) in hostname) the domain suffix is stripped. If the original hostname does not contain a domain suffix and the variable '$config['mydomain']' is set, the domain suffix is added to the hostname.

@murrant murrant commented on an outdated diff Jun 9, 2016
// fetch info about the node and then a list of versions for that node
- $node_info = json_decode(file_get_contents($config['oxidized']['url'].'/node/show/'.$device['hostname'].'?format=json'), true);
+ $node_info = json_decode(file_get_contents($config['oxidized']['url'].'/node/show/'.$oxidized_hostname.'?format=json'), true);
+ // Try other hostname format if Oxidized request failed
+ if (! $node_info) {
+ // Adjust hostname based on whether domain was already in it or not
+ if (strpos($oxidized_hostname, '.') !== false) {
+ // Use short name
+ $oxidized_hostname = strtok($device['hostname'], '.');
+ } else {
+ // Add domain if $config['mydomain'] is set
+ $oxidized_hostname = $config['mydomain'] ? $device['hostname'].'.'.$config['mydomain'] : $oxidized_hostname;
murrant Jun 9, 2016 Contributor

this would be a little more clear if you used something like this:

} elseif($config['mydomain']) {
    $oxidized_hostname = $device['hostname'].'.'.$config['mydomain'];
laf commented Jun 9, 2016 edited

Ok looks good to me except for formatting.

We use four spaces for indentation and } else { should be

else {

Same with elseif, etc.

@murrant murrant merged commit 8b9e68d into librenms:master Jun 10, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment