From d799600cabe1f7c7f85665a55be7753bdd6590ac Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Thu, 26 Apr 2018 16:14:28 +0100 Subject: [PATCH] refactor: Updated the oxidized script (#8572) * refactor: Updated the oxidized script * Updated to use rmccue::Requests + Config::get() --- scripts/syslog-notify-oxidized.php | 39 ++++++++++-------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/scripts/syslog-notify-oxidized.php b/scripts/syslog-notify-oxidized.php index 2d820caa47..2c2c967635 100755 --- a/scripts/syslog-notify-oxidized.php +++ b/scripts/syslog-notify-oxidized.php @@ -1,28 +1,20 @@ #!/usr/bin/env php $username, "msg" => $msg); - - $version = `git rev-parse --short HEAD`; - if ($version != "") { - $version = "/".$version; + $postdata = ["user" => $username, "msg" => $msg]; + $oxidized_url = Config::get('oxidized.url'); + if (!empty($oxidized_url)) { + Requests::put("$oxidized_url/node/next/$hostname", [], json_encode($postdata), ['proxy' => get_proxy()]); } - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postdata)); - curl_setopt($curl, CURLOPT_USERAGENT, "librenms".$version); - curl_setopt($curl, CURLOPT_URL, $config['oxidized']['url'].'/node/next/'.$hostname); - $result = curl_exec($curl); }//end oxidized_node_update() $hostname = $argv[1]; @@ -30,18 +22,13 @@ $os = $argv[2]; $msg = $argv[3]; if (preg_match('/(SYS-(SW[0-9]+-)?5-CONFIG_I|VSHD-5-VSHD_SYSLOG_CONFIG_I): Configured from .+ by (?P.+) on .*/', $msg, $matches)) { - $username = $matches['user']; - oxidized_node_update($hostname, $username, $msg); + oxidized_node_update($hostname, $msg, $matches['user']); } elseif (preg_match('/GBL-CONFIG-6-DB_COMMIT : Configuration committed by user \\\\\'(?P.+?)\\\\\'..*/', $msg, $matches)) { - $username = $matches['user']; - oxidized_node_update($hostname, $username, $msg); + oxidized_node_update($hostname, $msg, $matches['user']); } elseif (preg_match('/ASA-(config-)?5-111005: (?P.+) end configuration: OK/', $msg, $matches)) { - $username = $matches['user']; - oxidized_node_update($hostname, $username, $msg); + oxidized_node_update($hostname, $msg, $matches['user']); } elseif (preg_match('/startup-config was changed by (?P.+) from telnet client .*/', $msg, $matches)) { - $username = $matches['user']; - oxidized_node_update($hostname, $username, $msg); + oxidized_node_update($hostname, $msg, $matches['user']); } elseif (preg_match('/HWCM\/4\/CFGCHANGE/', $msg, $matches)) { //Huawei VRP devices CFGCHANGE syslog - $username = 'not_provided'; //Huawei VRP syslog does not provide username here. - oxidized_node_update($hostname, $username, $msg); + oxidized_node_update($hostname, $msg); }