mirror of
https://github.com/librenms/librenms.git
synced 2024-09-24 11:58:54 +00:00
Merge pull request #434 from f0o/issue-433
Updated IRC-Bot to follow Alerting changes
This commit is contained in:
commit
ded516a450
@ -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`)
|
||||
|
26
irc.php
26
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,18 +162,31 @@ class ircbot {
|
||||
private function alertData() {
|
||||
if( ($alert = $this->read("alert")) !== false ) {
|
||||
$alert = json_decode($alert,true);
|
||||
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 ".$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['rule'])." - Faults".(sizeof($alert['faults']) > 3 ? " (showing first 3 out of ".sizeof($alert['faults'])." )" : "" ).":");
|
||||
$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);
|
||||
if( $k >= 3 )
|
||||
$this->irc_raw("PRIVMSG ".$nick." :#".$k." ".$v['string']);
|
||||
if( $k >= 3 ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getData() {
|
||||
if( ($data = $this->read("irc")) !== false ) {
|
||||
|
Loading…
Reference in New Issue
Block a user