mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added colors to alerts sent to IRC
This commit is contained in:
@@ -23,6 +23,7 @@ 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_alert_utf8']` | `false` | Optional; Enables use of strikethrough in alerts via UTF-8 encoded characters. Might cause trouble for some clients.
|
||||
`$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)
|
||||
|
||||
@@ -511,6 +511,7 @@ $config['irc_external'] = '';
|
||||
$config['irc_authtime'] = 3;
|
||||
$config['irc_debug'] = false;
|
||||
$config['irc_alert'] = false;
|
||||
$config['irc_alert_utf8'] = false;
|
||||
|
||||
// Authentication
|
||||
$config['allow_unauth_graphs'] = 0;
|
||||
|
||||
15
irc.php
15
irc.php
@@ -227,9 +227,20 @@ class ircbot {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($alert['state']):
|
||||
case 3: $severity_extended = '+'; break;
|
||||
case 4: $severity_extended = '-'; break;
|
||||
default: $severity_extended = '';
|
||||
endswitch;
|
||||
|
||||
$severity = str_replace(array('warning', 'critical'), array(chr(3).'8Warning', chr(3).'4Critical'), $alert['severity']).$severity_extended.chr(3).' ';
|
||||
if ($alert['state'] == 0 and $this->config['irc_alert_utf8']) {
|
||||
$severity = str_replace(array('Warning', 'Critical'), array('W̶a̶r̶n̶i̶n̶g̶', 'C̶r̶i̶t̶i̶c̶a̶l̶'), $severity);
|
||||
}
|
||||
|
||||
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:' : ''));
|
||||
$this->irc_raw('PRIVMSG '.$chan.' :'.$severity.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']);
|
||||
}
|
||||
@@ -238,7 +249,7 @@ class ircbot {
|
||||
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']).' )' : '' ).':' : ''));
|
||||
$this->irc_raw('PRIVMSG '.$nick.' :'.$severity.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) {
|
||||
|
||||
Reference in New Issue
Block a user