From 38b929942cb8cce7f8be0aa0cf76bf1e1eae16cc Mon Sep 17 00:00:00 2001 From: f0o Date: Sat, 31 Jan 2015 17:05:25 +0000 Subject: [PATCH] Updated irc.php Added Alert-Channels to irc.php --- doc/Extensions/IRC-Bot.md | 5 +++-- irc.php | 32 ++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/doc/Extensions/IRC-Bot.md b/doc/Extensions/IRC-Bot.md index fa9214affe..c06353f67b 100644 --- a/doc/Extensions/IRC-Bot.md +++ b/doc/Extensions/IRC-Bot.md @@ -22,12 +22,13 @@ The Bot will reply the same way it's being called. If you send it the commands v Option | Default-Value | Notes --- | --- | --- `$config['irc_alert']` | `false` | Optional; Enables Alerting-Socket. `EXPERIMENTAL` +`$config['irc_alert_chan']` | `false` | Optional; Multiple channels can be defined as Array or delimited with `,`. `EXPERIMENTAL` `$config['irc_authtime']` | `3` | Optional; Defines how long in Hours an auth-session is valid. `$config['irc_chan']` | `##librenms` | Optional; Multiple channels can be defined as Array or delimited with `,` `$config['irc_debug']` | `false` | Optional; Enables debug output (Wall of text) `$config['irc_external']` | | Optional; Array or `,` delimited string with commands to include from `includes/ircbot/*.inc.php` `$config['irc_host']` | | Required; Domain or IP to connect. If it's an IPv6 Address, embed it in `[]`. (Example: `[::1]`) -`$config['irc_maxretry]` | `5` | Optional; How many connection attempts should be made before giving up +`$config['irc_maxretry']` | `5` | Optional; How many connection attempts should be made before giving up `$config['irc_nick']` | `LibreNMS` | Optional; `$config['irc_pass']` | | Optional; This sends the IRC-PASS Sequence to IRC-Servers that require Password on Connect `$config['irc_port']` | `6667` | Required; To enable SSL append a `+` before the Port. (Example: `+6697`) @@ -127,4 +128,4 @@ File: includes/ircbot/echo.inc.php } else { return $this->respond("root shouldn't be online so late!"); } -``` \ No newline at end of file +``` diff --git a/irc.php b/irc.php index 913ba594c7..ed3e832a2c 100755 --- a/irc.php +++ b/irc.php @@ -69,6 +69,13 @@ class ircbot { $this->chan = array($this->config['irc_chan']); } } + if($this->config['irc_alert_chan']) { + if(strstr($this->config['irc_alert_chan'],",")) { + $this->config['irc_alert_chan'] = explode(",",$this->config['irc_alert_chan']); + } else { + $this->config['irc_alert_chan'] = array($this->config['irc_alert_chan']); + } + } if($this->config['irc_pass']) { $this->pass = $this->config['irc_pass']; } @@ -155,13 +162,26 @@ class ircbot { private function alertData() { if( ($alert = $this->read("alert")) !== false ) { $alert = json_decode($alert,true); - foreach( $this->authd as $nick=>$data ) { - if( $data['expire'] >= time() ) { - $this->irc_raw("PRIVMSG ".$nick." :".trim($alert['title'])." - Rule: ".trim($alert['rule'])." - Faults".(sizeof($alert['faults']) > 3 ? " (showing first 3 out of ".sizeof($alert['faults'])." )" : "" ).":"); + if( !is_array($alert) ) { + return false; + } + if( $this->config['irc_alert_chan'] ) { + foreach( $this->config['irc_alert_chan'] as $chan ) { + $this->irc_raw("PRIVMSG ".$chan." :".trim($alert['title'])." - Rule: ".trim($alert['name'] ? $alert['name'] : $alert['rule']).(sizeof($alert['faults']) > 0 ? " - Faults:" : "")); foreach( $alert['faults'] as $k=>$v ) { - $this->irc_raw("PRIVMSG ".$nick." :#".$k." ".$v); - if( $k >= 3 ) - break; + $this->irc_raw("PRIVMSG ".$chan." :#".$k." ".$v['string']); + } + } + } else { + foreach( $this->authd as $nick=>$data ) { + if( $data['expire'] >= time() ) { + $this->irc_raw("PRIVMSG ".$nick." :".trim($alert['title'])." - Rule: ".trim($alert['name'] ? $alert['name'] : $alert['rule']).(sizeof($alert['faults']) > 0 ? " - Faults".(sizeof($alert['faults']) > 3 ? " (showing first 3 out of ".sizeof($alert['faults'])." )" : "" ).":" : "")); + foreach( $alert['faults'] as $k=>$v ) { + $this->irc_raw("PRIVMSG ".$nick." :#".$k." ".$v['string']); + if( $k >= 3 ) { + break; + } + } } } }