mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
IRC Add more logging and debug info (#12140)
* Add more logging and debug info * Code cleanup * Code cleanup take two
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user