From aada69cd649943daf903b2f98e4cc58208ab943d Mon Sep 17 00:00:00 2001 From: Olen Date: Wed, 23 Sep 2020 13:38:42 +0200 Subject: [PATCH] IRC Add more logging and debug info (#12140) * Add more logging and debug info * Code cleanup * Code cleanup take two --- LibreNMS/IRCBot.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/LibreNMS/IRCBot.php b/LibreNMS/IRCBot.php index 92e7f19930..2fbffa1ea3 100644 --- a/LibreNMS/IRCBot.php +++ b/LibreNMS/IRCBot.php @@ -126,7 +126,9 @@ class IRCBot } foreach ($this->config['irc_external'] as $ext) { + $this->log("Command $ext..."); if (($this->external[$ext] = file_get_contents('includes/ircbot/' . $ext . '.inc.php')) == '') { + $this->log('failed!'); unset($this->external[$ext]); } } @@ -246,6 +248,12 @@ class IRCBot if (! is_array($alert)) { return false; } + if ($this->debug) { + $this->log('Alert received ' . $alert['title']); + $this->log('Alert state ' . $alert['state']); + $this->log('Alert severity ' . $alert['severity']); + $this->log('Alert channels ' . print_r($this->config['irc_alert_chan'], true)); + } switch ($alert['state']) { case AlertState::WORSE: @@ -391,9 +399,11 @@ class IRCBot $this->command = str_replace(':.', '', $this->command); $tmp = explode(':.' . $this->command . ' ', $this->data); $this->user = $this->getAuthdUser(); + $this->log('isAuthd-1? ' . $this->isAuthd()); if (! $this->isAuthd() && (isset($this->config['irc_auth']))) { $this->hostAuth(); } + $this->log('isAuthd-2? ' . $this->isAuthd()); if ($this->isAuthd() || trim($this->command) == 'auth') { $this->proceedCommand(str_replace("\n", '', trim($this->command)), trim($tmp[1])); } @@ -533,7 +543,9 @@ class IRCBot private function log($msg) { - echo '[' . date('r') . '] ' . trim($msg) . "\n"; + $log = '[' . date('r') . '] IRCbot ' . trim($msg) . "\n"; + echo $log; + file_put_contents($this->config['log_dir'] . '/irc.log', $log, FILE_APPEND); return true; } @@ -579,10 +591,14 @@ class IRCBot private function hostAuth() { + $this->log('HostAuth'); global $authorizer; foreach ($this->config['irc_auth'] as $nms_user => $hosts) { foreach ($hosts as $host) { $host = preg_replace("/\*/", '.*', $host); + if ($this->debug) { + $this->log("HostAuth on irc matching $host to " . $this->getUserHost($this->data)); + } if (preg_match("/$host/", $this->getUserHost($this->data))) { $user_id = LegacyAuth::get()->getUserid(mres($nms_user)); $user = LegacyAuth::get()->getUser($user_id);