From c57f60644d4dc5448164d3794c2a05296b5c9381 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 17 Aug 2018 12:17:45 -0500 Subject: [PATCH] Add a check for a failed dns query in get_astext() (#9020) DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply `, i.e `./scripts/github-apply 5926` --- includes/functions.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 73cc107232..2bd660396b 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -968,21 +968,25 @@ function snmp2ipv6($ipv6_snmp) function get_astext($asn) { - global $config,$cache; + global $cache; - if (isset($config['astext'][$asn])) { - return $config['astext'][$asn]; - } else { - if (isset($cache['astext'][$asn])) { - return $cache['astext'][$asn]; - } else { - $result = dns_get_record("AS$asn.asn.cymru.com", DNS_TXT); - $txt = explode('|', $result[0]['txt']); - $result = trim(str_replace('"', '', $txt[4])); - $cache['astext'][$asn] = $result; - return $result; - } + if (Config::has("astext.$asn")) { + return Config::get("astext.$asn"); } + + if (isset($cache['astext'][$asn])) { + return $cache['astext'][$asn]; + } + + $result = dns_get_record("AS$asn.asn.cymru.com", DNS_TXT); + if (!empty($result[0]['txt'])) { + $txt = explode('|', $result[0]['txt']); + $result = trim($txt[4], ' "'); + $cache['astext'][$asn] = $result; + return $result; + } + + return ''; } /**